问题描述
我在寻找获得以将该信息发布到一个对等网络的网络我自己的IP地址。在POSIX / C,我们有的getaddrinfo(NULL,...)
,但这似乎总是返回 INADDR_ANY
或 INADDR_LOOPBACK
,这对我没用。
I'm looking to obtain my own IP address in order to publish that information in to a Peer-to-Peer network. In POSIX/C we have getaddrinfo(NULL, ...)
, but this always seems to returns INADDR_ANY
or INADDR_LOOPBACK
, which is useless to me.
有什么建议?
推荐答案
其中一个问题是,即使你的本地IP地址,由网络的其余部分看到的IP地址,可能是因为不同的, 的杂牌这是不幸的是很常见的。使用IPv6可能会坐席preSS这个问题,但它可能不是一个选择,现在。
One of the problems is that, even if you get the local IP address, the IP address seen by the rest of the Internet may be different, because of the kludge of NAT which is unfortunately very common. Using IPv6 probably will suppress this problem but it may not be an option for you, now.
要获得公开 IP地址,您将需要为此做了一个协议,如的()。有以及现有的。
To get the public IP address, you will need a protocol made for that purpose such as STUN (RFC 5389). There are public STUN servers and already existing STUN clients in C.
所有对等网络程序也有类似的问题,所以要学会别人在做什么,我强烈建议阅读的。
All the peer-to-peer programs have similar issues, so learn what others are doing, I strongly recommend reading RFC 5128, "State of Peer-to-Peer (P2P) Communication across Network Address Translators (NATs)".
这篇关于获取自己的外部IP地址POSIXÇ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!