Getting IP address from an interface in C
My program (in C) sends data via 4 interfaces. ppp0,ppp1,ppp2,ppp3. I have to find a way to get the IP address of each of the sending interfaces and I have to log these IP addresses. The program reads data from a file and sends it to the server. It has to also send the IP address to the server. What function can I use? and where do I put it? Any help would be appreciated.
int i; for (i = 0; i < 4; i++){ if (setsockopt(client_socket, SOL_SOCKET, SO_BINDTODEVICE, ifname[i], strlen(ifname[i]) + 1) ==-1) { printf ("Error setting interface %s \n", ifname[i]); perror("XXX "); } else{ printf("about to connect ip addr %s\n", ServerIPAddr); if (connect(client_socket, (struct sockaddr *)&server_ssin, sizeof(struct sockaddr_in)) == -1 ) { printf ("Error connecting to server from interface %s \n", ifname[i]); } else { printf("Connected to server on port %d from interface %s \n", dport, ifname[i]); break; } } } int data_read=0; while ((data_read = read(file_tosend, buffer, BUFF_SIZE)) > 0){ if ((data = send(client_socket, buffer, data_read, 0)) == -1) { printf("Error sending data to server\n"); return -1; } total_sent += data; memset(buffer, 0x0, BUFF_SIZE); } IT IS URGENTLY NEEDED Thank you in advance |
|
and if u look around more on my main page u'll see a guide to netlink, which can also do this for u, although a bit more complex.
|
All times are GMT -5. The time now is 09:56 AM. |