1.2.1.2 Berkeley Module

The Berkeley_Socket_Distribution (BSD) APIs provide a BSD wrapper to the native Microchip TCP/IP Stack APIs. Using this interface, programmers familiar with BSD_sockets can quickly develop applications using Microchip's TCP/IP Stack.

Abstraction Model

The following illustration shows a typical interaction for a TCP server or client using the Berkeley_socket_APIs

bsd_diagram

Library Interface

NameDescription
Macros
MAX_BSD_SOCKETSBerkeley API max number of sockets simultaneous supported
Functions
acceptThis function accepts connection requests queued for a listening socket.
bindThis function assigns a name to the socket descriptor.
closesocketThe closesocket function closes an existing socket.
connectThis function connects to the peer communications end point.
gethostnameReturns the standard host name for the system.
listenThe listen function sets the specified socket in a listen mode.
recvThe recv() function is used to receive incoming data that has been queued for a socket.
recvfromThe recvfrom() function is used to receive incoming data that has been queued for a socket.
sendThe send function is used to send outgoing data on an already connected socket.
sendtoThis function used to send the data for both connection oriented and connection-less sockets.
socketThis function creates a new Berkeley socket.
getsockoptAllows setting options to a socket like adjust RX/TX buffer size, etc
setsockoptAllows setting options to a socket like adjust RX/TX buffer size, etc
gethostbynameThe gethostbyname function returns a structure of type hostent for the given host name.
freeaddrinfoFrees the memory allocated by getaddrinfo
getaddrinfoDoes an address look up for the provided node name.
getsocknameReturns the current address to which the socket is bound.
TCPIP_BSD_SocketReturns the native socket number associated with the BSD socket.
TCPIP_BSD_TaskStandard TCP/IP stack module task function.
TCPIP_BSD_PresSocketReturns the NET_PRES socket number associated with the BSD socket.
Data Types and Constants
in_addrin_addr structure
sockaddrgeneric address structure for all address families
sockaddr_inIn the Internet address family
SOCKADDRgeneric address structure for all address families
SOCKADDR_INIn the Internet address family
SOCKETSocket descriptor
AF_INETInternet Address Family - IPv4, UDP, TCP, etc.
INADDR_ANYIP address for server binding.
INVALID_TCP_PORTInvalid TCP port
IP_ADDR_ANYIP Address for server binding
IPPROTO_IPIndicates IP pseudo-protocol.
IPPROTO_TCPIndicates TCP level options
IPPROTO_UDPIndicates UDP level options
SOCK_DGRAMConnectionless datagram socket. Use UDP for the Internet address family.
SOCK_STREAMConnection based byte streams. Use TCP for the Internet address family.
SOCKET_CNXN_IN_PROGRESSSocket connection state.
SOCKET_DISCONNECTEDSocket disconnected
SOCKET_ERRORSocket error
ICMP6_FILTERSEt the IPv6 Filtering options - Not yet supported
IP_ADD_MEMBERSHIPJoin a multicast group - Not yet supported
IP_DROP_MEMBERSHIPLeave a multicast group - Not yet supported
IP_MULTICAST_IFSet the Interface that multicast packets should be sent on - Not yet supported
IP_MULTICAST_LOOPSpecify a copy of multicast packets should be delivered to the sending host - Not yet supported
IP_MULTICAST_TTLSet the Time to Live option for multicast packets - Not yet supported
IP_OPTIONSIP Header Options - Not yet supported
IP_TOSType of Service - Not yet supported
IP_TTLTime to Live - Not yet supported
IPPROTO_ICMPV6Indicates IPv6 ICMP Protocol Options
IPPROTO_IPV6Indicates IP v6 Header options
IPV6_CHECKSUMSets the IPv6 Checksum options - Not yet supported
IPV6_JOIN_GROUPJoin an IPv6 multicast group - Not yet supported
IPV6_LEAVE_GROUPLeave an IPv6 multicast group - Not yet supported
IPV6_MULTICAST_HOPSSet the hop limit for multicast IPv6 packets - Not yet supported
IPV6_MULTICAST_IFSet the Interface that multicast IPv6 packets should be sent on - Not yet supported
IPV6_MULTICAST_LOOPSpecify a copy of multicast IPv6 packets should be delivered to the sending host - Not yet supported
IPV6_UNICAST_HOPSSet the hop limit for unicast IPv6 packets - Not yet supported
IPV6_V6ONLYSets the socket to IPv6 only - Not yet supported
SO_BROADCASTEnables the Socket for sending broadcast data
SO_DEBUGIndicates if low level debut is active - Not yet supported
SO_DONTROUTEBypass normal routing - Not yet supported
SO_KEEPALIVEKeep the connection alive by sending periodic transmissions - Not yet supported
SO_LINGERIndicates if the system should send any buffered data when a socket is closed
SO_OOBINLINEIndicates whether or not Out of Band Data should be received inline with normal data - Not yet supported
SO_RCVBUFReceive Buffer Size (TCP only)
SO_RCVLOWATReceive Low Water mark - Not yet supported
SO_RCVTIMEOSet the Receive Timeout - Not yet supported
SO_REUSEADDRIndicates if the local socket can be reused immediately after close - Not yet supported
SO_SNDBUFSend Buffer Size
SO_SNDLOWATSend Low Water mark - Not yet supported
SO_SNDTIMEOSet the Send Timeout - Not yet supported
SOL_SOCKETIndicates socket level options
TCP_NODELAYIndicates if TCP is to buffer packets - Not yet supported
lingerThis is record linger.
hostentThis is record hostent.
in6_addrThis is record in6_addr.
sockaddr_in6In the Internet address family
sockaddr_storageThis is record sockaddr_storage.
addrinfoThis is record addrinfo.
SOCKADDR_IN6This is type SOCKADDR_IN6.
AF_INET6Internet Address Family - IPv6
HOST_NOT_FOUNDAuthoritative Answer host not found
NO_DATAValid name, no data record of requested type
NO_RECOVERYNon recoverable errors,
TRY_AGAINNon authoritative host not found or server fail
BERKELEY_MODULE_CONFIGBerkeley API module configuration structure
__ss_aligntypeStructure large enough to hold any socket address (with the historical exception of AF_UNIX). 128 bytes reserved.
_SS_PADSIZEThis is macro _SS_PADSIZE.
_SS_SIZEThis is macro _SS_SIZE.
EAI_AGAINTemporary failure in name resolution.
EAI_BADFLAGSInvalid value for ai_flags field.
EAI_FAILNon-recoverable failure in name res.
EAI_FAMILYai_family not supported.
EAI_MEMORYMemory allocation failure.
EAI_NONAMENAME or SERVICE is unknown.
EAI_OVERFLOWArgument buffer overflow.
EAI_SERVICESERVICE not supported for ai_socktype.
EAI_SOCKTYPEai_socktype not supported.
EAI_SYSTEMSystem error returned in errno.
_BERKELEY_API_HEADER_FILEThis is macro _BERKELEY_API_HEADER_FILE.
BERKELEYAPI_CONFIG_HThis is macro BERKELEYAPI_CONFIG_H.