| Samsung Internal API reference 2.0

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

Typedefs | Functions
Socket library API

## Typedefs
typedef int | socklen_t
| A type of width of at least 32 bits representing lengths in socket subsystem.

## Functions
int | accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
| Accept a connection on a socket. More...
int | bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
| Bind a name to a socket. More...
int | connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
| Initiate a connection on a socket. More...
int | getsockopt (int sockfd, int level, int optname, void *optval, socklen_t *optlen)
| Get options on socket. More...
int | setsockopt (int sockfd, int level, int optname, const void *optval, socklen_t optlen)
| Set options on socket. More...
int | listen (int sockfd, int backlog)
| Listen for connections on a socket. More...
int | socket (int socket_family, int socket_type, int protocol)
| Create endpoint for communication. More...
ssize_t | recv (int sockfd, void *buf, size_t len, int flags)
| Receive a message from a socket. More...
ssize_t | send (int sockfd, const void *buf, size_t len, int flags)
| Send a message to a socket. More...
int | socketpair (int socket_family, int socket_type, int protocol, int sv[2])
| Create a pair of connected sockets. More...
ssize_t | recvmsg (int sockfd, struct msghdr *msg, int flags)
| Receive multipple message on a socket. More...
ssize_t | sendmsg (int sockfd, struct msghdr *msg, int flags)
| Send multipple message on a socket. More...

## Detailed Description

## Function Documentation

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

`#include <sys/socket.h>`

Accept a connection on a socket.

Parameters

  [in] | sockfd | listening socket descriptor
  [in] | addr | pointer to a sockaddr structure
  [in,out] | addrlen | size of structure pointed to by addr

Returns
  nonnegative file descriptor for the accepted socket on success
  -1 with errno on error

int bind | ( | int | sockfd,
|  | const struct sockaddr * | addr,
|  | socklen_t | addrlen
| ) |  |

`#include <sys/socket.h>`

Bind a name to a socket.

Parameters

  [in] | sockfd | socket descriptor
  [in] | addr | address to the socket
  [in] | addrlen | size of the address structure

Returns
  0 on success
  -1 with errno on error

int connect | ( | int | sockfd,
|  | const struct sockaddr * | addr,
|  | socklen_t | addrlen
| ) |  |

`#include <sys/socket.h>`

Initiate a connection on a socket.

Parameters

  [in] | sockfd | socket descriptor
  [in] | addr | address to the socket
  [in] | addrlen | size of the address structure

Returns
  0 on success
  -1 with errno on error

int getsockopt | ( | int | sockfd,
|  | int | level,
|  | int | optname,
|  | void * | optval,
|  | socklen_t * | optlen
| ) |  |

`#include <sys/socket.h>`

Get options on socket.

Parameters

  [in] | sockfd | socket descriptor
  [in] | level | socket API level
  [in] | optname | specified options
  [in,out] | optval | buffer in which the value of the requested options are to be returned
  [in,out] | optlen | the size of the buffer pointed to by optval

Returns
  0 on success
  -1 with errno on error

int listen | ( | int | sockfd,
|  | int | backlog
| ) |  |

`#include <sys/socket.h>`

Listen for connections on a socket.

Parameters

  [in] | sockfd | socket descriptor
  [in] | backlog | maximum length to which the queue of pending connections for sockfd may grow

Returns
  0 on success
  -1 with errno on error

ssize_t recv | ( | int | sockfd,
|  | void * | buf,
|  | size_t | len,
|  | int | flags
| ) |  |

`#include <sys/socket.h>`

Receive a message from a socket.

Parameters

  [in] | sockfd | socket descriptor
  [in] | buf | pointer to a message buffer
  [in] | len | message length
  [in] | flags | type of receiving

Returns
  number of bytes received on success
  -1 with errno on error

ssize_t recvmsg | ( | int | sockfd,
|  | struct msghdr * | msg,
|  | int | flags
| ) |  |

`#include <sys/socket.h>`

Receive multipple message on a socket.

Parameters

  [in] | sockfd | socket descriptor
  [in] | msg | pointer to an array of msghdr structures
  [in] | flags | type of receiving

Returns
  number of messages received in msg on success
  -1 with errno on error

ssize_t send | ( | int | sockfd,
|  | const void * | buf,
|  | size_t | len,
|  | int | flags
| ) |  |

`#include <sys/socket.h>`

Send a message to a socket.

Parameters

  [in] | sockfd | socket descriptor
  [in,out] | buf | pointer to a message buffer
  [in] | len | message length
  [in] | flags | type of sending

Returns
  number of bytes sent on success
  -1 with errno on error

ssize_t sendmsg | ( | int | sockfd,
|  | struct msghdr * | msg,
|  | int | flags
| ) |  |

`#include <sys/socket.h>`

Send multipple message on a socket.

Parameters

  [in] | sockfd | socket descriptor
  [out] | msg | pointer to an array of msghdr structures
  [in] | flags | type of sending

Returns
  number of messages sent from msg on success
  -1 with errno on error

int setsockopt | ( | int | sockfd,
|  | int | level,
|  | int | optname,
|  | const void * | optval,
|  | socklen_t | optlen
| ) |  |

`#include <sys/socket.h>`

Set options on socket.

Parameters

  [in] | sockfd | socket descriptor
  [in] | level | socket API level
  [in] | optname | specified options
  [in] | optval | buffer in which the new value of the requested options is stored
  [in] | optlen | the size of the buffer pointed to by optval

Returns
  0 on success
  -1 with errno on error

int socket | ( | int | socket_family,
|  | int | socket_type,
|  | int | protocol
| ) |  |

`#include <sys/socket.h>`

Create endpoint for communication.

Parameters

  [in] | socket_family | communication domain
  [in] | socket_type | communication semantics specifier
  [in] | protocol | particular protocol to be used with the socket

Returns
  nonnegative file descriptor for the new socket on success
  -1 with errno on error

int socketpair | ( | int | socket_family,
|  | int | socket_type,
|  | int | protocol,
|  | int | sv[2]
| ) |  |

`#include <sys/socket.h>`

Create a pair of connected sockets.

Parameters

  [in] | socket_family | communication domain
  [in] | socket_type | communication semantics specifier
  [in] | protocol | particular protocol to be used with the socket
  [in] | sv | file descriptors

Returns
  0 on success
  -1 with errno on error