Provide SIOCGIFNAME.

This commit is contained in:
joerg 2009-11-13 21:45:03 +00:00
parent f3583ee6ce
commit 8277e92195
4 changed files with 69 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_socket.c,v 1.104 2009/06/17 14:18:51 njoly Exp $ */
/* $NetBSD: linux_socket.c,v 1.105 2009/11/13 21:45:03 joerg 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.104 2009/06/17 14:18:51 njoly Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.105 2009/11/13 21:45:03 joerg Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@ -114,6 +114,7 @@ int linux_to_bsd_so_sockopt(int);
int linux_to_bsd_ip_sockopt(int);
int linux_to_bsd_tcp_sockopt(int);
int linux_to_bsd_udp_sockopt(int);
int linux_getifname(struct lwp *, register_t *, void *);
int linux_getifconf(struct lwp *, register_t *, void *);
int linux_getifhwaddr(struct lwp *, register_t *, u_int, void *);
static int linux_get_sa(struct lwp *, int, struct mbuf **,
@ -1004,6 +1005,31 @@ linux_sys_getsockopt(struct lwp *l, const struct linux_sys_getsockopt_args *uap,
return sys_getsockopt(l, &bga, retval);
}
int
linux_getifname(struct lwp *l, register_t *retval, void *data)
{
struct ifnet *ifp;
struct linux_ifreq ifr;
int error;
error = copyin(data, &ifr, sizeof(ifr));
if (error)
return error;
if (ifr.ifr_ifru.ifru_ifindex >= if_indexlim)
return ENODEV;
ifp = ifindex2ifnet[ifr.ifr_ifru.ifru_ifindex];
if (ifp == NULL)
return ENODEV;
strncpy(ifr.ifr_name, ifp->if_xname, sizeof(ifr.ifr_name));
error = copyout(&ifr, data, sizeof(ifr));
return 0;
}
int
linux_getifconf(struct lwp *l, register_t *retval, void *data)
{
@ -1225,6 +1251,10 @@ linux_ioctl_socket(struct lwp *l, const struct linux_sys_ioctl_args *uap, regist
retval[0] = 0;
switch (com) {
case LINUX_SIOCGIFNAME:
error = linux_getifname(l, retval, SCARG(uap, data));
dosys = 0;
break;
case LINUX_SIOCGIFCONF:
error = linux_getifconf(l, retval, SCARG(uap, data));
dosys = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_sockio.h,v 1.16 2008/07/03 14:07:09 njoly Exp $ */
/* $NetBSD: linux_sockio.h,v 1.17 2009/11/13 21:45:03 joerg Exp $ */
/*-
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@ -32,6 +32,7 @@
#ifndef _LINUX_SOCKIO_H
#define _LINUX_SOCKIO_H
#define LINUX_SIOCGIFNAME _LINUX_IO(0x89, 0x10)
#define LINUX_SIOCGIFCONF _LINUX_IO(0x89, 0x12)
#define LINUX_SIOCGIFFLAGS _LINUX_IO(0x89, 0x13)
#define LINUX_SIOCSIFFLAGS _LINUX_IO(0x89, 0x14)
@ -66,6 +67,7 @@ struct linux_ifreq {
struct osockaddr ifru_addr;
struct osockaddr ifru_hwaddr;
struct linux_ifmap ifru_map;
int ifru_ifindex;
} ifr_ifru;
#define ifr_name ifr_ifrn.ifrn_name /* interface name */
#define ifr_addr ifr_ifru.ifru_addr /* address */

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux32_socket.c,v 1.10 2008/11/19 18:36:04 ad Exp $ */
/* $NetBSD: linux32_socket.c,v 1.11 2009/11/13 21:45:03 joerg Exp $ */
/*-
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@ -33,7 +33,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.10 2008/11/19 18:36:04 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.11 2009/11/13 21:45:03 joerg Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -91,6 +91,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.10 2008/11/19 18:36:04 ad Exp $
#include <compat/linux32/common/linux32_ioctl.h>
#include <compat/linux32/linux32_syscallargs.h>
int linux32_getifname(struct lwp *, register_t *, void *);
int linux32_getifconf(struct lwp *, register_t *, void *);
int linux32_getifhwaddr(struct lwp *, register_t *, u_int, void *);
@ -386,6 +387,31 @@ linux32_sys_recv(struct lwp *l, const struct linux32_sys_recv_args *uap, registe
return sys_recvfrom(l, &ua, retval);
}
int
linux32_getifname(struct lwp *l, register_t *retval, void *data)
{
struct ifnet *ifp;
struct linux32_ifreq ifr;
int error;
error = copyin(data, &ifr, sizeof(ifr));
if (error)
return error;
if (ifr.ifr_ifru.ifru_ifindex >= if_indexlim)
return ENODEV;
ifp = ifindex2ifnet[ifr.ifr_ifru.ifru_ifindex];
if (ifp == NULL)
return ENODEV;
strncpy(ifr.ifr_name, ifp->if_xname, sizeof(ifr.ifr_name));
error = copyout(&ifr, data, sizeof(ifr));
return 0;
}
int
linux32_getifconf(struct lwp *l, register_t *retval, void *data)
{
@ -606,6 +632,10 @@ linux32_ioctl_socket(struct lwp *l, const struct linux32_sys_ioctl_args *uap, re
retval[0] = 0;
switch (com) {
case LINUX_SIOCGIFNAME:
error = linux32_getifname(l, retval, SCARG_P32(uap, data));
dosys = 0;
break;
case LINUX_SIOCGIFCONF:
error = linux32_getifconf(l, retval, SCARG_P32(uap, data));
dosys = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux32_sockio.h,v 1.2 2008/07/23 12:32:09 njoly Exp $ */
/* $NetBSD: linux32_sockio.h,v 1.3 2009/11/13 21:45:03 joerg Exp $ */
/*
* Copyright (c) 2008 Nicolas Joly
@ -48,6 +48,7 @@ struct linux32_ifreq {
struct osockaddr ifru_addr;
struct osockaddr ifru_hwaddr;
struct linux32_ifmap ifru_map;
int ifru_ifindex;
} ifr_ifru;
#define ifr_name ifr_ifrn.ifrn_name /* interface name */
#define ifr_addr ifr_ifru.ifru_addr /* address */