Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

struct ifreq : different definition in "linux/if.h" and man page

In online manual page netdevice(7) - Linux man page, the definition of ifreq structure is given as:

struct ifreq {
               char ifr_name[IFNAMSIZ]; /* Interface name */
               union {
                   struct sockaddr ifr_addr;
                   struct sockaddr ifr_dstaddr;
                   struct sockaddr ifr_broadaddr;
                   struct sockaddr ifr_netmask;
                   struct sockaddr ifr_hwaddr;
                   short           ifr_flags;
                   int             ifr_ifindex;
                   int             ifr_metric;
                   int             ifr_mtu;
                   struct ifmap    ifr_map;
                   char            ifr_slave[IFNAMSIZ];
                   char            ifr_newname[IFNAMSIZ];
                   char           *ifr_data;
               };
           };

But my linux header shows different definition. Below is the definition from /usr/include/linux/if.h The kernel version I'm using is Linux 3.18

struct ifreq {
#define IFHWADDRLEN 6
    union
    {
        char    ifrn_name[IFNAMSIZ];        /* if name, e.g. "en0" */
    } ifr_ifrn;

    union {
        struct  sockaddr ifru_addr;
        struct  sockaddr ifru_dstaddr;
        struct  sockaddr ifru_broadaddr;
        struct  sockaddr ifru_netmask;
        struct  sockaddr ifru_hwaddr;
        short   ifru_flags;
        int ifru_ivalue;
        int ifru_mtu;
        struct  ifmap ifru_map;
        char    ifru_slave[IFNAMSIZ];   /* Just fits the size */
        char    ifru_newname[IFNAMSIZ];
        void *  ifru_data;
        struct  if_settings ifru_settings;
    } ifr_ifru;
};

Why is this change made ? Which one should I stick to for portability with different linux distros ?

like image 440
anoop.babu Avatar asked Oct 14 '15 08:10

anoop.babu


1 Answers

Different header files; linux/if.h and net/if.h are similar, but unless you're working against the linux kernel and not the linux userspace, you probably want to use net/if.h.

like image 96
Daniel Beecham Avatar answered Sep 20 '22 16:09

Daniel Beecham