htonl()函数 返回一个32位的tcp/ip网络字节顺序的数
例如: server.sin_addr.s_addr = htonl(INADDR_ANY);
U_long htonl(
U_long hostlong//一个32位的数,将要转为网络字节顺序
)
htons()函数,里面传得一般式端口号
例如: server.sin_port = htons(8888);
u_short htons(
u_short hostshort//一般传得是端口号
)
ntohl()函数
U_long ntohl(
u_long netlong//一般传得网络地址
)
ntohs()函数 一般传的是网络的端口
u_short ntohs(
u_short netshort//网络端口
)
inet_addr()函数
ser.sin_addr.s_addr = inet_addr(“127.0.0.1”);
unsiged long inet_addr(
const char FAR*cp//传入的时点形式的IP地址。例如127.0.0.1
)
inet_ntoa()函数
inet_ntoa(cli.sin_addr)
inet_ntoa(
struct in_addr in
)
-gethostname()
int gethostname(
char FAR*name,//指向将要存放缓冲区的指针,调用完以后主机名被存入这个缓冲区
int namelen//缓冲区长度
)
getpeername()函数
int getpeername(
SOCKET s,//传入参数,已建立连接的套接口
struct sockaddr FAR* name,//传出参数,指向返回远程协议的地址
int FAR* namelen//传出参数,远程协议地址长度
)
getsockname()函数
int getsockname(
SOCKET s,//传入参数,已连接的套接口
struct sockaddr FAR*name,//传出参数,返回本地协议的指针
int FAR* namelen//传出参数,本地协议地址长度
)
gethostbyname()函数
struct hostent FAR*gethostbyname (
const char FAR* name
)
gethostbyaddr()函数
struct hostent FAR* gethostbyaddr(
const char FAR* addr,//传入参数,网络字节顺序地址的指针
int len,//传入参数,地址的长度 ipv4则为4
int type//传入参数,地址类型,例如 AF_INET
)
getprotobyname()
struct protoent FAR *getprotobyname(
const char FAR*name//指向协议名的指针
)
getprotobynumber()函数
struct protoent FAR*getprotobynumber(
int number//以主机字节排列的协议号
)
getservbyport()函数
struct servent FAR* getservbyport(
int port,//传入参数,给定的端口号,以网络字节顺序排列
const char FAR*proto//传入参数,指向协议名的指针
)