I learned a lot from this site:
Beej's Guide to Network Programming
I learned a lot from this site:
Beej's Guide to Network Programming
Here is the workaround how to get source ip. (It is adopted part from iputils)
Code:int probe_fd = socket(AF_INET,SOCK_DGRAM,0); struct sockaddr_in dst; dst.sin_family = AF_INET; connect(probe_fd, (struct sockaddr*)&dst, sizeof(dst)); socklen_t alen = sizeof(dst); getsockname(probe_fd, (struct sockaddr*)&dst, &alen); close(probe_fd); printf("Source: %s\n",inet_ntoa(dst.sin_addr));