2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1995 Christos Zoulas
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/svr4/svr4_sockio.c,v 1.7 1999/12/08 12:00:48 newton Exp $
29 * $DragonFly: src/sys/emulation/svr4/Attic/svr4_sockio.c,v 1.6 2003/09/12 00:43:30 daver Exp $
32 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/filedesc.h>
37 #include <sys/sockio.h>
38 #include <sys/socket.h>
40 #include <sys/file2.h>
42 #include <emulation/43bsd/43bsd_socket.h>
45 #include "svr4_util.h"
46 #include "svr4_ioctl.h"
47 #include "svr4_sockio.h"
49 static int bsd_to_svr4_flags (int);
51 #define bsd_to_svr4_flag(a) \
52 if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
59 bsd_to_svr4_flag(FF_UP);
60 bsd_to_svr4_flag(FF_BROADCAST);
61 bsd_to_svr4_flag(FF_DEBUG);
62 bsd_to_svr4_flag(FF_LOOPBACK);
63 bsd_to_svr4_flag(FF_POINTOPOINT);
64 #if defined(IFF_NOTRAILERS)
65 bsd_to_svr4_flag(FF_NOTRAILERS);
67 bsd_to_svr4_flag(FF_RUNNING);
68 bsd_to_svr4_flag(FF_NOARP);
69 bsd_to_svr4_flag(FF_PROMISC);
70 bsd_to_svr4_flag(FF_ALLMULTI);
71 bsd_to_svr4_flag(FF_MULTICAST);
76 svr4_sock_ioctl(fp, td, retval, fd, cmd, data)
96 * This does not return the number of physical
97 * interfaces (if_index), but the number of interfaces
98 * + addresses like ifconf() does, because this number
99 * is used by code that will call SVR4_SIOCGIFCONF to
100 * find the space needed for SVR4_SIOCGIFCONF. So we
101 * count the number of ifreq entries that the next
102 * SVR4_SIOCGIFCONF will return. Maybe a more correct
103 * fix is to make SVR4_SIOCGIFCONF return only one
104 * entry per physical interface?
107 for (ifp = ifnet.tqh_first;
108 ifp != 0; ifp = ifp->if_link.tqe_next)
109 if ((ifa = ifp->if_addrhead.tqh_first) == NULL)
113 ifa = ifa->ifa_link.tqe_next)
117 DPRINTF(("SIOCGIFNUM %d\n", ifnum));
118 return copyout(&ifnum, data, sizeof(ifnum));
121 case SVR4_SIOCGIFFLAGS:
124 struct svr4_ifreq sr;
126 if ((error = copyin(data, &sr, sizeof(sr))) != 0)
129 (void) strncpy(br.ifr_name, sr.svr4_ifr_name,
130 sizeof(br.ifr_name));
131 if ((error = fo_ioctl(fp, SIOCGIFFLAGS,
132 (caddr_t) &br, td)) != 0) {
133 DPRINTF(("SIOCGIFFLAGS (%s) %s: error %d\n",
134 br.ifr_name, sr.svr4_ifr_name, error));
138 sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
139 DPRINTF(("SIOCGIFFLAGS %s = %x\n",
140 sr.svr4_ifr_name, sr.svr4_ifr_flags));
141 return copyout(&sr, data, sizeof(sr));
144 case SVR4_SIOCGIFCONF:
146 struct svr4_ifconf sc;
148 if ((error = copyin(data, &sc, sizeof(sc))) != 0)
151 DPRINTF(("ifreq %d svr4_ifreq %d ifc_len %d\n",
152 sizeof(struct ifreq), sizeof(struct svr4_ifreq),
155 if ((error = fo_ioctl(fp, OSIOCGIFCONF,
156 (caddr_t) &sc, td)) != 0)
159 DPRINTF(("SIOCGIFCONF\n"));
165 DPRINTF(("Unknown svr4 sockio %lx\n", cmd));
166 return 0; /* ENOSYS really */