The thread/proc pointer argument in the VFS subsystem originally existed
[dragonfly.git] / sys / emulation / svr4 / svr4_sockio.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1995 Christos Zoulas
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
16 *
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.
27 *
28 * $FreeBSD: src/sys/svr4/svr4_sockio.c,v 1.7 1999/12/08 12:00:48 newton Exp $
87de5057 29 * $DragonFly: src/sys/emulation/svr4/Attic/svr4_sockio.c,v 1.9 2006/05/06 02:43:12 dillon Exp $
984263bc
MD
30 */
31
32#include <sys/param.h>
33#include <sys/proc.h>
34#include <sys/systm.h>
35#include <sys/file.h>
36#include <sys/filedesc.h>
37#include <sys/sockio.h>
38#include <sys/socket.h>
39#include <net/if.h>
dadab5e9 40#include <sys/file2.h>
984263bc 41
9eee10d0
DRJ
42#include <emulation/43bsd/43bsd_socket.h>
43
1f2de5d4
MD
44#include "svr4.h"
45#include "svr4_util.h"
46#include "svr4_ioctl.h"
47#include "svr4_sockio.h"
984263bc 48
04078f12 49static int bsd_to_svr4_flags (int);
984263bc
MD
50
51#define bsd_to_svr4_flag(a) \
52 if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
53
54static int
2da2a8af 55bsd_to_svr4_flags(int bf)
984263bc
MD
56{
57 int sf = 0;
58 bsd_to_svr4_flag(FF_UP);
59 bsd_to_svr4_flag(FF_BROADCAST);
60 bsd_to_svr4_flag(FF_DEBUG);
61 bsd_to_svr4_flag(FF_LOOPBACK);
62 bsd_to_svr4_flag(FF_POINTOPOINT);
63#if defined(IFF_NOTRAILERS)
64 bsd_to_svr4_flag(FF_NOTRAILERS);
65#endif
66 bsd_to_svr4_flag(FF_RUNNING);
67 bsd_to_svr4_flag(FF_NOARP);
68 bsd_to_svr4_flag(FF_PROMISC);
69 bsd_to_svr4_flag(FF_ALLMULTI);
70 bsd_to_svr4_flag(FF_MULTICAST);
71 return sf;
72}
73
74int
2da2a8af
SW
75svr4_sock_ioctl(struct file *fp, struct thread *td, register_t *retval,
76 int fd, u_long cmd, caddr_t data)
984263bc 77{
87de5057 78 struct ucred *cred = curproc->p_ucred;
984263bc
MD
79 int error;
80
81 *retval = 0;
82
83 switch (cmd) {
84 case SVR4_SIOCGIFNUM:
85 {
86 struct ifnet *ifp;
87 struct ifaddr *ifa;
88 int ifnum = 0;
89
90 /*
91 * This does not return the number of physical
92 * interfaces (if_index), but the number of interfaces
93 * + addresses like ifconf() does, because this number
94 * is used by code that will call SVR4_SIOCGIFCONF to
95 * find the space needed for SVR4_SIOCGIFCONF. So we
96 * count the number of ifreq entries that the next
97 * SVR4_SIOCGIFCONF will return. Maybe a more correct
98 * fix is to make SVR4_SIOCGIFCONF return only one
99 * entry per physical interface?
100 */
101
ecd80f47
JS
102 TAILQ_FOREACH(ifp, &ifnet, if_link) {
103 if (TAILQ_EMPTY(&ifp->if_addrhead))
984263bc 104 ifnum++;
ecd80f47
JS
105 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
106 ifnum++;
107 }
984263bc
MD
108
109 DPRINTF(("SIOCGIFNUM %d\n", ifnum));
110 return copyout(&ifnum, data, sizeof(ifnum));
111 }
112
113 case SVR4_SIOCGIFFLAGS:
114 {
115 struct ifreq br;
116 struct svr4_ifreq sr;
117
118 if ((error = copyin(data, &sr, sizeof(sr))) != 0)
119 return error;
120
121 (void) strncpy(br.ifr_name, sr.svr4_ifr_name,
122 sizeof(br.ifr_name));
123 if ((error = fo_ioctl(fp, SIOCGIFFLAGS,
87de5057 124 (caddr_t) &br, cred)) != 0) {
984263bc
MD
125 DPRINTF(("SIOCGIFFLAGS (%s) %s: error %d\n",
126 br.ifr_name, sr.svr4_ifr_name, error));
127 return error;
128 }
129
130 sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
131 DPRINTF(("SIOCGIFFLAGS %s = %x\n",
132 sr.svr4_ifr_name, sr.svr4_ifr_flags));
133 return copyout(&sr, data, sizeof(sr));
134 }
135
136 case SVR4_SIOCGIFCONF:
137 {
138 struct svr4_ifconf sc;
139
140 if ((error = copyin(data, &sc, sizeof(sc))) != 0)
141 return error;
142
143 DPRINTF(("ifreq %d svr4_ifreq %d ifc_len %d\n",
144 sizeof(struct ifreq), sizeof(struct svr4_ifreq),
145 sc.svr4_ifc_len));
146
147 if ((error = fo_ioctl(fp, OSIOCGIFCONF,
87de5057 148 (caddr_t) &sc, cred)) != 0)
984263bc
MD
149 return error;
150
151 DPRINTF(("SIOCGIFCONF\n"));
152 return 0;
153 }
154
155
156 default:
157 DPRINTF(("Unknown svr4 sockio %lx\n", cmd));
158 return 0; /* ENOSYS really */
159 }
160}