Structure
1. struct in_addr
struct in_addr
{
unsigned long s_addr; // inet_aton() ... 用法可參考下面的 API
};
2. in_addr_t
unsigned long s_addr; // inet_aton() ... 用法可參考下面的 API
};
2. in_addr_t
typedef u_int32_t in_addr_t; // type = unsigned long
API
1. convert "struct in_addr" to string
char *inet_ntoa( struct in_addr in );
2. convert "string" to "struct in_addr"
2. convert "string" to "struct in_addr"
int inet_aton( char *cp, struct in_addr *in );
3. convert "string" to "in_addr_t"
in_addr_t inet_addr( char * cp );
補充
在 socket programming 常用的 structure: struct sockaddr_in
struct sockaddr_in
{short sin_family; // AF_INET
u_short sin_port; // htons(80)
struct in_addr sin_addr;
char sin_zero;
};
沒有留言:
張貼留言