diff options
| author | ozaki-r <ozaki-r@NetBSD.org> | 2014-11-21 06:03:04 +0000 |
|---|---|---|
| committer | ozaki-r <ozaki-r@NetBSD.org> | 2014-11-21 06:03:04 +0000 |
| commit | ff8545f79ae324d5b14f61c3d28057f04a26321f (patch) | |
| tree | 88fb767b50069ba0c454b71b3e0685b2806d9f4b /sys/compat/linux/common/linux_socket.c | |
| parent | eb6b57ce4770f16eab7f9399b3e74c2fa6d44c04 (diff) | |
Tweak linux_getifhwaddr
No functional change.
Diffstat (limited to 'sys/compat/linux/common/linux_socket.c')
| -rw-r--r-- | sys/compat/linux/common/linux_socket.c | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/sys/compat/linux/common/linux_socket.c b/sys/compat/linux/common/linux_socket.c index 2be483875c3..18b8682b9f0 100644 --- a/sys/compat/linux/common/linux_socket.c +++ b/sys/compat/linux/common/linux_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_socket.c,v 1.120 2014/11/09 17:48:08 maxv Exp $ */ +/* $NetBSD: linux_socket.c,v 1.121 2014/11/21 06:03:04 ozaki-r Exp $ */ /*- * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.120 2014/11/09 17:48:08 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.121 2014/11/21 06:03:04 ozaki-r Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -1234,45 +1234,46 @@ linux_getifhwaddr(struct lwp *l, register_t *retval, u_int fd, } } - if (strncmp(lreq.ifr_name, "eth", 3) == 0) { - for (ifnum = 0, index = 3; - index < LINUX_IFNAMSIZ && lreq.ifr_name[index] != '\0'; - index++) { - ifnum *= 10; - ifnum += lreq.ifr_name[index] - '0'; - } - - error = EINVAL; /* in case we don't find one */ - found = 0; - IFNET_FOREACH(ifp) { - if (found) - break; - memcpy(lreq.ifr_name, ifp->if_xname, - MIN(LINUX_IFNAMSIZ, IFNAMSIZ)); - IFADDR_FOREACH(ifa, ifp) { - sadl = satosdl(ifa->ifa_addr); - /* only return ethernet addresses */ - /* XXX what about FDDI, etc. ? */ - if (sadl->sdl_family != AF_LINK || - sadl->sdl_type != IFT_ETHER) - continue; - if (ifnum--) - /* not the reqested iface */ - continue; - memcpy(&lreq.ifr_hwaddr.sa_data, - CLLADDR(sadl), - MIN(sadl->sdl_alen, - sizeof(lreq.ifr_hwaddr.sa_data))); - lreq.ifr_hwaddr.sa_family = - sadl->sdl_family; - error = copyout(&lreq, data, sizeof(lreq)); - found = 1; - break; - } - } - } else { + if (strncmp(lreq.ifr_name, "eth", 3) != 0) { /* unknown interface, not even an "eth*" name */ error = ENODEV; + goto out; + } + + for (ifnum = 0, index = 3; + index < LINUX_IFNAMSIZ && lreq.ifr_name[index] != '\0'; + index++) { + ifnum *= 10; + ifnum += lreq.ifr_name[index] - '0'; + } + + error = EINVAL; /* in case we don't find one */ + found = 0; + IFNET_FOREACH(ifp) { + if (found) + break; + memcpy(lreq.ifr_name, ifp->if_xname, + MIN(LINUX_IFNAMSIZ, IFNAMSIZ)); + IFADDR_FOREACH(ifa, ifp) { + sadl = satosdl(ifa->ifa_addr); + /* only return ethernet addresses */ + /* XXX what about FDDI, etc. ? */ + if (sadl->sdl_family != AF_LINK || + sadl->sdl_type != IFT_ETHER) + continue; + if (ifnum--) + /* not the reqested iface */ + continue; + memcpy(&lreq.ifr_hwaddr.sa_data, + CLLADDR(sadl), + MIN(sadl->sdl_alen, + sizeof(lreq.ifr_hwaddr.sa_data))); + lreq.ifr_hwaddr.sa_family = + sadl->sdl_family; + error = copyout(&lreq, data, sizeof(lreq)); + found = 1; + break; + } } out: |
