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 proc *,
48 struct getipdomainname_args *));
49 static int ibcs2_setipdomainname __P((struct proc *,
50 struct setipdomainname_args *));
53 * iBCS2 socksys calls.
58 register struct proc *p;
59 register struct ibcs2_socksys_args *uap;
62 int realargs[7]; /* 1 for command, 6 for recvfrom */
66 * SOCKET should only be legal on /dev/socksys.
67 * GETIPDOMAINNAME should only be legal on /dev/socksys ?
68 * The others are (and should be) only legal on sockets.
71 if ((error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) != 0)
73 DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n",
74 realargs[0], realargs[1], realargs[2], realargs[3],
75 realargs[4], realargs[5], realargs[6]));
77 passargs = (void *)(realargs + 1);
78 switch (realargs[0]) {
80 return accept(p, passargs);
82 return bind(p, passargs);
84 return connect(p, passargs);
85 case SOCKSYS_GETPEERNAME:
86 return getpeername(p, passargs);
87 case SOCKSYS_GETSOCKNAME:
88 return getsockname(p, passargs);
89 case SOCKSYS_GETSOCKOPT:
90 return getsockopt(p, passargs);
92 return listen(p, passargs);
94 realargs[5] = realargs[6] = 0;
96 case SOCKSYS_RECVFROM:
97 return recvfrom(p, passargs);
99 realargs[5] = realargs[6] = 0;
102 return sendto(p, passargs);
103 case SOCKSYS_SETSOCKOPT:
104 return setsockopt(p, passargs);
105 case SOCKSYS_SHUTDOWN:
106 return shutdown(p, passargs);
108 return socket(p, passargs);
110 return select(p, passargs);
111 case SOCKSYS_GETIPDOMAIN:
112 return ibcs2_getipdomainname(p, passargs);
113 case SOCKSYS_SETIPDOMAIN:
114 return ibcs2_setipdomainname(p, passargs);
115 case SOCKSYS_ADJTIME:
116 return adjtime(p, passargs);
117 case SOCKSYS_SETREUID:
118 return setreuid(p, passargs);
119 case SOCKSYS_SETREGID:
120 return setregid(p, passargs);
121 case SOCKSYS_GETTIME:
122 return gettimeofday(p, passargs);
123 case SOCKSYS_SETTIME:
124 return settimeofday(p, passargs);
125 case SOCKSYS_GETITIMER:
126 return getitimer(p, passargs);
127 case SOCKSYS_SETITIMER:
128 return setitimer(p, passargs);
131 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n",
132 realargs[0], realargs[1], realargs[2], realargs[3],
133 realargs[4], realargs[5], realargs[6]);
141 ibcs2_getipdomainname(p, uap)
143 struct getipdomainname_args *uap;
145 char hname[MAXHOSTNAMELEN], *dptr;
148 /* Get the domain name */
149 snprintf(hname, sizeof(hname), "%s", hostname);
150 dptr = index(hname, '.');
154 /* Make it effectively an empty string */
155 dptr = hname + strlen(hname);
157 len = strlen(dptr) + 1;
158 if ((u_int)uap->len > len + 1)
160 return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
165 ibcs2_setipdomainname(p, uap)
167 struct setipdomainname_args *uap;
169 char hname[MAXHOSTNAMELEN], *ptr;
170 int error, sctl[2], hlen;
172 if ((error = suser(p)))
175 /* W/out a hostname a domain-name is nonsense */
176 if ( strlen(hostname) == 0 )
179 /* Get the host's unqualified name (strip off the domain) */
180 snprintf(hname, sizeof(hname), "%s", hostname);
181 ptr = index(hname, '.');
188 /* Set ptr to the end of the string so we can append to it */
189 hlen = strlen(hname);
191 if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
194 /* Append the ipdomain to the end */
195 error = copyin((caddr_t)uap->ipdomainname, ptr, uap->len);
199 /* 'sethostname' with the new information */
201 sctl[1] = KERN_HOSTNAME;
202 hlen = strlen(hname) + 1;
203 return (kernel_sysctl(p, sctl, 2, 0, 0, hname, hlen, 0));