The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/svr4_32/svr4_32_sockio.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: svr4_32_sockio.c,v 1.9 2005/02/26 23:10:21 perry Exp $  */
    2 
    3 /*-
    4  * Copyright (c) 1995 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Christos Zoulas.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __KERNEL_RCSID(0, "$NetBSD: svr4_32_sockio.c,v 1.9 2005/02/26 23:10:21 perry Exp $");
   41 
   42 #include <sys/param.h>
   43 #include <sys/proc.h>
   44 #include <sys/systm.h>
   45 #include <sys/file.h>
   46 #include <sys/filedesc.h>
   47 #include <sys/ioctl.h>
   48 #include <sys/termios.h>
   49 #include <sys/tty.h>
   50 #include <sys/socket.h>
   51 #include <sys/ioctl.h>
   52 #include <sys/mount.h>
   53 #include <net/if.h>
   54 #include <sys/malloc.h>
   55 
   56 #include <sys/sa.h>
   57 #include <sys/syscallargs.h>
   58 
   59 #include <compat/svr4_32/svr4_32_types.h>
   60 #include <compat/svr4_32/svr4_32_util.h>
   61 #include <compat/svr4_32/svr4_32_signal.h>
   62 #include <compat/svr4_32/svr4_32_lwp.h>
   63 #include <compat/svr4_32/svr4_32_ucontext.h>
   64 #include <compat/svr4_32/svr4_32_syscallargs.h>
   65 #include <compat/svr4_32/svr4_32_stropts.h>
   66 #include <compat/svr4_32/svr4_32_ioctl.h>
   67 #include <compat/svr4_32/svr4_32_sockio.h>
   68 
   69 static int bsd_to_svr4_flags __P((int));
   70 
   71 #define bsd_to_svr4_flag(a) \
   72         if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
   73 
   74 static int
   75 bsd_to_svr4_flags(bf)
   76         int bf;
   77 {
   78         int sf = 0;
   79         bsd_to_svr4_flag(FF_UP);
   80         bsd_to_svr4_flag(FF_BROADCAST);
   81         bsd_to_svr4_flag(FF_DEBUG);
   82         bsd_to_svr4_flag(FF_LOOPBACK);
   83         bsd_to_svr4_flag(FF_POINTOPOINT);
   84         bsd_to_svr4_flag(FF_NOTRAILERS);
   85         bsd_to_svr4_flag(FF_RUNNING);
   86         bsd_to_svr4_flag(FF_NOARP);
   87         bsd_to_svr4_flag(FF_PROMISC);
   88         bsd_to_svr4_flag(FF_ALLMULTI);
   89         bsd_to_svr4_flag(FF_MULTICAST);
   90         return sf;
   91 }
   92 
   93 int
   94 svr4_32_sock_ioctl(fp, l, retval, fd, cmd, data)
   95         struct file *fp;
   96         struct lwp *l;
   97         register_t *retval;
   98         int fd;
   99         u_long cmd;
  100         caddr_t data;
  101 {
  102         struct proc *p = l->l_proc;
  103         int error;
  104         int (*ctl)(struct file *, u_long, void *, struct proc *) =
  105                         fp->f_ops->fo_ioctl;
  106 
  107         *retval = 0;
  108 
  109         switch (cmd) {
  110         case SVR4_SIOCGIFNUM:
  111                 {
  112                         struct ifnet *ifp;
  113                         struct ifaddr *ifa;
  114                         int ifnum = 0;
  115 
  116                         /*
  117                          * This does not return the number of physical
  118                          * interfaces (if_index), but the number of interfaces
  119                          * + addresses like ifconf() does, because this number
  120                          * is used by code that will call SVR4_SIOCGIFCONF to
  121                          * find the space needed for SVR4_SIOCGIFCONF. So we
  122                          * count the number of ifreq entries that the next
  123                          * SVR4_SIOCGIFCONF will return. Maybe a more correct
  124                          * fix is to make SVR4_SIOCGIFCONF return only one
  125                          * entry per physical interface?
  126                          */
  127 
  128                         for (ifp = ifnet.tqh_first;
  129                              ifp != 0; ifp = ifp->if_list.tqe_next)
  130                                 if ((ifa = ifp->if_addrlist.tqh_first) == NULL)
  131                                         ifnum++;
  132                                 else
  133                                         for (;ifa != NULL;
  134                                             ifa = ifa->ifa_list.tqe_next)
  135                                                 ifnum++;
  136 
  137 
  138                         DPRINTF(("SIOCGIFNUM %d\n", ifnum));
  139                         return copyout(&ifnum, data, sizeof(ifnum));
  140                 }
  141 
  142         case SVR4_32_SIOCGIFFLAGS:
  143                 {
  144                         struct ifreq br;
  145                         struct svr4_32_ifreq sr;
  146 
  147                         if ((error = copyin(data, &sr, sizeof(sr))) != 0)
  148                                 return error;
  149 
  150                         (void) strncpy(br.ifr_name, sr.svr4_ifr_name,
  151                             sizeof(br.ifr_name));
  152 
  153                         if ((error = (*ctl)(fp, SIOCGIFFLAGS, &br, p)) != 0) {
  154                                 DPRINTF(("SIOCGIFFLAGS %s: error %d\n",
  155                                          sr.svr4_ifr_name, error));
  156                                 return error;
  157                         }
  158 
  159                         sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
  160                         DPRINTF(("SIOCGIFFLAGS %s = %x\n",
  161                                 sr.svr4_ifr_name, sr.svr4_ifr_flags));
  162                         return copyout(&sr, data, sizeof(sr));
  163                 }
  164 
  165         case SVR4_32_SIOCGIFCONF:
  166                 {
  167                         struct svr4_32_ifconf sc;
  168                         struct ifconf ifc;
  169 
  170                         if ((error = copyin(data, &sc, sizeof(sc))) != 0)
  171                                 return error;
  172 
  173                         DPRINTF(("ifreq %ld svr4_32_ifreq %ld ifc_len %d\n",
  174                                 (unsigned long)sizeof(struct ifreq),
  175                                 (unsigned long)sizeof(struct svr4_32_ifreq),
  176                                 sc.svr4_32_ifc_len));
  177 
  178                         ifc.ifc_len = sc.svr4_32_ifc_len;
  179                         ifc.ifc_buf = (void *)(uintptr_t)sc.ifc_ifcu.ifcu_buf;
  180 
  181                         if ((error = (*ctl)(fp, OSIOCGIFCONF, &ifc, p)) != 0)
  182                                 return error;
  183 
  184                         DPRINTF(("SIOCGIFCONF\n"));
  185                         return 0;
  186                 }
  187 
  188 
  189         default:
  190                 DPRINTF(("Unknown svr4_32 sockio %lx\n", cmd));
  191                 return 0;       /* ENOSYS really */
  192         }
  193 }

Cache object: 0f705292ad6e1332d754d1b6baaca069


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.