Obtaining Own External IP Address in POSIX C

前端 未结 6 1670
长发绾君心
长发绾君心 2021-01-06 19:48

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

6条回答
  •  不思量自难忘°
    2021-01-06 20:47

    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.

    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)".

提交回复
热议问题