Is it possible to get network interface index not via /sys?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
7
down vote

favorite












So what I'm looking for is an interface index (or name) but the real one.
if_nametoindex(3) and ioctl(2) don't seem to help me here. Now the only way I found how to do this is via /sys. Let me demonstrate on example what I need:



# cat /sys/class/net/bond0.1007/ifindex 
26
# cat /sys/class/net/bond0.1007/iflink
23 <-- I need either this or a reference to bond0
# cat /sys/class/net/bond0/ifindex
23


Is there a way to do it with a function call or the only way is sysfs?
Thanks










share|improve this question





















  • Look at what ip link show does (probably using the netlink api)
    – Stéphane Chazelas
    Aug 14 '14 at 14:01










  • See also /proc/net/vlan/config or /proc/net/vlan/bond0.1007 if it's a vlan interface.
    – Stéphane Chazelas
    Aug 14 '14 at 14:02










  • @StéphaneChazelas Thanks. I decided to keep using /sys. /proc or /sys are more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
    – UVV
    Aug 15 '14 at 10:39






  • 1




    the syscalls would be the sendmsg/recvmsg using the netlink socket API.
    – Stéphane Chazelas
    Aug 15 '14 at 10:52






  • 1




    rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue RTM_GETLINK message and look for IFLA_LINK attribute in reply.
    – ecatmur
    Mar 23 '15 at 19:50














up vote
7
down vote

favorite












So what I'm looking for is an interface index (or name) but the real one.
if_nametoindex(3) and ioctl(2) don't seem to help me here. Now the only way I found how to do this is via /sys. Let me demonstrate on example what I need:



# cat /sys/class/net/bond0.1007/ifindex 
26
# cat /sys/class/net/bond0.1007/iflink
23 <-- I need either this or a reference to bond0
# cat /sys/class/net/bond0/ifindex
23


Is there a way to do it with a function call or the only way is sysfs?
Thanks










share|improve this question





















  • Look at what ip link show does (probably using the netlink api)
    – Stéphane Chazelas
    Aug 14 '14 at 14:01










  • See also /proc/net/vlan/config or /proc/net/vlan/bond0.1007 if it's a vlan interface.
    – Stéphane Chazelas
    Aug 14 '14 at 14:02










  • @StéphaneChazelas Thanks. I decided to keep using /sys. /proc or /sys are more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
    – UVV
    Aug 15 '14 at 10:39






  • 1




    the syscalls would be the sendmsg/recvmsg using the netlink socket API.
    – Stéphane Chazelas
    Aug 15 '14 at 10:52






  • 1




    rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue RTM_GETLINK message and look for IFLA_LINK attribute in reply.
    – ecatmur
    Mar 23 '15 at 19:50












up vote
7
down vote

favorite









up vote
7
down vote

favorite











So what I'm looking for is an interface index (or name) but the real one.
if_nametoindex(3) and ioctl(2) don't seem to help me here. Now the only way I found how to do this is via /sys. Let me demonstrate on example what I need:



# cat /sys/class/net/bond0.1007/ifindex 
26
# cat /sys/class/net/bond0.1007/iflink
23 <-- I need either this or a reference to bond0
# cat /sys/class/net/bond0/ifindex
23


Is there a way to do it with a function call or the only way is sysfs?
Thanks










share|improve this question













So what I'm looking for is an interface index (or name) but the real one.
if_nametoindex(3) and ioctl(2) don't seem to help me here. Now the only way I found how to do this is via /sys. Let me demonstrate on example what I need:



# cat /sys/class/net/bond0.1007/ifindex 
26
# cat /sys/class/net/bond0.1007/iflink
23 <-- I need either this or a reference to bond0
# cat /sys/class/net/bond0/ifindex
23


Is there a way to do it with a function call or the only way is sysfs?
Thanks







sysfs network-interface ioctl






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 14 '14 at 10:35









UVV

2,0651325




2,0651325











  • Look at what ip link show does (probably using the netlink api)
    – Stéphane Chazelas
    Aug 14 '14 at 14:01










  • See also /proc/net/vlan/config or /proc/net/vlan/bond0.1007 if it's a vlan interface.
    – Stéphane Chazelas
    Aug 14 '14 at 14:02










  • @StéphaneChazelas Thanks. I decided to keep using /sys. /proc or /sys are more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
    – UVV
    Aug 15 '14 at 10:39






  • 1




    the syscalls would be the sendmsg/recvmsg using the netlink socket API.
    – Stéphane Chazelas
    Aug 15 '14 at 10:52






  • 1




    rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue RTM_GETLINK message and look for IFLA_LINK attribute in reply.
    – ecatmur
    Mar 23 '15 at 19:50
















  • Look at what ip link show does (probably using the netlink api)
    – Stéphane Chazelas
    Aug 14 '14 at 14:01










  • See also /proc/net/vlan/config or /proc/net/vlan/bond0.1007 if it's a vlan interface.
    – Stéphane Chazelas
    Aug 14 '14 at 14:02










  • @StéphaneChazelas Thanks. I decided to keep using /sys. /proc or /sys are more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
    – UVV
    Aug 15 '14 at 10:39






  • 1




    the syscalls would be the sendmsg/recvmsg using the netlink socket API.
    – Stéphane Chazelas
    Aug 15 '14 at 10:52






  • 1




    rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue RTM_GETLINK message and look for IFLA_LINK attribute in reply.
    – ecatmur
    Mar 23 '15 at 19:50















Look at what ip link show does (probably using the netlink api)
– Stéphane Chazelas
Aug 14 '14 at 14:01




Look at what ip link show does (probably using the netlink api)
– Stéphane Chazelas
Aug 14 '14 at 14:01












See also /proc/net/vlan/config or /proc/net/vlan/bond0.1007 if it's a vlan interface.
– Stéphane Chazelas
Aug 14 '14 at 14:02




See also /proc/net/vlan/config or /proc/net/vlan/bond0.1007 if it's a vlan interface.
– Stéphane Chazelas
Aug 14 '14 at 14:02












@StéphaneChazelas Thanks. I decided to keep using /sys. /proc or /sys are more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
– UVV
Aug 15 '14 at 10:39




@StéphaneChazelas Thanks. I decided to keep using /sys. /proc or /sys are more or less the same in that sense. I just wanted to check if there is a syscall to get this kind of info, it turns out there is not.
– UVV
Aug 15 '14 at 10:39




1




1




the syscalls would be the sendmsg/recvmsg using the netlink socket API.
– Stéphane Chazelas
Aug 15 '14 at 10:52




the syscalls would be the sendmsg/recvmsg using the netlink socket API.
– Stéphane Chazelas
Aug 15 '14 at 10:52




1




1




rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue RTM_GETLINK message and look for IFLA_LINK attribute in reply.
– ecatmur
Mar 23 '15 at 19:50




rtnetlink documentation: man7.org/linux/man-pages/man7/rtnetlink.7.html - issue RTM_GETLINK message and look for IFLA_LINK attribute in reply.
– ecatmur
Mar 23 '15 at 19:50










1 Answer
1






active

oldest

votes

















up vote
0
down vote













The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.



# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f150216%2fis-it-possible-to-get-network-interface-index-not-via-sys%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.



    # ip link show
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
    link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
    3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
    link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
    4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
    link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff





    share|improve this answer
























      up vote
      0
      down vote













      The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.



      # ip link show
      1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
      link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
      3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
      link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
      4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
      link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff





      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.



        # ip link show
        1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
        link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
        3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
        link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
        4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
        link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff





        share|improve this answer












        The command ip link show is probably what you want. It will display the index in front of the interface information. Example below from a system with bonded NICs.



        # ip link show
        1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        2: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000000 state UP mode DEFAULT qlen 1000
        link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
        3: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9214 qdisc mq master bond0 portid 000f53000001 state UP mode DEFAULT qlen 1000
        link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff
        4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9214 qdisc noqueue state UP mode DEFAULT qlen 1000
        link/ether 00:0f:53:00:00:00 brd ff:ff:ff:ff:ff:ff






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 7 at 19:53









        Boscoe

        1364




        1364



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f150216%2fis-it-possible-to-get-network-interface-index-not-via-sys%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)