2 * Copyright (c) 1994, 1995 Scott Bartram
3 * Copyright (c) 1994 Arne H Juul
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. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_socksys.c,v 1.4 2003/08/07 21:17:17 dillon Exp $
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/sysproto.h>
31 #include <sys/kernel.h>
32 #include <sys/sysctl.h>
34 #include "ibcs2_socksys.h"
35 #include "ibcs2_util.h"
37 /* Local structures */
38 struct getipdomainname_args {
43 struct setipdomainname_args {
48 /* Local prototypes */
49 static int ibcs2_getipdomainname __P((struct getipdomainname_args *));
50 static int ibcs2_setipdomainname __P((struct setipdomainname_args *));
53 * iBCS2 socksys calls.
57 ibcs2_socksys(struct ibcs2_socksys_args *uap)
60 int realargs[7]; /* 1 for command, 6 for recvfrom */
64 * SOCKET should only be legal on /dev/socksys.
65 * GETIPDOMAINNAME should only be legal on /dev/socksys ?
66 * The others are (and should be) only legal on sockets.
69 if ((error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) != 0)
71 DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n",
72 realargs[0], realargs[1], realargs[2], realargs[3],
73 realargs[4], realargs[5], realargs[6]));
75 passargs = (void *)(realargs + 1);
76 switch (realargs[0]) {
78 return accept(passargs);
80 return bind(passargs);
82 return connect(passargs);
83 case SOCKSYS_GETPEERNAME:
84 return getpeername(passargs);
85 case SOCKSYS_GETSOCKNAME:
86 return getsockname(passargs);
87 case SOCKSYS_GETSOCKOPT:
88 return getsockopt(passargs);
90 return listen(passargs);
92 realargs[5] = realargs[6] = 0;
94 case SOCKSYS_RECVFROM:
95 return recvfrom(passargs);
97 realargs[5] = realargs[6] = 0;
100 return sendto(passargs);
101 case SOCKSYS_SETSOCKOPT:
102 return setsockopt(passargs);
103 case SOCKSYS_SHUTDOWN:
104 return shutdown(passargs);
106 return socket(passargs);
108 return select(passargs);
109 case SOCKSYS_GETIPDOMAIN:
110 return ibcs2_getipdomainname(passargs);
111 case SOCKSYS_SETIPDOMAIN:
112 return ibcs2_setipdomainname(passargs);
113 case SOCKSYS_ADJTIME:
114 return adjtime(passargs);
115 case SOCKSYS_SETREUID:
116 return setreuid(passargs);
117 case SOCKSYS_SETREGID:
118 return setregid(passargs);
119 case SOCKSYS_GETTIME:
120 return gettimeofday(passargs);
121 case SOCKSYS_SETTIME:
122 return settimeofday(passargs);
123 case SOCKSYS_GETITIMER:
124 return getitimer(passargs);
125 case SOCKSYS_SETITIMER:
126 return setitimer(passargs);
129 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n",
130 realargs[0], realargs[1], realargs[2], realargs[3],
131 realargs[4], realargs[5], realargs[6]);
139 ibcs2_getipdomainname(struct getipdomainname_args *uap)
141 char hname[MAXHOSTNAMELEN], *dptr;
144 /* Get the domain name */
145 snprintf(hname, sizeof(hname), "%s", hostname);
146 dptr = index(hname, '.');
150 /* Make it effectively an empty string */
151 dptr = hname + strlen(hname);
153 len = strlen(dptr) + 1;
154 if ((u_int)uap->len > len + 1)
156 return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
161 ibcs2_setipdomainname(struct setipdomainname_args *uap)
163 char hname[MAXHOSTNAMELEN], *ptr;
164 int error, sctl[2], hlen;
166 if ((error = suser(curthread)))
169 /* W/out a hostname a domain-name is nonsense */
170 if ( strlen(hostname) == 0 )
173 /* Get the host's unqualified name (strip off the domain) */
174 snprintf(hname, sizeof(hname), "%s", hostname);
175 ptr = index(hname, '.');
182 /* Set ptr to the end of the string so we can append to it */
183 hlen = strlen(hname);
185 if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
188 /* Append the ipdomain to the end */
189 error = copyin((caddr_t)uap->ipdomainname, ptr, uap->len);
193 /* 'sethostname' with the new information */
195 sctl[1] = KERN_HOSTNAME;
196 hlen = strlen(hname) + 1;
197 return (kernel_sysctl(sctl, 2, 0, 0, hname, hlen, 0));