开发者

use inet_pton to store computed network address in ''struct in6_addr'' or "struct in6_addr.sin6_addr"

Convert a text host address to a numeric address

int inet_pton( int af, const char * src, void * dst );

I have seen two different usages of this functions as follows:

Example 1:

http://man7.org/tlpi/code/online/book/sockets/i6d_ucase_cl.c.html

struct sockaddr_in6 svaddr;
...
inet_pton(AF_INET6, argv[1], &svaddr.sin6_addr)

Example 2:

http://www.qnx.com/developers/docs/6.4.1/neutrino/l开发者_如何学Pythonib_ref/i/inet_pton.html

struct in6_addr in6addr;
...
inet_pton(AF_INET6, IN6ADDR, &in6addr))

Which one is correct? If all of them are correct, why each of them store the converted network address into totally different data structure?


It's the same structure: svaddr.sin6_addr is of type struct in6_addr.

netinet/in.h

The header shall define the sockaddr_in6 structure, which shall include at least the following members:

...
struct in6_addr  sin6_addr      IPv6 address.

As a mater of fact, anything that has enough size will do, as inet_pton is:

int inet_pton(int af, const char *restrict src, void *restrict dst);
                                                ^ anything
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜