getting IP addresses of network interfaces on Linux box

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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


Re: getting IP addresses of network interfaces on Linux box

Quoted text here. Click to load it

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

Site Timeline