getting IP addresses of network interfaces on Linux box

Apr 06, 2007 1 Replies

HI all, I need to know is there anyway I can get the IP addresses of Network interfaces (i.e. physical and logical) on my Linux box through socket APIs?



Thanks, B



There are IOCTL's you can call on a socket fd, something like this, from the top of my head:

int fd; strict ifreq ifr; struct sockaddr_sin *sa; fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); strcpy(ifr.ifr_name, ifname); /* Don't use strcpy */ ioctl(fd, SIOGCIFADDR, &ifr); sa = (struct sockaddr_in *)(ifr.ifr_addr);

:wq ^X^Cy^K^X^C^C^C^C

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required