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.
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/sysproto.h>
29 #include <sys/kernel.h>
30 #include <sys/sysctl.h>
32 #include <i386/ibcs2/ibcs2_socksys.h>
33 #include <i386/ibcs2/ibcs2_util.h>
35 /* Local structures */
36 struct getipdomainname_args {
41 struct setipdomainname_args {
46 /* Local prototypes */
47 static int ibcs2_getipdomainname __P((struct getipdomainname_args *));
48 static int ibcs2_setipdomainname __P((struct setipdomainname_args *));
51 * iBCS2 socksys calls.
55 ibcs2_socksys(struct ibcs2_socksys_args *uap)
58 int realargs[7]; /* 1 for command, 6 for recvfrom */
62 * SOCKET should only be legal on /dev/socksys.
63 * GETIPDOMAINNAME should only be legal on /dev/socksys ?
64 * The others are (and should be) only legal on sockets.
67 if ((error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) != 0)
69 DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n",
70 realargs[0], realargs[1], realargs[2], realargs[3],
71 realargs[4], realargs[5], realargs[6]));
73 passargs = (void *)(realargs + 1);
74 switch (realargs[0]) {
76 return accept(passargs);
78 return bind(passargs);
80 return connect(passargs);
81 case SOCKSYS_GETPEERNAME:
82 return getpeername(passargs);
83 case SOCKSYS_GETSOCKNAME:
84 return getsockname(passargs);
85 case SOCKSYS_GETSOCKOPT:
86 return getsockopt(passargs);
88 return listen(passargs);
90 realargs[5] = realargs[6] = 0;
92 case SOCKSYS_RECVFROM:
93 return recvfrom(passargs);
95 realargs[5] = realargs[6] = 0;
98 return sendto(passargs);
99 case SOCKSYS_SETSOCKOPT:
100 return setsockopt(passargs);
101 case SOCKSYS_SHUTDOWN:
102 return shutdown(passargs);
104 return socket(passargs);
106 return select(passargs);
107 case SOCKSYS_GETIPDOMAIN:
108 return ibcs2_getipdomainname(passargs);
109 case SOCKSYS_SETIPDOMAIN:
110 return ibcs2_setipdomainname(passargs);
111 case SOCKSYS_ADJTIME:
112 return adjtime(passargs);
113 case SOCKSYS_SETREUID:
114 return setreuid(passargs);
115 case SOCKSYS_SETREGID:
116 return setregid(passargs);
117 case SOCKSYS_GETTIME:
118 return gettimeofday(passargs);
119 case SOCKSYS_SETTIME:
120 return settimeofday(passargs);
121 case SOCKSYS_GETITIMER:
122 return getitimer(passargs);
123 case SOCKSYS_SETITIMER:
124 return setitimer(passargs);
127 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n",
128 realargs[0], realargs[1], realargs[2], realargs[3],
129 realargs[4], realargs[5], realargs[6]);
137 ibcs2_getipdomainname(struct getipdomainname_args *uap)
139 char hname[MAXHOSTNAMELEN], *dptr;
142 /* Get the domain name */
143 snprintf(hname, sizeof(hname), "%s", hostname);
144 dptr = index(hname, '.');
148 /* Make it effectively an empty string */
149 dptr = hname + strlen(hname);
151 len = strlen(dptr) + 1;
152 if ((u_int)uap->len > len + 1)
154 return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
159 ibcs2_setipdomainname(struct setipdomainname_args *uap)
161 char hname[MAXHOSTNAMELEN], *ptr;
162 int error, sctl[2], hlen;
164 if ((error = suser()))
167 /* W/out a hostname a domain-name is nonsense */
168 if ( strlen(hostname) == 0 )
171 /* Get the host's unqualified name (strip off the domain) */
172 snprintf(hname, sizeof(hname), "%s", hostname);
173 ptr = index(hname, '.');
180 /* Set ptr to the end of the string so we can append to it */
181 hlen = strlen(hname);
183 if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
186 /* Append the ipdomain to the end */
187 error = copyin((caddr_t)uap->ipdomainname, ptr, uap->len);
191 /* 'sethostname' with the new information */
193 sctl[1] = KERN_HOSTNAME;
194 hlen = strlen(hname) + 1;
195 return (kernel_sysctl(sctl, 2, 0, 0, hname, hlen, 0));