I am writing a program in C++ which uses network sockets. I need to find out what the computer's IP address is, so I can display it to the user. The program must run on Windows and Linux.
I have heard somewhere that a computer can have multiple IP addresses. I want the one that other programs on different computers can use to connect to the computer.
Here is the relevant code I already have (the variables are declared in other places):
master = new fd_set;
FD_ZERO(master);
struct sockaddr_in my_addr;
listener = socket(PF_INET, SOCK_STREAM, 0);
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(port);
my_addr.sin_addr.s_addr = INADDR_ANY;
memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero);
bind(listener, (struct sockaddr *)&my_addr, sizeof my_addr);
listen(listener, 10);
FD_SET(listener, master);
fdmax = listener;