SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.15
Simplifies the implementation of Internet connectivity
BSD_Socket

Controls standard client/server sockets programming options and capabilities. More...

Functions

struct hostentgethostbyname (const char *name)
 Get host IP by name
Obtain the IP Address of machine on network, by machine name. More...
 
int socket (int Domain, int Type, int Protocol)
 Create an endpoint for communication. More...
 
int accept (int sd, sockaddr *addr, socklen_t *addrlen)
 Accept a connection on a socket. More...
 
int bind (int sd, const sockaddr *addr, socklen_t addrlen)
 Assign a name to a socket. More...
 
int listen (int sd, int backlog)
 Listen for connections on a socket. More...
 
int connect (int sd, const sockaddr *addr, socklen_t addrlen)
 Initiate a connection on a socket. More...
 
int select (int nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout)
 Monitor socket activity. More...
 
int setsockopt (int sd, int level, int optname, const void *optval, socklen_t optlen)
 Set socket options-. More...
 
int getsockopt (int sd, int level, int optname, void *optval, socklen_t *optlen)
 Get socket options. More...
 
ssize_t recv (int sd, void *pBuf, size_t Len, int flags)
 Read data from TCP socket. More...
 
ssize_t recvfrom (int sd, void *buf, _i16 Len, _i16 flags, sockaddr *from, socklen_t *fromlen)
 Read data from socket. More...
 
ssize_t send (int sd, const void *pBuf, _i16 Len, _i16 flags)
 Write data to TCP socket. More...
 
ssize_t sendto (int sd, const void *pBuf, size_t Len, int flags, const sockaddr *to, socklen_t tolen)
 Write data to socket. More...
 

Detailed Description

Controls standard client/server sockets programming options and capabilities.

Function Documentation

int accept ( int  sd,
sockaddr *  addr,
socklen_t *  addrlen 
)

Accept a connection on a socket.

This function is used with connection-based socket types (SOCK_STREAM).
It extracts the first connection request on the queue of pending connections, creates a new connected socket, and returns a new file descriptor referring to that socket.
The newly created socket is not in the listening state. The original socket sd is unaffected by this call.
The argument sd is a socket that has been created with socket(), bound to a local address with bind(), and is listening for connections after a listen(). The argument addr is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket, as known to the communications layer. The exact format of the address returned addr is determined by the socket's address family.
The addrlen argument is a value-result argument: it should initially contain the size of the structure pointed to by addr, on return it will contain the actual length (in bytes) of the address returned.

Parameters
[in]sdSocket descriptor (handle)
[out]addrThe argument addr is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket, as known to the communications layer. The exact format of the address returned addr is determined by the socket's address
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[out]addrlenThe addrlen argument is a value-result argument: it should initially contain the size of the structure pointed to by addr
Returns
On success, a socket handle.
On a non-blocking accept a possible retrun is -1 and errno is set to EAGAIN.
On failure, errno is set and -1 is returned.
ENOMEM may be return in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS.
See also
socket bind listen
Note
Belongs to server_side
Warning

Definition at line 90 of file socket.c.

91 {
92  int RetVal = (int)sl_Accept(sd, addr, addrlen);
93  return _SlDrvSetErrno(RetVal);
94 }
_i16 sl_Accept(_i16 sd, SlSockAddr_t *addr, SlSocklen_t *addrlen)
Accept a connection on a socket.
Definition: sl_socket.c:683
int bind ( int  sd,
const sockaddr *  addr,
socklen_t  addrlen 
)

Assign a name to a socket.

This function gives the socket the local address addr. addr is addrlen bytes long. Traditionally, this is called When a socket is created with socket, it exists in a name space (address family) but has no name assigned. It is necessary to assign a local address before a SOCK_STREAM socket may receive connections.

Parameters
[in]sdSocket descriptor (handle)
[in]addrSpecifies the destination addrs
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format.
[in]addrlenContains the size of the structure pointed to by addr
Returns
Zero on success, or -1 on failure and sets errno to the corresponding BDS error code.
See also
socket accept listen
Note
belongs to basic_api
Warning

Definition at line 23 of file socket.c.

24 {
25  int RetVal = (int)sl_Bind(sd, addr, addrlen);
26  return _SlDrvSetErrno(RetVal);
27 }
_i16 sl_Bind(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen)
Assign a name to a socket.
Definition: sl_socket.c:221
int connect ( int  sd,
const sockaddr *  addr,
socklen_t  addrlen 
)

Initiate a connection on a socket.

Function connects the socket referred to by the socket descriptor sd, to the address specified by addr. The addrlen argument specifies the size of addr. The format of the address in addr is determined by the address space of the socket. If it is of type SOCK_DGRAM, this call specifies the peer with which the socket is to be associated; this address is that to which datagrams are to be sent, and the only address from which datagrams are to be received. If the socket is of type SOCK_STREAM, this call attempts to make a connection to another socket. The other socket is specified by address, which is an address in the communications space of the socket.

Parameters
[in]sdSocket descriptor (handle)
[in]addrSpecifies the destination addr
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[in]addrlenContains the size of the structure pointed to by addr
Returns
On success, a socket handle.
On a non-blocking connect a possible negative value is EALREADY. On failure, -1 is returned and sets errno to the corresponding BDS error code.
ENOMEM may be return in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See also
sl_Socket
Note
belongs to client_side
Warning

Definition at line 57 of file socket.c.

58 {
59  int RetVal = (int)sl_Connect(sd, addr, addrlen);
60  return _SlDrvSetErrno(RetVal);
61 }
_i16 sl_Connect(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen)
Initiate a connection on a socket.
Definition: sl_socket.c:440
struct hostent* gethostbyname ( const char *  name)

Get host IP by name
Obtain the IP Address of machine on network, by machine name.

Parameters
[in]constchar *name Host name
Returns
Struct hostent containing the answer on success or NULL failure.
See also
sl_NetAppDnsGetHostByName
Note
Note: The function isn't reentrant! It utilize a static hostent struct which holds the answer for the DNS query. Calling this function form several threads may result in invalid answers. A user interested in a reentrant function which resolves IP address by name, can use the SimpleLink API: 'sl_NetAppDnsGetHostByName'. Another option is to protect this call with a lock and copy the returned hostent struct to a user buffer, before unlocking.
Warning
The parameter 'name' is assumed to be allocated by the user, and it's the user's Responsibility to maintain it's validity. This field is copied (not deep copied) to the struct returned by this function.
Example
  • Getting host by name:
    1 int DestinationIP;
    2 int AddrSize;
    3 int SockId;
    4 sockaddr_t Addr;
    5 struct hostent DnsEntry;
    6 
    7 DnsEntry = gethostbyname("www.google.com");
    8 
    9 if(!DnsEntry)
    10 {
    11  Addr.sin_family = AF_INET;
    12  Addr.sin_port = htons(80);
    13  Addr.sin_addr.s_addr = htonl(DestinationIP);
    14  AddrSize = sizeof(sockaddr_t);
    15  SockId = socket(AF_INET, SOCK_STREAM, 0);
    16 }

Definition at line 145 of file socket.c.

146 {
147  static struct hostent Hostent;
148  static char* AddrArray[2];
149  static char Addr[16];
150 
151  int RetVal = 0;
152 
153  /* Clear the reused buffer */
154  _SlDrvMemZero(&Hostent, sizeof(struct hostent));
155  _SlDrvMemZero(&AddrArray, sizeof(AddrArray));
156  _SlDrvMemZero(&Addr, sizeof(Addr));
157 
158  /* Set the host name */
159  Hostent.h_name = (char*)name;
160  /* Query DNS for IPv4 address. */
161  RetVal = sl_NetAppDnsGetHostByName((signed char*)name , (_u16)strlen(name), (unsigned long*)(&Addr), AF_INET);
162 
163  if(RetVal < 0)
164  {
165  /* If call fails, try again for IPv6. */
166  RetVal = sl_NetAppDnsGetHostByName((signed char*)name , (_u16)strlen(name), (unsigned long*)(&Addr), AF_INET6);
167  if(RetVal < 0)
168  {
169  /* if the request failed twice, there's an error, return NULL. */
170  return NULL;
171  }
172  else
173  {
174  /* fill the answer fields */
175  Hostent.h_addrtype = AF_INET6 ;
176  Hostent.h_length = IPv6_ADDR_LEN;
177  }
178  }
179  else
180  {
181  /* fill the answer fields */
182  Hostent.h_addrtype = AF_INET ;
183  Hostent.h_length = IPv4_ADDR_LEN;
184  }
185 
186  AddrArray[0] = &Addr[0];
187  Hostent.h_addr_list = AddrArray;
188 
189  /* Return the address of the reused buffer */
190  return (&Hostent);
191 }
Definition: netdb.h:30
_i16 sl_NetAppDnsGetHostByName(_i8 *pHostName, const _u16 NameLen, _u32 *OutIpAddr, const _u8 Family)
Get host IP by name Obtain the IP Address of machine on network, by machine name. ...
Definition: netapp.c:833
int getsockopt ( int  sd,
int  level,
int  optname,
void *  optval,
socklen_t *  optlen 
)

Get socket options.

This function manipulate the options associated with a socket. Options may exist at multiple protocol levels; they are always present at the uppermost socket level.
When manipulating socket options the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level, level is specified as SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate proto- col controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP;
The parameters optval and optlen are used to access optval - ues for setsockopt(). For getsockopt() they identify a buffer in which the value for the requested option(s) are to be returned. For getsockopt(), optlen is a value-result parameter, initially containing the size of the buffer pointed to by option_value, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, option_value may be NULL.

Parameters
[in]sdSocket handle
[in]levelDefines the protocol level for this option
[in]optnamedefines the option name to interrogate
[out]optvalSpecifies a value for the option
[out]optlenSpecifies the length of the option value
Returns
Zero on success, or -1 on failure and sets errno to the corresponding BDS error code.
See also
setsockopt Belongs to ext_api
Warning

Definition at line 123 of file socket.c.

124 {
125  int RetVal = (int)sl_GetSockOpt(sd, level, optname, optval, optlen);
126  return _SlDrvSetErrno(RetVal);
127 }
_i16 sl_GetSockOpt(_i16 sd, _i16 level, _i16 optname, void *optval, SlSocklen_t *optlen)
Get socket options.
Definition: sl_socket.c:1005
int listen ( int  sd,
int  backlog 
)

Listen for connections on a socket.

The willingness to accept incoming connections and a queue limit for incoming connections are specified with listen(), and then the connections are accepted with accept. The listen() call applies only to sockets of type SOCK_STREAM The backlog parameter defines the maximum length the queue of pending connections may grow to.

Parameters
[in]sdSocket descriptor (handle)
[in]backlogSpecifies the listen queue depth.
Returns
Zero on success, or -1 on failure and sets errno to the corresponding BDS error code.
See also
socket accept bind
Note
Belongs to server_side
Warning

Definition at line 79 of file socket.c.

80 {
81  int RetVal = (int)sl_Listen(sd, backlog);
82  return _SlDrvSetErrno(RetVal);
83 }
_i16 sl_Listen(_i16 sd, _i16 backlog)
Listen for connections on a socket.
Definition: sl_socket.c:647
ssize_t recv ( int  sd,
void *  pBuf,
size_t  Len,
int  flags 
)

Read data from TCP socket.

Function receives a message from a connection-mode socket

Parameters
[in]sdSocket handle
[out]bufPoints to the buffer where the message should be stored.
[in]lenSpecifies the length in bytes of the buffer pointed to by the buffer argument. Range: 1-16000 bytes
[in]flagsSpecifies the type of message reception. On this version, this parameter is not supported.
Returns
Return the number of bytes received, or a -1 if an error occurred. Errno is set accordingly.
Using a non-blocking recv a possible errno value is EAGAIN.
errno may be set to ENOMEM in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See also
sl_RecvFrom
Note
Belongs to recv_api
Warning
Examples
  • Receiving data using TCP socket:
    1 sockaddr_in Addr;
    2 sockaddr_in LocalAddr;
    3 int AddrSize = sizeof(socklen_t);
    4 int SockID, newSockID;
    5 int Status;
    6 char Buf[RECV_BUF_LEN];
    7 
    8 LocalAddr.sin_family = AF_INET;
    9 LocalAddr.sin_port = htons(5001);
    10 LocalAddr.sin_addr.s_addr = 0;
    11 
    12 Addr.sin_family = AF_INET;
    13 Addr.sin_port = htons(5001);
    14 Addr.sin_addr.s_addr = htonl(SL_IPV4_VAL(10,1,1,200));
    15 
    16 SockID = socket(AF_INET, SOCK_STREAM, 0);
    17 Status = bind(SockID, (sockaddr *)&LocalAddr, AddrSize);
    18 Status = listen(SockID, 0);
    19 newSockID = accept(SockID, (sockaddr *)&Addr, (socklen_t*) &AddrSize);
    20 Status = recv(newSockID, Buf, 1460, 0);

Definition at line 101 of file socket.c.

102 {
103  ssize_t RetVal = (ssize_t)sl_Recv(sd, pBuf, (_i16)Len, flags);
104  return (ssize_t)(_SlDrvSetErrno(RetVal));
105 }
_i16 sl_Recv(_i16 sd, void *buf, _i16 len, _i16 flags)
Read data from TCP socket.
Definition: sl_socket.c:911
ssize_t recvfrom ( int  sd,
void *  buf,
_i16  Len,
_i16  flags,
sockaddr *  from,
socklen_t *  fromlen 
)

Read data from socket.

Function receives a message from a connection-mode or connectionless-mode socket

Parameters
[in]sdSocket handle
[out]bufPoints to the buffer where the message should be stored.
[in]lenSpecifies the length in bytes of the buffer pointed to by the buffer argument. Range: 1-16000 bytes
[in]flagsSpecifies the type of message reception. On this version, this parameter is not supported.
[in]fromPointer to an address structure indicating the source address.
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[in]fromlenSource address structure size. This parameter MUST be set to the size of the structure pointed to by addr.
Returns
Return the number of bytes received, or a -1 if an error occurred. Errno is set accordingly.
Using a non-blocking recv a possible errno value is EAGAIN.
errno will be set to EINVAL if fromlen has incorrect length.
errno may be set to ENOMEM in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See also
recv
Note
Belongs to recv_api
Warning
Example
  • Receiving data:
    1 sockaddr_in Addr;
    2 sockaddr_in LocalAddr;
    3 int AddrSize = sizeof(socklen_t);
    4 int SockID, newSockID;
    5 int Status;
    6 char Buf[RECV_BUF_LEN];
    7 
    8 LocalAddr.sin_family = AF_INET;
    9 LocalAddr.sin_port = htons(5001);
    10 LocalAddr.sin_addr.s_addr = 0;
    11 
    12 SockID = socket(AF_INET, SOCK_STREAM, 0);
    13 Status = bind(SockID, (sockaddr *)&LocalAddr, AddrSize);
    14 Status = recvfrom(SockID, Buf, 1472, 0, (sockaddr_in *)&Addr, (socklen_t*)&AddrSize);

Definition at line 46 of file socket.c.

47 {
48  ssize_t RetVal = (ssize_t)sl_RecvFrom(sd, buf, Len, flags, from, fromlen);
49  return (ssize_t)(_SlDrvSetErrno(RetVal));
50 }
_i16 sl_RecvFrom(_i16 sd, void *buf, _i16 len, _i16 flags, SlSockAddr_t *from, SlSocklen_t *fromlen)
Read data from socket.
Definition: sl_socket.c:351
int select ( int  nfds,
fd_set *  readsds,
fd_set *  writesds,
fd_set *  exceptsds,
struct timeval *  timeout 
)

Monitor socket activity.

Select allow a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready" for some class of I/O operation. If trigger mode is enabled the active fdset is the one that retreived in the first triggerd call. To enable the trigger mode, an handler must be statically registered to the slcb_SocketTriggerEventHandler (user.h)

Parameters
[in]nfdsThe highest-numbered file descriptor in any of the three sets, plus 1.
[out]readsdsSocket descriptors list for read monitoring and accept monitoring
[out]writesdsSocket descriptors list for connect monitoring only, write monitoring is not supported
[out]exceptsdsSocket descriptors list for exception monitoring, not supported.
[in]timeoutIs an upper bound on the amount of time elapsed before select() returns. Null or above 0xffff seconds means infinity timeout. The minimum timeout is 10 milliseconds, less than 10 milliseconds will be set automatically to 10 milliseconds. Max microseconds supported is 0xfffc00. In trigger mode the timout fields must be set to zero.
Returns
On success, select() returns the number of file descriptors contained in the three returned descriptor sets (that is, the total number of bits that are set in readfds, writefds, exceptfds) which may be zero if the timeout expires before anything interesting happens.
On error, a negative value is returned. readsds - return the sockets on which Read request will return without delay with valid data.
writesds - return the sockets on which Write request will return without delay.
exceptsds - return the sockets closed recently.
ENOMEM may be return in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See also
socket
Note
If the timeout value set to less than 10ms it will automatically set to 10ms to prevent overload of the system
Belongs to basic_api

Only one select can be handled at a time.Calling this API while the same command is called from another thread, may result in one of the following scenarios:

  1. The command will wait (internal) until the previous command finish, and then be executed.
  2. There are not enough resources and ENOMEM error will return. In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try again later to issue the command.
  3. In case there is already a triggered sl_Select in progress, the following call will return with SL_RET_CODE_SOCKET_SELECT_IN_PROGRESS_ERROR.
Warning

Definition at line 134 of file socket.c.

135 {
136  int RetVal = (int)sl_Select(nfds, readsds, writesds, exceptsds, timeout);
137  return _SlDrvSetErrno(RetVal);
138 }
_i16 sl_Select(_i16 nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout)
Monitor socket activity.
Definition: sl_socket.c:1096
ssize_t send ( int  sd,
const void *  pBuf,
_i16  Len,
_i16  flags 
)

Write data to TCP socket.

This function is used to transmit a message to another socket. Returns immediately after sending data to device. In case of TCP failure an async event SL_SOCKET_TX_FAILED_EVENT is going to be received.

Parameters
[in]sdSocket handle
[in]bufPoints to a buffer containing the message to be sent
[in]lenMessage size in bytes. Range: 1-1460 bytes
[in]flagsSpecifies the type of message transmission. On this version, this parameter is not supported for TCP.
Returns
Zero on success, or -1 on failure and sets errno to the corresponding BDS error code.
See also
sl_SendTo
Note
Belongs to send_api
Warning
Example
  • Sending data:
    1 sockaddr_in Addr;
    2 int AddrSize = sizeof(socklen_t);
    3 int SockID;
    4 int Status;
    5 char Buf[SEND_BUF_LEN];
    6 
    7 Addr.sin_family = AF_INET;
    8 Addr.sin_port = htons(5001);
    9 Addr.sin_addr.s_addr = htonl(SL_IPV4_VAL(10,1,1,200));
    10 
    11 SockID = socket(AF_INET, SOCK_STREAM, 0);
    12 Status = connect(SockID, (sockaddr_in*)&Addr, AddrSize);
    13 Status = send(SockID, Buf, 1460, 0 );

Definition at line 68 of file socket.c.

69 {
70  ssize_t RetVal = (ssize_t)sl_Send(sd, pBuf, Len, flags);
71  return (ssize_t)(_SlDrvSetErrno(RetVal));
72 }
_i16 sl_Send(_i16 sd, const void *buf, _i16 len, _i16 flags)
Write data to TCP socket.
Definition: sl_socket.c:581
ssize_t sendto ( int  sd,
const void *  pBuf,
size_t  Len,
int  flags,
const sockaddr *  to,
socklen_t  tolen 
)

Write data to socket.

This function is used to transmit a message to another socket (connection less socket SOCK_DGRAM, SOCK_RAW).
Returns immediately after sending data to device.
In case of transmission failure an async event SL_SOCKET_TX_FAILED_EVENT is going to be received.

Parameters
[in]sdSocket handle
[in]bufPoints to a buffer containing the message to be sent
[in]lenmessage size in bytes. Range: 1-1460 bytes
[in]flagsSpecifies the type of message transmission. On this version, this parameter is not supported
[in]toPointer to an address structure indicating the destination address.
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[in]tolenDestination address structure size
Returns
Zero on success, or -1 on failure and sets errno to the corresponding BDS error code.
See also
sl_Send
Note
Belongs to send_api
Warning
Example
  • Sending data:
    1 sockaddr_in Addr;
    2 int AddrSize = sizeof(socklen_t);
    3 int SockID;
    4 int Status;
    5 char Buf[SEND_BUF_LEN];
    6 
    7 Addr.sin_family = AF_INET;
    8 Addr.sin_port = htons(5001);
    9 Addr.sin_addr.s_addr = htonl(SL_IPV4_VAL(10,1,1,200));
    10 
    11 SockID = socket(AF_INET, SOCK_DGRAM, 0);
    12 Status = sendto(SockID, Buf, 1472, 0, (sockaddr_in *)&Addr, AddrSize);

Definition at line 35 of file socket.c.

36 {
37  ssize_t RetVal = (ssize_t)sl_SendTo(sd, pBuf, (_i16)Len, flags, to, tolen);
38  return (ssize_t)(_SlDrvSetErrno(RetVal));
39 }
_i16 sl_SendTo(_i16 sd, const void *buf, _i16 len, _i16 flags, const SlSockAddr_t *to, SlSocklen_t tolen)
Write data to socket.
Definition: sl_socket.c:270
int setsockopt ( int  sd,
int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
)

Set socket options-.

This function manipulate the options associated with a socket.
Options may exist at multiple protocol levels; they are always present at the uppermost socket level.
When manipulating socket options the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level, level is specified as SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate proto- col controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP;
The parameters optval and optlen are used to access optval - ues for setsockopt(). For getsockopt() they identify a buffer in which the value for the requested option(s) are to be returned. For getsockopt(), optlen is a value-result parameter, initially containing the size of the buffer pointed to by option_value, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, option_value may be NULL.

Parameters
[in]sdSocket handle
[in]levelDefines the protocol level for this option
  • SOL_SOCKET Socket level configurations (L4, transport layer)
  • IPPROTO_IP IP level configurations (L3, network layer)
[in]optnameDefines the option name to interrogate
  • SOL_SOCKET
  • SO_KEEPALIVE
    Enable/Disable periodic keep alive. Keeps TCP connections active by enabling the periodic transmission of messages
    Timeout is 5 minutes.
    Default: Enabled
    This options takes SlSockKeepalive_t struct as parameter
    • SO_KEEPALIVETIME
      Set keep alive timeout. Value is in seconds
      Default: 5 minutes
    • SO_RX_NO_IP_BOUNDARY
      Enable/Disable rx ip boundary. In connectionless socket (udp/raw), unread data is dropped (when recvfrom len parameter < data size), Enable this option in order to read the left data on the next recvfrom iteration Default: Disabled, IP boundary kept,
      This options takes SlSockRxNoIpBoundary_t struct as parameter
    • SO_RCVTIMEO
      Sets the timeout value that specifies the maximum amount of time an input function waits until it completes.
      Default: No timeout
      This options takes SlTimeval_t struct as parameter
    • SO_RCVBUF
      Sets tcp max recv window size.
      This options takes SlSockWinsize_t struct as parameter
    • SO_NONBLOCKING
      Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom.
      Default: Blocking. This options takes SlSockNonblocking_t struct as parameter
  • IPPROTO_IP
    • IP_MULTICAST_TTL
      Set the time-to-live value of outgoing multicast packets for this socket.
      This options takes _u8 as parameter
    • IP_ADD_MEMBERSHIP
      UDP socket, Join a multicast group.
      This options takes SlSockIpMreq_t struct as parameter
    • IP_DROP_MEMBERSHIP
      UDP socket, Leave a multicast group
      This options takes SlSockIpMreq_t struct as parameter
    • SO_LINGER
      Socket lingers on close pending remaining send/receive packetst
[in]optvalSpecifies a value for the option
[in]optlenSpecifies the length of the option value
Returns
Zero on success, or -1 on failure and sets errno to the corresponding BDS error code.
Persistent
All params are Non- Persistent
See also
getsockopt
Note
Belongs to basic_api
Warning

Definition at line 112 of file socket.c.

113 {
114  int RetVal = (int)sl_SetSockOpt(sd, level, optname, optval, optlen);
115  return _SlDrvSetErrno(RetVal);
116 }
_i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen)
Set socket options-.
Definition: sl_socket.c:962
int socket ( int  Domain,
int  Type,
int  Protocol 
)

Create an endpoint for communication.

The socket function creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it.
This function is called by the application layer to obtain a socket handle.

Parameters
[in]DomainSpecifies the protocol family of the created socket. For example:
  • AF_INET for network protocol IPv4
  • AF_INET6 for network protocol IPv6
[in]Typespecifies the communication semantic, one of:
  • SOCK_STREAM (reliable stream-oriented service or Stream Sockets)
  • SOCK_DGRAM (datagram service or Datagram Sockets)
  • SOCK_RAW (raw protocols atop the network layer)
[in]Protocolspecifies a particular transport to be used with the socket.
The most common are
  • IPPROTO_TCP
  • IPPROTO_UDP The value 0 may be used to select a default protocol from the selected domain and type
Returns
On success, socket handle that is used for consequent socket operations.
A successful return code should be a positive number (int16)
On error, a negative (int16) value will be returned specifying the error code.
  • EAFNOSUPPORT - illegal domain parameter
  • EPROTOTYPE - illegal type parameter
  • EACCES - permission denied
  • ENSOCK - exceeded maximal number of socket
  • ENOMEM - memory allocation error
  • EINVAL - error in socket configuration
  • EPROTONOSUPPORT - illegal protocol parameter
  • EOPNOTSUPP - illegal combination of protocol and type parameters
See also
close
Note
belongs to basic_api
Warning

Definition at line 11 of file socket.c.

12 {
13  int RetVal = (int)sl_Socket(Domain, Type, Protocol);
14  return _SlDrvSetErrno(RetVal);
15 }
_i16 sl_Socket(_i16 Domain, _i16 Type, _i16 Protocol)
Create an endpoint for communication.
Definition: sl_socket.c:118