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/svr4_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_sockio.c,v 1.35 2008/04/28 20:23:45 martin Exp $   */
    2 
    3 /*-
    4  * Copyright (c) 1995, 2008 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  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: svr4_sockio.c,v 1.35 2008/04/28 20:23:45 martin Exp $");
   34 
   35 #include <sys/param.h>
   36 #include <sys/proc.h>
   37 #include <sys/systm.h>
   38 #include <sys/file.h>
   39 #include <sys/filedesc.h>
   40 #include <sys/ioctl.h>
   41 #include <sys/termios.h>
   42 #include <sys/tty.h>
   43 #include <sys/socket.h>
   44 #include <sys/mount.h>
   45 #include <net/if.h>
   46 #include <sys/malloc.h>
   47 
   48 #include <sys/syscallargs.h>
   49 
   50 #include <compat/sys/socket.h>
   51 #include <compat/sys/sockio.h>
   52 
   53 #include <compat/svr4/svr4_types.h>
   54 #include <compat/svr4/svr4_util.h>
   55 #include <compat/svr4/svr4_signal.h>
   56 #include <compat/svr4/svr4_lwp.h>
   57 #include <compat/svr4/svr4_ucontext.h>
   58 #include <compat/svr4/svr4_syscallargs.h>
   59 #include <compat/svr4/svr4_stropts.h>
   60 #include <compat/svr4/svr4_ioctl.h>
   61 #include <compat/svr4/svr4_sockio.h>
   62 
   63 static int bsd_to_svr4_flags(int);
   64 
   65 #define bsd_to_svr4_flag(a) \
   66         if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
   67 
   68 static int
   69 bsd_to_svr4_flags(int bf)
   70 {
   71         int sf = 0;
   72         bsd_to_svr4_flag(FF_UP);
   73         bsd_to_svr4_flag(FF_BROADCAST);
   74         bsd_to_svr4_flag(FF_DEBUG);
   75         bsd_to_svr4_flag(FF_LOOPBACK);
   76         bsd_to_svr4_flag(FF_POINTOPOINT);
   77         bsd_to_svr4_flag(FF_NOTRAILERS);
   78         bsd_to_svr4_flag(FF_RUNNING);
   79         bsd_to_svr4_flag(FF_NOARP);
   80         bsd_to_svr4_flag(FF_PROMISC);
   81         bsd_to_svr4_flag(FF_ALLMULTI);
   82         bsd_to_svr4_flag(FF_MULTICAST);
   83         return sf;
   84 }
   85 
   86 int
   87 svr4_count_ifnum(struct ifnet *ifp)
   88 {
   89         struct ifaddr *ifa;
   90         int ifnum = 0;
   91 
   92         IFADDR_FOREACH(ifa, ifp)
   93                 ifnum++;
   94 
   95         return MAX(1, ifnum);
   96 }
   97 
   98 int
   99 svr4_sock_ioctl(file_t *fp, struct lwp *l, register_t *retval,
  100     int fd, u_long cmd, void *data)
  101 {
  102         int error;
  103         int (*ctl)(file_t *, u_long,  void *) = fp->f_ops->fo_ioctl;
  104 
  105         *retval = 0;
  106 
  107         switch (cmd) {
  108         case SVR4_SIOCGLIFNUM:
  109                 {
  110                         struct ifnet *ifp;
  111                         struct svr4_lifnum lifnum;
  112 
  113                         error = copyin(data, &lifnum, sizeof(lifnum));
  114                         if (error)
  115                                 return error;
  116 
  117                         lifnum.lifn_count = 0;
  118                         /* XXX: We don't pay attention to family or flags */
  119                         IFNET_FOREACH(ifp)
  120                                 lifnum.lifn_count += svr4_count_ifnum(ifp);
  121 
  122                         DPRINTF(("SIOCGLIFNUM [family=%d,flags=%d,count=%d]\n",
  123                             lifnum.lifn_family, lifnum.lifn_flags,
  124                             lifnum.lifn_count));
  125                         return copyout(&lifnum, data, sizeof(lifnum));
  126                 }
  127 
  128         case SVR4_SIOCGIFNUM:
  129                 {
  130                         struct ifnet *ifp;
  131                         int ifnum = 0;
  132 
  133                         /*
  134                          * This does not return the number of physical
  135                          * interfaces (if_index), but the number of interfaces
  136                          * + addresses like ifconf() does, because this number
  137                          * is used by code that will call SVR4_SIOCGIFCONF to
  138                          * find the space needed for SVR4_SIOCGIFCONF. So we
  139                          * count the number of ifreq entries that the next
  140                          * SVR4_SIOCGIFCONF will return. Maybe a more correct
  141                          * fix is to make SVR4_SIOCGIFCONF return only one
  142                          * entry per physical interface?
  143                          */
  144 
  145                         IFNET_FOREACH(ifp)
  146                                 ifnum += svr4_count_ifnum(ifp);
  147 
  148                         DPRINTF(("SIOCGIFNUM %d\n", ifnum));
  149                         return copyout(&ifnum, data, sizeof(ifnum));
  150                 }
  151 
  152         case SVR4_SIOCGIFFLAGS:
  153                 {
  154                         struct oifreq br;
  155                         struct svr4_ifreq sr;
  156 
  157                         if ((error = copyin(data, &sr, sizeof(sr))) != 0)
  158                                 return error;
  159 
  160                         (void) strncpy(br.ifr_name, sr.svr4_ifr_name,
  161                             sizeof(br.ifr_name));
  162 
  163                         if ((error = (*ctl)(fp, SIOCGIFFLAGS, &br)) != 0) {
  164                                 DPRINTF(("SIOCGIFFLAGS %s: error %d\n",
  165                                          sr.svr4_ifr_name, error));
  166                                 return error;
  167                         }
  168 
  169                         sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
  170                         DPRINTF(("SIOCGIFFLAGS %s = %x\n",
  171                                 sr.svr4_ifr_name, sr.svr4_ifr_flags));
  172                         return copyout(&sr, data, sizeof(sr));
  173                 }
  174 
  175         case SVR4_SIOCGIFCONF:
  176                 {
  177                         struct svr4_ifconf sc;
  178 
  179                         if ((error = copyin(data, &sc, sizeof(sc))) != 0)
  180                                 return error;
  181 
  182                         DPRINTF(("ifreq %ld svr4_ifreq %ld ifc_len %d\n",
  183                                 (unsigned long)sizeof(struct oifreq),
  184                                 (unsigned long)sizeof(struct svr4_ifreq),
  185                                 sc.svr4_ifc_len));
  186 
  187                         if ((error = (*ctl)(fp, OOSIOCGIFCONF, &sc)) != 0)
  188                                 return error;
  189 
  190                         DPRINTF(("SIOCGIFCONF\n"));
  191                         return 0;
  192                 }
  193 
  194 
  195         default:
  196                 DPRINTF(("Unknown svr4 sockio %lx\n", cmd));
  197                 return 0;       /* ENOSYS really */
  198         }
  199 }

Cache object: 4c2bf2931a3ebb7b87a86aa9408945bb


[ 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.