Socket APIs
int socket(int domain, int type, int protocol);
Creates a socket of the given domain, type and protocol.
int bind(int sd, struct sockaddr *addr_p, int lenght);
Binds a name to a socket.
int listen(int sd, int size);
This is called in a server process to establish a connection-based socket (of type SOCK_STREAM or SOCK_SEQPACKET) for communication.
int connect(int sd, struct sockaddr *addr_p, int lenght);
This is called in a client process in requesting a connection to a server socket.
int accept(int sd, struct sockaddr *addr_p, int* lenght);
This is called in a server process to establish a connection-based socket connection with a client socket.
int send(int sd, const char *buf, int len, int flag);
int sendto(int sd, const char *buf, int len, int flag, struct sockaddr *addr_p, int addr_p_len);
The send function sends a message, contained in buf, of size len bytes, to a socket that is connected to this socket, as designated by sd.
int recv(int sd, const char *buf, int len, int flag);
int recvfrom(int sd, const char *buf, int len, int flag, struct sockaddr *addr_p, int* addr_p_len);
The recv function receives a message via a socket designated by sid. The message received is copied to buf, and the maximum size of buf is specified in the len argument.
int htons(short var);
int htonl(long var);
int ntohs(short var);
int ntohl(long var);
The htons (host to network short) function converts short values from host byte order (little-endian) to network byte order (big-endian).
The htonl (host to network long) function converts long values from host byte order (little-endian) to network byte order (big-endian).
The ntohs and ntohl functions do the opposites of htons and htonl functions.
int inet_aton(const char *cp, struct in_addr *addr);
Converts the specified string, in the Internet standard dot notation, to an integer value suitable for use as an Internet address. The converted address is in network byte order.
char* inet_ntoa(struct in_addr in);
Converts the specified Internet host address to a string in the Internet standard dot notation.
|