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/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/sysproto.h>
33 #include <sys/kernel.h>
34 #include <sys/sysctl.h>
36 #include <i386/ibcs2/ibcs2_socksys.h>
37 #include <i386/ibcs2/ibcs2_util.h>
39 /* Local structures */
40 struct getipdomainname_args {
45 struct setipdomainname_args {
50 /* Local prototypes */
51 static int ibcs2_getipdomainname(struct thread *,
52 struct getipdomainname_args *);
53 static int ibcs2_setipdomainname(struct thread *,
54 struct setipdomainname_args *);
57 * iBCS2 socksys calls.
61 ibcs2_socksys(td, uap)
62 register struct thread *td;
63 register struct ibcs2_socksys_args *uap;
66 int realargs[7]; /* 1 for command, 6 for recvfrom */
70 * SOCKET should only be legal on /dev/socksys.
71 * GETIPDOMAINNAME should only be legal on /dev/socksys ?
72 * The others are (and should be) only legal on sockets.
75 if ((error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) != 0)
77 DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n",
78 realargs[0], realargs[1], realargs[2], realargs[3],
79 realargs[4], realargs[5], realargs[6]));
81 passargs = (void *)(realargs + 1);
82 switch (realargs[0]) {
84 return sys_accept(td, passargs);
86 return sys_bind(td, passargs);
88 return sys_connect(td, passargs);
89 case SOCKSYS_GETPEERNAME:
90 return sys_getpeername(td, passargs);
91 case SOCKSYS_GETSOCKNAME:
92 return sys_getsockname(td, passargs);
93 case SOCKSYS_GETSOCKOPT:
94 return sys_getsockopt(td, passargs);
96 return sys_listen(td, passargs);
98 realargs[5] = realargs[6] = 0;
100 case SOCKSYS_RECVFROM:
101 return sys_recvfrom(td, passargs);
103 realargs[5] = realargs[6] = 0;
106 return sys_sendto(td, passargs);
107 case SOCKSYS_SETSOCKOPT:
108 return sys_setsockopt(td, passargs);
109 case SOCKSYS_SHUTDOWN:
110 return sys_shutdown(td, passargs);
112 return sys_socket(td, passargs);
114 return sys_select(td, passargs);
115 case SOCKSYS_GETIPDOMAIN:
116 return ibcs2_getipdomainname(td, passargs);
117 case SOCKSYS_SETIPDOMAIN:
118 return ibcs2_setipdomainname(td, passargs);
119 case SOCKSYS_ADJTIME:
120 return sys_adjtime(td, passargs);
121 case SOCKSYS_SETREUID:
122 return sys_setreuid(td, passargs);
123 case SOCKSYS_SETREGID:
124 return sys_setregid(td, passargs);
125 case SOCKSYS_GETTIME:
126 return sys_gettimeofday(td, passargs);
127 case SOCKSYS_SETTIME:
128 return sys_settimeofday(td, passargs);
129 case SOCKSYS_GETITIMER:
130 return sys_getitimer(td, passargs);
131 case SOCKSYS_SETITIMER:
132 return sys_setitimer(td, passargs);
135 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n",
136 realargs[0], realargs[1], realargs[2], realargs[3],
137 realargs[4], realargs[5], realargs[6]);
145 ibcs2_getipdomainname(td, uap)
147 struct getipdomainname_args *uap;
149 char hname[MAXHOSTNAMELEN], *dptr;
152 /* Get the domain name. */
153 getcredhostname(td->td_ucred, hname, sizeof(hname));
155 dptr = strchr(hname, '.');
159 /* Make it effectively an empty string */
160 dptr = hname + strlen(hname);
162 len = strlen(dptr) + 1;
163 if ((u_int)uap->len > len + 1)
165 return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
170 ibcs2_setipdomainname(td, uap)
172 struct setipdomainname_args *uap;
174 char hname[MAXHOSTNAMELEN], *ptr;
175 int error, sctl[2], hlen;
177 /* Get the domain name */
178 getcredhostname(td->td_ucred, hname, sizeof(hname));
180 /* W/out a hostname a domain-name is nonsense */
181 if ( strlen(hname) == 0 )
184 /* Get the host's unqualified name (strip off the domain) */
185 ptr = strchr(hname, '.');
190 if (strlcat(hname, ".", sizeof(hname)) >= sizeof(hname))
194 /* Set ptr to the end of the string so we can append to it */
195 hlen = strlen(hname);
197 if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
200 /* Append the ipdomain to the end */
201 error = copyinstr((caddr_t)uap->ipdomainname, ptr, uap->len, NULL);
205 /* 'sethostname' with the new information */
207 sctl[1] = KERN_HOSTNAME;
208 hlen = strlen(hname) + 1;
209 return (kernel_sysctl(td, sctl, 2, 0, 0, hname, hlen, 0, 0));