Socket Programming under Linux System
IPv4
sin_addr is 32-bit IP address
1
2
3
4
5
6
7
8
9
10
11
12struct sockaddr_in
{
__SOCKADDR_COMMON (sin_);
in_port_t sin_port; /* Port number. */
struct in_addr sin_addr; /* Internet address. */
/* Pad to size of `struct sockaddr'. */
unsigned char sin_zero[sizeof (struct sockaddr)
- __SOCKADDR_COMMON_SIZE
- sizeof (in_port_t)
- sizeof (struct in_addr)];
};点分十进制字符串 & type(in_addr) 转换
1
2
3
4
5
6
7/* point decimal string -> in_addr functions */
int inet_aton (const char *strptr, struct in_addr * addrptr);
in_addr_t inet_addr(const char* strptr);
int inet_pton(int family, const void * addrptr, char *strptr, size_t len);
/* in_addr functions -> point decimal string */
char *inet_ntoa(struct in_addr inaddr);
const char *inet_ntop(int family, const void* addrptr, char* strptr, size_t len);