tech-userlevel archive

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

Re: interface name optional in wake(8)



>> Make the interface name argument to wake(8) optional. If the first argument
>> given to wake(8) is not the name of a local ethernet interface, wake(8)
>> determines the first ethernet device in the system and uses it instead.
>> 
>> With the interface name being optional, scripts using wake(8) can work
>> unaltered on machines with different ethernet devices.

[...]

In a discussion with joerg@ we found that just checking for AF_LINK and 
IFT_ETHER might give us the wrong interface.  So at least also check IFF_UP and 
IFF_RUNNING to make sure we get an ethernet interface that is up and running:

static int
find_ether(char *dst, size_t len)
{
        struct ifaddrs *ifap, *ifa;
        struct sockaddr_dl *sdl = NULL;

        if (dst == NULL || len == 0)
                return 0;

        if (getifaddrs(&ifap) != 0)
                return -1;

        for (ifa = ifap; ifa; ifa = ifa->ifa_next)
                if (ifa->ifa_addr->sa_family == AF_LINK &&
                    ifa->ifa_flags & IFF_UP && ifa->ifa_flags & IFF_RUNNING) {
                        sdl = (struct sockaddr_dl *)ifa->ifa_addr;
                        if (sdl->sdl_type == IFT_ETHER) {
                                strlcpy(dst, ifa->ifa_name, len);
                                break;
                        }
                }

        freeifaddrs(ifap);
        return 0;
}



Home | Main Index | Thread Index | Old Index