How to get the current ip address in C++ [duplicate]
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);
精彩评论