BSD API
81
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Socket
•
Secure
sockets provide users the ability to establish encrypted data transport (SSL and TLS). For
more information, see
6.4
BSD API
The SimpleLink driver provide two sets of socket API: the SimpleLink API and a BSD-compliant API. The
major differences are:
•
The SimpleLink APIs return informative error codes instead of using the errno method
•
The BSD-compliant API is an additional socket layer which allows the user to use an errno mechanism
implemented by the operating system. If this mechanism is not available in the target operating
system, the host driver offers an internal errno mechanism.
describes a list of BSD socket APIs and their corresponding SimpleLink API.
Table 6-2. BSD APIs
BSD
SimpleLink
Server or
Client
TCP or UDP
Description
socket()
sl_Socket()
Both
Both
Creates an endpoint for communication.
bind()
sl_Bind()
Both
Both
Assigns an IP address and a port to a socket. If the
socket is not bound, a port is chosen automatically.
listen()
sl_Listen()
Server
TCP
Listens for connections on a socket.
connect()
sl_Connect()
Client
Both
Initiates a connection on a socket.
accept()
sl_Accept()
Server
TCP
Accepts an incoming connection on a socket.
send(), recv()
sl_Send(),
sl_Recv()
Both
Both
Writes and reads data. (On UDP, connect API which sets
the default address must be called before sl_Send).
write(), read()
Not supported
sendto(), recvfrom()
sl_SendTo(),
sl_RecvFrom()
Both
UDP
Writes/reads data to/from a UDP socket.
close()
sl_Close()
Both
Both
Causes the system to release resources allocated to a
socket. In case of TCP, the connection is terminated.
select()
sl_Select()
Both
Both
Select allows a program to monitor multiple sockets,
waiting until one or more sockets become ready. Only a
single select is supported at a time.
SimpleLink supports:
• Readfds: On data socket: data arrived. On listen
socket: indicating new client connected
• Writefds: only on TCP connect, must configure
nonblocking socket
• Exceptfds: not supported
gethostbyname()
sl_NetAppDnsGetH
ostByName()
None
None
This is not a socket operation. It is preliminary to a socket
operation, to retrieve host IP information corresponding to
a host name.
poll()
Not supported
getsockopt()
sl_SockOpt()
Both
Both
Retrieves the current value of a particular socket option
for the specified socket.
setsockopt()
sl_SetSockOpt()
Both
Both
Sets a particular socket option for the specified socket.
htons(), ntohs()
sl_Htons(),
sl_Ntohs()
Both
Both
Reorders the bytes of a 16-bit unsigned value from
processor order to network order.
htonl(), ntohl()
sl_Htonl(),
sl_Ntohl()
Both
Both
Reorders the bytes of a 32-bit unsigned value from
processor order to network order.
The following examples demonstrate the differences between these APIs:
/* Send using BSD API and checking errno value */
if
(send(sock , pBuff,
sizeof
(pBuff), 0) == -1)
{
int
errsv = errno;
printf(
"send() failed\n"
);
if
(errsv == ...) { ... }