在windows/linux下有下面結構:
sockaddr結構
基本介紹
- 外文名:sockaddr_in
- 屬性:windows/linux下的網路編程結構
- 庫檔案:netinet/in.h
- 結構類型:sockaddr結構
基本結構
struct sockaddr_in{short sin_family;/*Address family一般來說AF_INET(地址族)PF_INET(協定族)*/unsigned short sin_port;/*Port number(必須要採用網路數據格式,普通數字可以用htons()函式轉換成網路數據格式的數字)*/struct in_addr sin_addr;/*IP address in network byte order(Internet address)*/unsigned char sin_zero[8];/*Same size as struct sockaddr沒有實際意義,只是為了 跟SOCKADDR結構在記憶體中對齊*/};
struct sockaddr_in{ #if(_WIN32_WINNT<0x0600) short sin_family; #else//(_WIN32_WINNT<0x0600) address_family sin_family; #endif//(_WIN32_WINNT<0x0600) ushort sin_port; in_addr sin_addr; char sin_zero[8];}
struct sockaddr_in { short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8];};
typedef uint32_t in_addr_t;struct in_addr { in_addr_t s_addr; };
typedef struct in_addr{ union{ struct { unsigned char s_b1,s_b2,s_b3,s_b4; } S_un_b; struct { unsigned short s_w1,s_w2; } S_un_w; unsigned long S_addr; }S_un;}in_addr;