Re: How to get network interface info only with its name

From: Glynn Clements (
Date: Thu Mar 02 2000 - 04:39:12 EST

Jaekwon Oh wrote:

> Now, I'm trying to get the network device's MAC address and IP address
> only with its interface name.

#include <net/if.h>

static void device_addresses(const char *if_name)
        struct ifreq req;
        int fd = socket(PF_INET, SOCK_DGRAM, 0);

        strcpy(req.ifr_name, if_name);
        req.ifr_addr.sa_family = AF_INET;

        ioctl(fd, SIOCGIFHWADDR, &req);

        ioctl(fd, SIOCGIFADDR, &req);

Glynn Clements <>

- To unsubscribe from this list: send the line "unsubscribe linux-net" in the body of a message to

This archive was generated by hypermail 2b29 : Tue Mar 07 2000 - 21:00:27 EST