开发者

How to get the current ip address in C++ [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

get global ip address

I 开发者_StackOverflow中文版am wondering is there anyway to get the ipv4 address easily?


For the local computer:

Get the IP address of the machine


It depends on the OS your program running on.

For Windows see http://msdn.microsoft.com/en-us/library/aa365915%28v=VS.85%29.aspx


Try Beej's Guide to Network Programming at http://beej.us/guide/bgnet/

There you may find an answer for your platform and the case of multiple addresses.


Actually C++ standard library does not provide any function to get the ip address of a system. The api for that must be provided by the OS on which you are working.

From your question what I understood is you are working on something but your IP keep changing because it is assigned by DHCP, well I may be wrong.

However, for linux you would like to google for inet_ntop

Check this out:
#include <arpa/inet.h>
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜