tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

tap interface address



Hi,

Am trying to open a tap(4) device and get the interface address, but
SIOCGIFADDR does not work (though it seems that it should, looking at the
if_tap.c code and ether_ioctl()) No error is produced but nothing is
returned. test program attached, output (with linewraps added) is:

name: tap0
dump:
74 61 70 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

is there a some incantation I must do?  There does get printed on the
console a message:

tap0: Ethernet address f2:0b:a4:60:f5:03
tap0: detached

and I worked out how to change the physical address using SIOCSIFPHYADDR
but I wanted to see what the address actually was as reported by ifconfig
(I got lost in the twisty passages there, not sure how it gets it)

the tap(4) manpage mentions a sysctl node but that seems overcomplicated

regards,
iain
#include <sys/ioctl.h>

#include <net/if.h>
#include <net/if_tap.h>

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int ac, char *av[])
{
        struct ifreq ifr;
        int fd, i;
        uint8_t *p;

        fd = open("/dev/tap", O_RDWR);
        if (fd == -1)
                exit(EXIT_FAILURE);

        memset(&ifr, 0, sizeof(ifr));
        if (ioctl(fd, TAPGIFNAME, &ifr) == -1)
                exit(EXIT_FAILURE);

        if (ioctl(fd, SIOCGIFADDR, &ifr) == -1)
                exit(EXIT_FAILURE);

        printf("name: %s\n", ifr.ifr_name);
        printf("dump:\n");

        p = (uint8_t *)&ifr;
        for (i = 0; i < sizeof(ifr); i++)
                printf("%2.2x ", p[i]);

        printf("\n");

        close(fd);
}


Home | Main Index | Thread Index | Old Index