顯示具有 linux program 標籤的文章。 顯示所有文章
顯示具有 linux program 標籤的文章。 顯示所有文章

2008年4月10日 星期四

network related API

receive a message from a socket

ssize_t recvfrom (int socket, void *restrict buffer, size_t length,
int flags, struct sockaddr *restrict address,
socklen_t *restrict address_len);

ssize_t sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);

2008年3月4日 星期二

inet_ntoa

inet_ntoa:
converts a network address in a struct in_addr to a dots-and-numbers format string.

inet_aton:
inet_aton() is the opposite, converting from a dots-and-numbers string into a in_addr_t

struct sockaddr and sockaddr_in and in_addr

struct sockaddr
{
unsigned short sa_family; /* address family, AF_xxx */
char sa_data[14]; /* 14 bytes of protocol address */
};


struct sockaddr_in
{
short int sin_family; /* Address family */
unsigned short int sin_port; /* Port number */
struct in_addr sin_addr; /* Internet address */
unsigned char sin_zero[8]; /* Same size as struct sockaddr */
};

struct in_addr
{
in_addr_t s_addr;
};

2008年3月3日 星期一

select

int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);

If timeout is NULL , select will return after get sthing

getaddrinfo

#include
#include
#include

int ai_flags Input flags.
int ai_family Address family of socket.
int ai_socktype Socket type.
int ai_protocol Protocol of socket.
socklen_t ai_addrlen Length of socket address.
struct sockaddr *ai_addr Socket address of socket.
char *ai_canonname Canonical name of service location.
struct addrinfo *ai_next Pointer to next in list.