#include <netinet/in.h>
1、socketaddr_in 结构体
struct sockaddr_in
eg:
#define SERV_PORT 6666
struct sockaddr_in serveraddr;
serveraddr.sin_family=AF_INET;
serveraddr.sin_port=htons(SERV_PORT);
2、htons系统调用
extern uint16_t htons (uint16_t __hostshort)
__THROW __attribute__ ((__const__));
eg:
#define SERV_PORT 6666
serveraddr.sin_port=htons(SERV_PORT);