获取自己的外部IP地址POSIXÇ [英] Obtaining Own External IP Address in POSIX C

查看:261
本文介绍了获取自己的外部IP地址POSIXÇ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找获得以将该信息发布到一个对等网络的网络我自己的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地址,可能是因为不同的, NAT 的杂牌这是不幸的是很常见的。使用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地址,您将需要为此做了一个协议,如​​的 STUN RFC 5389 )。有公共STUN服务器以及现有的 STUN客户用C

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.

所有对等网络程序也有类似的问题,所以要学会别人在做什么,我强烈建议阅读的 RFC 5128,跨越对等网络(P2P)通信的状态网络地址转换(NAT)

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Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆