tech-net archive

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

Re: tap interface address

On Mon, 11 Aug 2008, der Mouse wrote:

> > So, how do I get to the ethernet address? (technically, it does not
> > have any address family protocol code :)
> I thought that's what AF_LINK was for...?

Ok, I admit it.

        s = socket(PF_LINK, SOCK_DGRAM, 0);

        memset(&iflr, 0, sizeof(iflr));
        memcpy(iflr.iflr_name, ifr.ifr_name, IFNAMSIZ);

        sdl = (struct sockaddr_dl *)&iflr.addr;
        sdl->sdl_family = AF_LINK;
        sdl->sdl_len = sizeof(struct sockaddr_dl);
        sdl->sdl_alen = ETHER_ADDR_LEN;

        if (ioctl(s, SIOCGLIFADDR, &iflr) == -1) {
                syslog(LOG_ERR, "Could not get interface address: %m");

gives me the address with CLLADDR(sdl), thanks!


Home | Main Index | Thread Index | Old Index