Tizen RT Libs&Environment  v1.0 D5
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  hostent
 
struct  netent
 
struct  protoent
 
struct  servent
 
struct  addrinfo
 
struct  servent_data
 

Macros

#define EXTERN   extern
 
#define IPPORT_RESERVED   0xffff /* No reserved port numbers */
 
#define AI_PASSIVE   (1 << 0)
 
#define AI_CANONNAME   (1 << 1)
 
#define AI_NUMERICHOST   (1 << 2)
 
#define AI_NUMERICSERV   (1 << 3)
 
#define AI_V4MAPPED   (1 << 4)
 
#define AI_ALL   (1 << 5)
 
#define AI_ADDRCONFIG   (1 << 6)
 
#define NI_NOFQDN   (1 << 0)
 
#define NI_NUMERICHOST   (1 << 1)
 
#define NI_NAMEREQD   (1 << 2)
 
#define NI_NUMERICSERV   (1 << 3)
 
#define NI_NUMERICSCOPE   (1 << 4)
 
#define NI_DGRAM   (1 << 5)
 
#define HOST_NOT_FOUND   1
 
#define HOST_NOT_FOUND   1
 
#define NO_DATA   2
 
#define NO_DATA   2
 
#define NO_RECOVERY   3
 
#define NO_RECOVERY   3
 
#define TRY_AGAIN   4
 
#define TRY_AGAIN   4
 
#define EAI_AGAIN   1
 
#define EAI_BADFLAGS   2
 
#define EAI_FAMILY   3
 
#define EAI_MEMORY   4
 
#define EAI_NONAME   5
 
#define EAI_SERVICE   6
 
#define EAI_SOCKTYPE   7
 
#define EAI_SYSTEM   8
 
#define EAI_OVERFLOW   9
 
#define EAI_FAIL   -1
 
#define _PATH_SERVICES   "/etc/services"
 
#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 closesocket (int s)
 close a socket 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...
 
int getaddrinfo (const char *host, const char *service, 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...
 
void freeaddrinfo (FAR struct addrinfo *ai)
 freeaddrinfo() frees the memory allocated by the getaddrinfo() function. More...
 
FAR struct hostentgethostbyaddr (FAR const void *addr, socklen_t len, int type)
 gethostbyaddr() is the function returns a corresponding hostname with given IP addresses More...
 
FAR struct hostentgethostbyname (FAR const char *name)
 gethostbyname() is the function sending DNS query to DNS server with hostname 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...
 

Variables

EXTERN int h_errno
 

Detailed Description

Provides APIs for BSD Socket.

Macro Definition Documentation

#define _PATH_SERVICES   "/etc/services"

Definition at line 208 of file netdb.h.

#define AI_ADDRCONFIG   (1 << 6)

Definition at line 117 of file netdb.h.

#define AI_ALL   (1 << 5)

Definition at line 116 of file netdb.h.

#define AI_CANONNAME   (1 << 1)

Definition at line 112 of file netdb.h.

#define AI_NUMERICHOST   (1 << 2)

Definition at line 113 of file netdb.h.

#define AI_NUMERICSERV   (1 << 3)

Definition at line 114 of file netdb.h.

#define AI_PASSIVE   (1 << 0)

Definition at line 111 of file netdb.h.

#define AI_V4MAPPED   (1 << 4)

Definition at line 115 of file netdb.h.

#define EAI_AGAIN   1

Definition at line 176 of file netdb.h.

#define EAI_BADFLAGS   2

Definition at line 177 of file netdb.h.

#define EAI_FAIL   -1

Definition at line 185 of file netdb.h.

#define EAI_FAMILY   3

Definition at line 178 of file netdb.h.

#define EAI_MEMORY   4

Definition at line 179 of file netdb.h.

#define EAI_NONAME   5

Definition at line 180 of file netdb.h.

#define EAI_OVERFLOW   9

Definition at line 184 of file netdb.h.

#define EAI_SERVICE   6

Definition at line 181 of file netdb.h.

#define EAI_SOCKTYPE   7

Definition at line 182 of file netdb.h.

#define EAI_SYSTEM   8

Definition at line 183 of file netdb.h.

#define EXTERN   extern

Definition at line 86 of file ether.h.

#define EXTERN   extern

Definition at line 88 of file socket.h.

#define EXTERN   extern

Definition at line 157 of file inet.h.

#define EXTERN   extern

Definition at line 283 of file netdb.h.

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

Definition at line 225 of file netdb.h.

#define HOST_NOT_FOUND   1

Definition at line 203 of file netdb.h.

#define HOST_NOT_FOUND   1

Definition at line 203 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 IPPORT_RESERVED   0xffff /* No reserved port numbers */

Definition at line 92 of file netdb.h.

#define NI_DGRAM   (1 << 5)

Definition at line 142 of file netdb.h.

#define NI_NAMEREQD   (1 << 2)

Definition at line 139 of file netdb.h.

#define NI_NOFQDN   (1 << 0)

Definition at line 137 of file netdb.h.

#define NI_NUMERICHOST   (1 << 1)

Definition at line 138 of file netdb.h.

#define NI_NUMERICSCOPE   (1 << 4)

Definition at line 141 of file netdb.h.

#define NI_NUMERICSERV   (1 << 3)

Definition at line 140 of file netdb.h.

#define NO_DATA   2

Definition at line 204 of file netdb.h.

#define NO_DATA   2

Definition at line 204 of file netdb.h.

#define NO_RECOVERY   3

Definition at line 205 of file netdb.h.

#define NO_RECOVERY   3

Definition at line 205 of file netdb.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.

#define TRY_AGAIN   4

Definition at line 206 of file netdb.h.

#define TRY_AGAIN   4

Definition at line 206 of file netdb.h.

Function Documentation

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

requests a connection to be made on a socket

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
Tizen RT v1.0
int bind ( int  sockfd,
FAR const struct sockaddr *  addr,
socklen_t  addrlen 
)

assigns an address to an unnamed socket.

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
Tizen RT v1.0
int closesocket ( int  s)

close a socket

Parameters
[in]sthe file descriptor of the socket
Returns
On success, 0 is returned. On failure, -1 is returned.
Since
Tizen RT v1.0
int connect ( int  sockfd,
FAR const struct sockaddr *  addr,
socklen_t  addrlen 
)

requests a connection to be made on a socket

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
Tizen RT 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.

Parameters
[in]addris the Ethernet host address addr given in network byte order
Returns
the string is returned in a statically allocated buffer
Since
Tizen RT v1.0
void freeaddrinfo ( FAR 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 *  host,
const char *  service,
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]hostcan be either a domain name or NULL
[in]servicecan 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
[in]resis a pointer that points to a new addrinfo structure
Returns
On success, 0 is returned. On failure, a negative value is returned
Since
Tizen RT v1.0
FAR struct hostent* gethostbyaddr ( FAR const void *  addr,
socklen_t  len,
int  type 
)

gethostbyaddr() is the function returns a corresponding hostname with given IP addresses

Parameters
[in]*addrhost address sending DNS server (e.g., 192.168.0.0)
Returns
On success, hostent, the structure contains hostname of requested IP addresses, returns. On failure, hostname parameters in hostent structure is NULL
Since
Tizen RT v1.0
FAR struct hostent* gethostbyname ( FAR const char *  name)

gethostbyname() is the function sending DNS query to DNS server with hostname

Parameters
[in]*namehostname sending DNS server (e.g., www.samsung.com)
Returns
On success, hostent, the structure contains IP addresses of requested hostname, returns. On failure, IP address parameters in hostent structure is NULL
Since
Tizen RT v1.0
int getpeername ( int  s,
struct sockaddr *  name,
socklen_t *  namelen 
)

get the name of the peer socket

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
Tizen RT v1.0
int getsockname ( int  sockfd,
FAR struct sockaddr *  addr,
FAR socklen_t *  addrlen 
)

get the socket name

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
Tizen RT v1.0
int getsockopt ( int  sockfd,
int  level,
int  option,
FAR void *  value,
FAR socklen_t *  value_len 
)

get the socket options

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
Tizen RT v1.0
uint32_t htonl ( uint32_t  hl)

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

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.

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.

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.

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.
int listen ( int  sockfd,
int  backlog 
)

listen for socket connections and limit the queue of incoming connections

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
Tizen RT v1.0
uint32_t ntohl ( uint32_t  nl)

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

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.

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

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
Tizen RT 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

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
Tizen RT v1.0
ssize_t send ( int  sockfd,
FAR const void *  buf,
size_t  len,
int  flags 
)

send a message on a socket

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
Tizen RT v1.0
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

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
Tizen RT v1.0
int setsockopt ( int  sockfd,
int  level,
int  option,
FAR const void *  value,
socklen_t  value_len 
)

set the socket options

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
Tizen RT v1.0
int shutdown ( int  sockfd,
int  how 
)

shut down socket send and receive operations

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
Tizen RT v1.0
int socket ( int  domain,
int  type,
int  protocol 
)

creates an unbound socket in a communications domain.

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
Tizen RT v1.0

Variable Documentation

EXTERN int h_errno

Definition at line 292 of file netdb.h.