TizenRT Libs&Environment  v2.0 M2
Socket

Provides APIs for BSD Socket. More...

Collaboration diagram for Socket:

Files

file  socket.h
 Socket APIs.
 
file  netdb.h
 DNS client API.
 
file  inet.h
 inet API
 

Data Structures

struct  netent
 
struct  protoent
 
struct  servent
 
struct  servent_data
 

Macros

#define EXTERN   extern
 
#define h_addr   h_addr_list[0] /* For backward compatibility */
 
#define EXTERN   extern
 
#define EXTERN   extern
 
#define INET_ADDRSTRLEN   16
 
#define INET6_ADDRSTRLEN   46
 
#define HTONS(ns)
 
#define HTONL(nl)
 
#define NTOHS(hs)   HTONS(hs)
 
#define NTOHL(hl)   HTONL(hl)
 
#define EXTERN   extern
 

Functions

int socket (int domain, int type, int protocol)
 creates an unbound socket in a communications domain. More...
 
int bind (int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen)
 assigns an address to an unnamed socket. More...
 
int connect (int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen)
 requests a connection to be made on a socket More...
 
int listen (int sockfd, int backlog)
 listen for socket connections and limit the queue of incoming connections More...
 
int accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 requests a connection to be made on a socket More...
 
ssize_t send (int sockfd, FAR const void *buf, size_t len, int flags)
 send a message on a socket More...
 
ssize_t sendto (int sockfd, FAR const void *buf, size_t len, int flags, FAR const struct sockaddr *to, socklen_t tolen)
 send a message on a socket More...
 
ssize_t recv (int sockfd, FAR void *buf, size_t len, int flags)
 send a message on a socket More...
 
ssize_t recvfrom (int sockfd, FAR void *buf, size_t len, int flags, FAR struct sockaddr *from, FAR socklen_t *fromlen)
 receive a message from a socket More...
 
int shutdown (int sockfd, int how)
 shut down socket send and receive operations More...
 
int setsockopt (int sockfd, int level, int option, FAR const void *value, socklen_t value_len)
 set the socket options More...
 
int getsockopt (int sockfd, int level, int option, FAR void *value, FAR socklen_t *value_len)
 get the socket options More...
 
int getsockname (int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)
 get the socket name More...
 
int getpeername (int s, struct sockaddr *name, socklen_t *namelen)
 get the name of the peer socket More...
 
ssize_t recvmsg (int sockfd, struct msghdr *msg, int flags)
 
ssize_t sendmsg (int sockfd, struct msghdr *msg, int flags)
 
struct hostent * gethostbyname (const char *name)
 gethostbyname is a function to get 32bit ip address from domain name or ip address string. More...
 
void freeaddrinfo (struct addrinfo *ai)
 freeaddrinfo() frees the memory allocated by the getaddrinfo() function. More...
 
int getaddrinfo (const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
 getaddrinfo() is a function that returns information on a particular host name (such as its IP address) and loads up a struct sockaddr. More...
 
int getnameinfo (const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
 getnameinfo() is a function that returns translated string from 32bit(ipv4)/128bit(ipv6) IP address. As lwip doesn't support rarp and relative functions it has restricted usage. More...
 
EXTERN FAR char * ether_ntoa (FAR const struct ether_addr *addr)
 ether_ntoa() function converts the Ethernet host address addr given in network byte order to a string in standard hex-digits-and-colons notation. More...
 
uint32_t ntohl (uint32_t nl)
 Convert the unsigned integer netlong from network byte order to host byte order. More...
 
uint16_t ntohs (uint16_t ns)
 Convert the unsigned short integer netshort from network byte order to host byte order. More...
 
uint32_t htonl (uint32_t hl)
 Convert the unsigned integer hostlong from host byte order to network byte order. More...
 
uint16_t htons (uint16_t hs)
 Convert the unsigned short integer hostshort from host byte order to network byte order. More...
 
int inet_aton (FAR const char *cp, FAR struct in_addr *inp)
 Convert the Internet host address from the IPv4 numbers-and-dots notation into binary form. More...
 
in_addr_t inet_addr (FAR const char *cp)
 Convert the Internet host address from the IPv4 numbers-and-dots notation into binary data in network byte order. More...
 
FAR char * inet_ntoa (struct in_addr in)
 Convert the Internet host address to a string in IPv4 dotted-decimal notation. More...
 

Variables

EXTERN int h_errno
 

Detailed Description

Provides APIs for BSD Socket.

Macro Definition Documentation

#define EXTERN   extern

Definition at line 86 of file ether.h.

#define EXTERN   extern

Definition at line 89 of file socket.h.

#define EXTERN   extern

Definition at line 126 of file inet.h.

#define EXTERN   extern

Definition at line 134 of file netdb.h.

#define h_addr   h_addr_list[0] /* For backward compatibility */

Definition at line 88 of file netdb.h.

#define HTONL (   nl)
Value:
(unsigned long) \
(((((unsigned long)(nl)) & 0x000000ffUL) << 24) | \
((((unsigned long)(nl)) & 0x0000ff00UL) << 8) | \
((((unsigned long)(nl)) & 0x00ff0000UL) >> 8) | \
((((unsigned long)(nl)) & 0xff000000UL) >> 24))

Definition at line 105 of file inet.h.

#define HTONS (   ns)
Value:
(unsigned short) \
(((((unsigned short)(ns)) & 0x00ff) << 8) | \
((((unsigned short)(ns)) >> 8) & 0x00ff))

Definition at line 101 of file inet.h.

#define INET6_ADDRSTRLEN   46

Definition at line 86 of file inet.h.

#define INET_ADDRSTRLEN   16

Definition at line 82 of file inet.h.

#define NTOHL (   hl)    HTONL(hl)

Definition at line 114 of file inet.h.

#define NTOHS (   hs)    HTONS(hs)

Definition at line 113 of file inet.h.

Function Documentation

int accept ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

requests a connection to be made on a socket

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor associated with the socket.
[in,out]addrnull or pointer to a sockaddr structure where the address of the connecting socket will be returned
[in,out]addrlenon input specifies the length of the supplied sockaddr structure, and on output specifies the length of the stored address.
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
int bind ( int  sockfd,
FAR const struct sockaddr *  addr,
socklen_t  addrlen 
)

assigns an address to an unnamed socket.

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor of the socket to be bound.
[in]addrpointer to a sockaddr structure containing the address to be bound to the socket
[in]addrlenthe length of the sockaddr structure
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
int connect ( int  sockfd,
FAR const struct sockaddr *  addr,
socklen_t  addrlen 
)

requests a connection to be made on a socket

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor associated with the socket.
[in]addrpointer to a sockaddr structure containing the peer address
[in]addrlenthe length of the sockaddr structure
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
EXTERN FAR char* ether_ntoa ( FAR const struct ether_addr *  addr)

ether_ntoa() function converts the Ethernet host address addr given in network byte order to a string in standard hex-digits-and-colons notation.

#include <netinet/ether.h>

Parameters
[in]addris the Ethernet host address addr given in network byte order
Returns
the string is returned in a statically allocated buffer
Since
TizenRT v1.0
void freeaddrinfo ( struct addrinfo *  ai)

freeaddrinfo() frees the memory allocated by the getaddrinfo() function.

Parameters
[in]aiis the head of the addrinfo list
Returns
void
Since
Tizen RT v1.0
int getaddrinfo ( const char *  nodename,
const char *  servname,
const struct addrinfo *  hints,
struct addrinfo **  res 
)

getaddrinfo() is a function that returns information on a particular host name (such as its IP address) and loads up a struct sockaddr.

Parameters
[in]nodenamecan be among a domain name, ip address and NULL
[in]servnamecan be a port number passed as string or a service name
[in]hintscan be either NULL or an addrinfo structure with the type of service requested
[out]resis a return pointer that points to a new addrinfo structure
Returns
On success, 0 is returned. On failure, a fail number is returned
Since
Tizen RT v1.0
struct hostent* gethostbyname ( const char *  name)

gethostbyname is a function to get 32bit ip address from domain name or ip address string.

Parameters
[in]namecan be the string of ip address or domain name
Returns
On success, 0 is returned. On failure, a pointer value is returned
Since
Tizen RT v1.0
int getnameinfo ( const struct sockaddr *  sa,
size_t  salen,
char *  host,
size_t  hostlen,
char *  serv,
size_t  servlen,
int  flags 
)

getnameinfo() is a function that returns translated string from 32bit(ipv4)/128bit(ipv6) IP address. As lwip doesn't support rarp and relative functions it has restricted usage.

Parameters
[in]sais an ip address structure pointer
[in]salencontains the length of sa structure, it is used to figure out ipv4/v6 structure
[out]hostis the return buffer that contains string that is translated from 32bit(ipv4)/128bit(ipv6) address.
[out]hostlencontains the length of host buffer length.
[out]servis the return buffer that contains port number string.
[out]servlencontains the length of serv buffer length.
[in]flagsis the bit field flag, this function supports NI_NUMERICHOST, NI_NUMERICSERV only.
Returns
On success, 0 is returned. On failure, a fail number is returned
Since
Tizen RT v1.0
int getpeername ( int  s,
struct sockaddr *  name,
socklen_t *  namelen 
)

get the name of the peer socket

#include <sys/socket.h>
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sthe file descriptor associated with the socket.
[in,out]namenull or pointer to a sockaddr structure where the address of the peer socket will be returned
[in,out]namelenon input specifies the length of the supplied sockaddr structure, and on output specifies the length of the stored address.
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
int getsockname ( int  sockfd,
FAR struct sockaddr *  addr,
FAR socklen_t *  addrlen 
)

get the socket name

#include <sys/socket.h>
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor associated with the socket.
[in,out]addrnull or pointer to a sockaddr structure where the address of the local socket will be returned
[in,out]addrlenon input specifies the length of the supplied sockaddr structure, and on output specifies the length of the stored address.
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
int getsockopt ( int  sockfd,
int  level,
int  option,
FAR void *  value,
FAR socklen_t *  value_len 
)

get the socket options

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor of the socket
[in]levelthe protocol level at which the option resides
[in]optiona single option to be retrieved
[out]valuepointer to value of the option retrieved
[out]value_lenthe length of the value retrieved
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
uint32_t htonl ( uint32_t  hl)

Convert the unsigned integer hostlong from host byte order to network byte order.

#include <arpa/inet.h>
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]hlhostlong
Returns
On success, the network byte-ordered hostlong is returned. On failure, -1 is returned.
uint16_t htons ( uint16_t  hs)

Convert the unsigned short integer hostshort from host byte order to network byte order.

#include <arpa/inet.h>
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]hshostshort
Returns
On success, the network byte-ordered hostshort is returned. On failure, -1 is returned.
in_addr_t inet_addr ( FAR const char *  cp)

Convert the Internet host address from the IPv4 numbers-and-dots notation into binary data in network byte order.

#include <arpa/inet.h>
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]cpthe Internet host address
Returns
On success, binary data in network byte order is returned. On failure, INADDR_NONE(usually -1) is returned.
int inet_aton ( FAR const char *  cp,
FAR struct in_addr *  inp 
)

Convert the Internet host address from the IPv4 numbers-and-dots notation into binary form.

#include <arpa/inet.h>

Parameters
[in]cpthe Internet host address
[in]inpstructure that will store the converted value (IPv4 numbers-and-dots notation)
Returns
On success, nonzero is returned. On failure, zero is returned.
FAR char* inet_ntoa ( struct in_addr  in)

Convert the Internet host address to a string in IPv4 dotted-decimal notation.

#include <arpa/inet.h>
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]inthe Internet host address in network byte order
Returns
On success, a string in IPv4 dotted-decimal notation is returned. On failure, -1 is returned.
int listen ( int  sockfd,
int  backlog 
)

listen for socket connections and limit the queue of incoming connections

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor associated with the socket.
[in]backlogthe number of outstanding connections in the socket's listen queue
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
uint32_t ntohl ( uint32_t  nl)

Convert the unsigned integer netlong from network byte order to host byte order.

#include <arpa/inet.h>
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]nlnetlong
Returns
On success, the host byte-ordered netlong is returned. On failure, -1 is returned.
uint16_t ntohs ( uint16_t  ns)

Convert the unsigned short integer netshort from network byte order to host byte order.

#include <arpa/inet.h>
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]nsnetshort
Returns
On success, the host byte-ordered netshort is returned. On failure, -1 is returned.
ssize_t recv ( int  sockfd,
FAR void *  buf,
size_t  len,
int  flags 
)

send a message on a socket

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor associated with the socket.
[out]bufPoints to a buffer where the message should be stored
[out]lenthe length in bytes of the buffer
[in]flagsthe type of message reception.
Returns
On success, returns the length of the message in bytes, On failure, -1 is returned.
Since
TizenRT v1.0
ssize_t recvfrom ( int  sockfd,
FAR void *  buf,
size_t  len,
int  flags,
FAR struct sockaddr *  from,
FAR socklen_t *  fromlen 
)

receive a message from a socket

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor associated with the socket.
[out]bufPointer to the buffer where the message should be stored.
[out]lenthe length of the message in bytes.
[in]flagsthe type of message reception
[in,out]fromA null pointer, or pointer to sockaddr structure in which the sending address is to be stored
[in,out]fromlennull or the length of the sockaddr structure
Returns
On success, returns the length of the message in bytes, On failure, -1 is returned.
Since
TizenRT v1.0
ssize_t recvmsg ( int  sockfd,
struct msghdr *  msg,
int  flags 
)
ssize_t send ( int  sockfd,
FAR const void *  buf,
size_t  len,
int  flags 
)

send a message on a socket

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor associated with the socket.
[in]bufPointer to the buffer containing the message to send.
[in]lenthe length of the message in bytes.
[in]flagsthe type of message transmission
Returns
On success, returns the number of bytes sent, On failure, -1 is returned.
Since
TizenRT v1.0
ssize_t sendmsg ( int  sockfd,
struct msghdr *  msg,
int  flags 
)
ssize_t sendto ( int  sockfd,
FAR const void *  buf,
size_t  len,
int  flags,
FAR const struct sockaddr *  to,
socklen_t  tolen 
)

send a message on a socket

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor associated with the socket.
[in]bufPointer to the buffer containing the message to send.
[in]lenthe length of the message in bytes.
[in]flagsthe type of message transmission
[in]topointer to a sockaddr structure containing the destination address
[in]tolenthe length of the sockaddr structure
Returns
On success, returns the number of bytes sent, On failure, -1 is returned.
Since
TizenRT v1.0
int setsockopt ( int  sockfd,
int  level,
int  option,
FAR const void *  value,
socklen_t  value_len 
)

set the socket options

/**

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor of the socket
[in]levelthe protocol level
[in]optionthe option to be set for the socket
[in]valuepointer to value of the option
[in]value_lenthe length of the value
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
int shutdown ( int  sockfd,
int  how 
)

shut down socket send and receive operations

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]sockfdthe file descriptor of the socket
[in]howthe type of shutdown
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
TizenRT v1.0
int socket ( int  domain,
int  type,
int  protocol 
)

creates an unbound socket in a communications domain.

#include <sys/socket.h>
SYSTEM CALL API
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)

Parameters
[in]domainthe communications domain in which a socket is to be created.
[in]typethe type of socket to be created
[in]protocolthe protocol to be used with the socket
Returns
On success, a non negative integer is returned. On failure, -1 is returned.
Since
TizenRT v1.0

Variable Documentation

EXTERN int h_errno

Definition at line 183 of file netdb.h.