mbed socket API

Dependents:   EthernetInterface EthernetInterface_RSF EthernetInterface EthernetInterface ... more

Deprecated

This is an mbed 2 sockets library. For mbed 5, network sockets have been revised to better support additional network stacks and thread safety here.

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Tue Jun 26 13:16:26 2012 +0000
Child:
1:8080965f5d76
Commit message:
Initial Commit

Changed in this revision

TCPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
TCPSocket.h Show annotated file Show diff for this revision Revisions of this file
UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
UDPSocket.h Show annotated file Show diff for this revision Revisions of this file
bsd_socket.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCPSocket.cpp	Tue Jun 26 13:16:26 2012 +0000
@@ -0,0 +1,280 @@
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+ 
+#include "TCPSocket.h"
+
+#include "bsd_socket.h"
+
+#include <cstring>
+
+using std::memset;
+
+TCPSocket::TCPSocket() : m_sock(-1)
+{
+}
+
+TCPSocket::~TCPSocket()
+{
+  close(); //Don't want to leak 
+}
+
+int TCPSocket::connect(char* host, int port, int timeout)
+{
+  int ret = init();
+  if( ret < 0 ) 
+  {
+    return -1;
+  }
+
+  //Populate m_remoteHost
+  std::memset(&m_remoteHost, 0, sizeof(struct sockaddr_in));
+
+  //Resolve DNS address or populate hard-coded IP address
+  struct hostent *server = ::gethostbyname(host);
+  if(server == NULL)
+  {
+    return -1; //Could not resolve address
+  }
+  std::memcpy((char*)&m_remoteHost.sin_addr.s_addr, (char*)server->h_addr_list[0], server->h_length);
+
+  m_remoteHost.sin_family = AF_INET;
+  m_remoteHost.sin_port = htons(port);
+  
+  ret = ::connect(m_sock, (const struct sockaddr *)&m_remoteHost, sizeof(m_remoteHost));
+  if (ret < 0)
+  {
+    close();
+    return -1;
+  }
+  
+  return 0;
+}
+
+int TCPSocket::bind(int port)
+{
+  int ret = init();
+  if( ret < 0 ) 
+  {
+    return -1;
+  }
+  
+  struct sockaddr_in localHost;
+  std::memset(&localHost, 0, sizeof(localHost));
+ 
+  localHost.sin_family = AF_INET;
+  localHost.sin_port = htons(port);
+  localHost.sin_addr.s_addr = INADDR_ANY;
+  
+  ret = ::bind(m_sock, (const struct sockaddr *)&localHost, sizeof(localHost));
+  if (ret < 0)
+  {
+    close();
+    return -1;
+  }
+
+  return 0;
+}
+
+int TCPSocket::listen(int max)
+{
+  if( m_sock < 0 )
+  {
+    return -1;
+  }
+  
+  int ret = ::listen(m_sock, max);
+  if (ret < 0)
+  {
+    close();
+    return -1;
+  }
+  
+  return 0;
+}
+
+int TCPSocket::accept(TCPSocket& socket, char** host, int* port, int timeout)
+{
+  if( m_sock < 0 )
+  {
+    return -1;
+  }
+
+  //Populate m_remoteHost
+  std::memset(&socket.m_remoteHost, 0, sizeof(struct sockaddr_in));
+
+  struct timeval t_val; //t_val will be decremented on each call to select()
+  t_val.tv_sec = timeout / 1000;
+  t_val.tv_usec = (timeout - (t_val.tv_sec * 1000)) * 1000;
+  //Wait for socket to get some connection request (i.e. to be "readable")
+  //Creating FS set
+  fd_set socksSet;
+  FD_ZERO(&socksSet);
+  FD_SET(m_sock, &socksSet);
+  int ret = ::select(FD_SETSIZE, &socksSet, NULL, NULL, &t_val);
+  if(ret <= 0 || !FD_ISSET(m_sock, &socksSet))
+  {
+    return -1; //Timeout
+  }
+  
+  socklen_t newSockRemoteHostLen = sizeof(socket.m_remoteHost);
+  
+  ret = ::accept(m_sock, (struct sockaddr*)&socket.m_remoteHost, &newSockRemoteHostLen);
+  if( ret < 0 )
+  {
+    return -1; //Accept failed
+  }
+  
+  socket.m_sock = ret; //ret is the new socket's fd
+  socket.m_closedByRemoteHost = false;
+  
+  static char hostBuf[16];
+  inet_ntoa_r(socket.m_remoteHost.sin_addr, hostBuf, sizeof(hostBuf));
+  
+  *host = hostBuf;
+  *port = ntohs(socket.m_remoteHost.sin_port);
+
+  return 0;
+}
+
+// -1 if unsuccessful, else number of bytes written
+int TCPSocket::send(uint8_t* data, int length, int timeout)
+{
+  if( m_sock < 0 )
+  {
+    return -1;
+  }
+  
+  if( m_closedByRemoteHost )
+  {
+    return 0;
+  }
+
+  size_t writtenLen = 0;
+  struct timeval t_val; //t_val will be decremented on each call to select()
+  t_val.tv_sec = timeout / 1000;
+  t_val.tv_usec = (timeout - (t_val.tv_sec * 1000)) * 1000;
+  while(writtenLen < length)
+  {
+    //Wait for socket to be writeable
+    //Creating FS set
+    fd_set socksSet;
+    FD_ZERO(&socksSet);
+    FD_SET(m_sock, &socksSet);
+
+    int ret = ::select(FD_SETSIZE, NULL, &socksSet, NULL, &t_val);
+    if(ret <= 0 || !FD_ISSET(m_sock, &socksSet))
+    {
+      return writtenLen; //Timeout -- FIXME should we return -1 or writtenLength ?
+    }
+
+    ret = ::send(m_sock, data + writtenLen, length - writtenLen, 0);
+    if( ret > 0)
+    {
+      writtenLen += ret;
+      continue;
+    }
+    else if( ret == 0 )
+    {
+      m_closedByRemoteHost = true;
+      return writtenLen; //Connection was closed by remote host -- FIXME how do we signal that the connection was closed ?
+    }
+    else
+    {
+      return -1; //Connnection error
+    }
+  }
+  
+  return writtenLen;
+}
+
+// -1 if unsuccessful, else number of bytes received
+int TCPSocket::receive(uint8_t* data, int length, int timeout)
+{
+  if( m_sock < 0 )
+  {
+    return -1;
+  }
+  
+  if( m_closedByRemoteHost )
+  {
+    return 0;
+  }
+  
+  size_t readLen = 0;
+  struct timeval t_val; //t_val will be decremented on each call to select()
+  t_val.tv_sec = timeout / 1000;
+  t_val.tv_usec = (timeout - (t_val.tv_sec * 1000)) * 1000;
+  while(readLen < length)
+  {
+    //Wait for socket to be readable
+    //Creating FS set
+    fd_set socksSet;
+    FD_ZERO(&socksSet);
+    FD_SET(m_sock, &socksSet);
+    int ret = ::select(FD_SETSIZE, &socksSet, NULL, NULL, &t_val);
+    if(ret <= 0 || !FD_ISSET(m_sock, &socksSet))
+    {
+      return readLen; //Timeout -- FIXME should we return -1 or writtenLength ?
+    }
+
+    ret = ::recv(m_sock, data + readLen, length - readLen, 0);
+    if( ret > 0)
+    {
+      readLen += ret;
+      continue;
+    }
+    else if( ret == 0 )
+    {
+      m_closedByRemoteHost = true;
+      return readLen; //Connection was closed by remote host -- FIXME how do we signal that the connection was closed ?
+    }
+    else
+    {
+      return -1; //Connnection error
+    }
+  }
+  return readLen;
+}
+
+int TCPSocket::close()
+{
+  if( m_sock < 0 )
+  {
+    return -1;
+  }
+
+  ::close(m_sock);
+  m_sock = -1;
+  
+  return 0;
+}
+
+int TCPSocket::init()
+{
+  if( m_sock != -1 )
+  {
+    return -1;
+  }
+  m_sock = ::socket(AF_INET, SOCK_STREAM, 0); //TCP socket
+  if (m_sock < 0)
+  {
+    return -1; //Could not create socket (Out of memory / available descriptors)
+  }
+  m_closedByRemoteHost = false;
+  return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCPSocket.h	Tue Jun 26 13:16:26 2012 +0000
@@ -0,0 +1,98 @@
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef TCPSOCKET_H
+#define TCPSOCKET_H
+
+#include <cstdint>
+
+#include "bsd_socket.h"
+
+/**
+This is a C++ abstraction for TCP networking sockets.
+*/
+class TCPSocket
+{
+  public:
+  
+    /** Instantiate a TCP Socket.
+    */
+    TCPSocket();
+    
+    ~TCPSocket();
+
+    /** Connect the TCP Socket to the following host.
+    \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
+    \param port The host's port to connect to.
+    \param timeout The maximum time in ms during which to try to connect.
+    \return 0 on success, -1 on failure.
+    */
+    int connect(char* host, int port, int timeout = 0);
+
+    /** Bind a socket to a specific port.
+    For a listening socket, bind the socket to the following port. The socket will start listening for incoming connections on this port on the call to listen().
+    \param port The port to listen for incoming connections on.
+    \return 0 on success, -1 on failure.
+    */
+    int bind(int port);
+
+    /** Start listening for incoming connections.
+    \param max The maximum number of connections that can be accepted.
+    \return 0 on success, -1 on failure.
+    */
+    int listen(int max);
+
+    /** Accept a new connection.
+    \param socket A socket instance that will handle the incoming connection.
+    \param host The reference that will point to the client's IP address.
+    \param port The reference that will point to the client's port.
+    \param timeout The maximum time in ms during which to wait for an incoming connection.
+    \return 0 on success, -1 on failure.
+    */
+    int accept(TCPSocket& socket, char** host, int* port, int timeout = 0);
+
+    /** Send data to the remote host.
+    \param data The buffer to send to the host.
+    \param length The length of the buffer to send.
+    \param timeout The maximum amount of time in ms to wait while trying to send the buffer.
+    \return the number of written bytes on success (>=0) or -1 on failure
+    */
+    int send(std::uint8_t* data, int length, int timeout = 0);
+
+    /** Receive data from the remote host.
+    \param data The buffer in which to store the data received from the host.
+    \param length The maximum length of the buffer.
+    \param timeout The maximum amount of time in ms to wait while trying to receive data.
+    \return the number of received bytes on success (>=0) or -1 on failure
+    */
+    int receive(std::uint8_t* data, int length, int timeout = 0);
+
+    /** Close the socket.
+    */
+    int close();
+    
+  private:
+    int init();
+
+    int m_sock;
+    bool m_closedByRemoteHost;
+    struct sockaddr_in m_remoteHost;
+
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UDPSocket.cpp	Tue Jun 26 13:16:26 2012 +0000
@@ -0,0 +1,205 @@
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "UDPSocket.h"
+#include "bsd_socket.h"
+
+#include <cstring>
+
+using std::memset;
+
+UDPSocket::UDPSocket() : m_sock(-1)
+{
+}
+
+UDPSocket::~UDPSocket()
+{
+  close(); //Don't want to leak
+}
+
+int UDPSocket::bind(int port)
+{
+  int ret = init();
+  if( ret < 0 ) 
+  {
+    return -1;
+  }
+  
+  struct sockaddr_in localHost;
+  std::memset(&localHost, 0, sizeof(localHost));
+ 
+  localHost.sin_family = AF_INET;
+  localHost.sin_port = htons(port);
+  localHost.sin_addr.s_addr = INADDR_ANY;
+  
+  ret = ::bind(m_sock, (const struct sockaddr *)&localHost, sizeof(localHost));
+  if (ret < 0)
+  {
+    close();
+    return -1;
+  }
+
+  return 0;
+}
+
+// -1 if unsuccessful, else number of bytes written
+int UDPSocket::sendTo(uint8_t* data, int length, char* host, int port, int timeout)
+{
+  if( m_sock < 0 )
+  {
+    return -1;
+  }
+  
+  struct sockaddr_in remoteHost;
+ 
+  //Populate m_remoteHost
+  std::memset(&remoteHost, 0, sizeof(struct sockaddr_in));
+
+  //Resolve DNS address or populate hard-coded IP address
+  struct hostent *server = ::gethostbyname(host);
+  if(server == NULL)
+  {
+    return -1; //Could not resolve address
+  }
+  std::memcpy((char*)&remoteHost.sin_addr.s_addr, (char*)server->h_addr_list[0], server->h_length);
+
+  remoteHost.sin_family = AF_INET;
+  remoteHost.sin_port = htons(port);
+
+  size_t writtenLen = 0;
+  struct timeval t_val; //t_val will be decremented on each call to select()
+  t_val.tv_sec = timeout / 1000;
+  t_val.tv_usec = (timeout - (t_val.tv_sec * 1000)) * 1000;
+  while(writtenLen < length)
+  {
+    //Wait for socket to be writeable
+    //Creating FS set
+    fd_set socksSet;
+    FD_ZERO(&socksSet);
+    FD_SET(m_sock, &socksSet);
+
+    int ret = ::select(FD_SETSIZE, NULL, &socksSet, NULL, &t_val);
+    if(ret <= 0 || !FD_ISSET(m_sock, &socksSet))
+    {
+      return writtenLen; //Timeout -- FIXME should we return -1 or writtenLength ?
+    }
+
+    ret = ::sendto(m_sock, data + writtenLen, length - writtenLen, 0, (const struct sockaddr *)&remoteHost, sizeof(remoteHost));
+    if( ret > 0)
+    {
+      writtenLen += ret;
+      continue;
+    }
+    else if( ret == 0 )
+    {
+      return writtenLen; //Connection was closed by server -- FIXME how do we signal that the connection was closed ?
+    }
+    else
+    {
+      return -1; //Connnection error
+    }
+  }
+  
+  return writtenLen;
+}
+
+// -1 if unsuccessful, else number of bytes received
+int UDPSocket::receiveFrom(uint8_t* data, int length, char** host, int* port, int timeout)
+{
+  if( m_sock < 0 )
+  {
+    return -1;
+  }
+
+  struct sockaddr_in remoteHost;
+ 
+  //Populate m_remoteHost
+  std::memset(&remoteHost, 0, sizeof(struct sockaddr_in));
+  
+  socklen_t remoteHostLen = sizeof(remoteHost);
+
+  size_t readLen = 0;
+  struct timeval t_val; //t_val will be decremented on each call to select()
+  t_val.tv_sec = timeout / 1000;
+  t_val.tv_usec = (timeout - (t_val.tv_sec * 1000)) * 1000;
+  
+  //No loop here as we don't want to mix packets from different sources
+  do
+  {
+    //Wait for socket to be readable
+    //Creating FS set
+    fd_set socksSet;
+    FD_ZERO(&socksSet);
+    FD_SET(m_sock, &socksSet);
+    int ret = ::select(FD_SETSIZE, &socksSet, NULL, NULL, &t_val);
+    if(ret <= 0 || !FD_ISSET(m_sock, &socksSet))
+    {
+      break; //Timeout -- FIXME should we return -1 or writtenLength ?
+    }
+    
+    ret = ::recvfrom(m_sock, data + readLen, length - readLen, 0, (struct sockaddr*)&remoteHost, &remoteHostLen);
+    if( ret > 0)
+    {
+      readLen += ret;
+    }
+    else if( ret == 0 )
+    {
+      //Connection was closed by server -- FIXME how do we signal that the connection was closed ?
+      //Continue and populate address
+    }
+    else
+    {
+      return -1; //Connection error
+    }
+  } while(0);
+  
+  static char hostBuf[16];
+  inet_ntoa_r(remoteHost.sin_addr, hostBuf, sizeof(hostBuf));
+  
+  *host = hostBuf;
+  *port = ntohs(remoteHost.sin_port);
+  
+  return readLen;
+}
+
+int UDPSocket::close()
+{
+  if( m_sock < 0 )
+  {
+    return -1;
+  }
+
+  ::close(m_sock);
+  m_sock = -1;
+  
+  return 0;
+}
+
+int UDPSocket::init()
+{
+  if( m_sock != -1 )
+  {
+    return -1;
+  }
+  m_sock = ::socket(AF_INET, SOCK_DGRAM, 0); //UDP socket
+  if (m_sock < 0)
+  {
+    return -1; //Could not create socket (Out of memory / available descriptors)
+  }
+  return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UDPSocket.h	Tue Jun 26 13:16:26 2012 +0000
@@ -0,0 +1,75 @@
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef UDPSOCKET_H
+#define UDPSOCKET_H
+
+#include <cstdint>
+
+/**
+This is a C++ abstraction for UDP networking sockets.
+*/
+class UDPSocket
+{
+  public:
+  
+    /** Instantiate a UDP Socket.
+    */
+    UDPSocket();
+    
+    ~UDPSocket();
+
+    /** Bind a socket to a specific port.
+    For a listening socket, bind the socket to the following port.
+    \param port The port to listen for incoming connections on, using 0 here will select a random port.
+    \return 0 on success, -1 on failure.
+    */
+    int bind(int port);
+
+    /** Send data to a remote host.
+    \param data The buffer to send to the host.
+    \param length The length of the buffer to send.
+    \param host The host to send data to. It can either be an IP Address or a hostname that will be resolved with DNS.
+    \param port The host's port to send data to.
+    \param timeout The maximum amount of time in ms to wait while trying to send the buffer.
+    \return the number of written bytes on success (>=0) or -1 on failure
+    */
+    int sendTo(std::uint8_t* data, int length, char* host, int port, int timeout = 0);
+
+    /** Receive data from a remote host.
+    \param data The buffer in which to store the data received from the host.
+    \param length The maximum length of the buffer.
+    \param host The reference that will point to the client's IP address.
+    \param port The reference that will point to the client's port.
+    \param timeout The maximum amount of time in ms to wait while trying to receive data.
+    \return the number of received bytes on success (>=0) or -1 on failure
+    */
+    int receiveFrom(std::uint8_t* data, int length, char** host, int* port, int timeout = 0);
+
+    /** Close the socket.
+    */
+    int close();
+
+  private:
+    int init();
+
+    int m_sock;
+  
+};
+
+#endif 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bsd_socket.h	Tue Jun 26 13:16:26 2012 +0000
@@ -0,0 +1,34 @@
+/* Copyright (C) 2012 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef BSD_SOCKET_H_
+#define BSD_SOCKET_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "socket/sys/socket.h" //Must conform to <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html>
+#include "socket/netinet/in.h" //Must conform to <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html>
+#include "socket/netdb.h"      //Must conform to <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netdb.h.html>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BSD_SOCKET_H_ */