[Bug 235920] ifconfig: unable to create another interface after renaming the previous one with the same name

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Feb 21 17:22:23 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235920

--- Comment #1 from olevole at olevole.ru ---
We can test that the interface is actually renamed via ioctl() via:

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <sys/ioctl.h>

-------
int list_devices() {

    char data[4096];
    struct ifconf ifc;
    struct ifreq *ifr;
    int sk,length;
    unsigned int idx;

    sk = socket(AF_INET, SOCK_DGRAM, 0);
    if(sk < 0)
    {
        perror("socket");
        return 0;
    }

    ifc.ifc_len = sizeof(data);
    ifc.ifc_buf = (caddr_t)data;
    if(ioctl(sk, SIOCGIFCONF, &ifc) < 0)
    {
        perror("ioctl(SIOCGIFCONF)");
        return 0;
    }

    ifr = (struct ifreq*)data;
    for(int i=0;i<ifc.ifc_len;)
    {
        length=IFNAMSIZ + ifr->ifr_addr.sa_len;
        idx=if_nametoindex(ifr->ifr_name);
        printf("Found: %s [index: %d]\n", ifr->ifr_name,idx);
        ifr=(struct ifr*)((char*)ifr+length);
        i+=length;
    }

    return 0;
}
----------

ifr->ifr_name is changing, but the index is the same (and this is normal?).
However, some information remains from the old interface, and this affects
http://man.freebsd.org/alloc_unr_specific/9

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list