root/compat/hpux/m68k/hpux_net.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. hpux_sys_netioctl
  2. socksetsize
  3. hpux_sys_setsockopt2
  4. hpux_sys_setsockopt
  5. hpux_sys_getsockopt

    1 /*      $OpenBSD: hpux_net.c,v 1.1 2004/07/09 21:33:45 mickey Exp $     */
    2 /*      $NetBSD: hpux_net.c,v 1.14 1997/04/01 19:59:02 scottr Exp $     */
    3 
    4 /*
    5  * Copyright (c) 1988 University of Utah.
    6  * Copyright (c) 1990, 1993
    7  *      The Regents of the University of California.  All rights reserved.
    8  *
    9  * This code is derived from software contributed to Berkeley by
   10  * the Systems Programming Group of the University of Utah Computer
   11  * Science Department.
   12  *
   13  * Redistribution and use in source and binary forms, with or without
   14  * modification, are permitted provided that the following conditions
   15  * are met:
   16  * 1. Redistributions of source code must retain the above copyright
   17  *    notice, this list of conditions and the following disclaimer.
   18  * 2. Redistributions in binary form must reproduce the above copyright
   19  *    notice, this list of conditions and the following disclaimer in the
   20  *    documentation and/or other materials provided with the distribution.
   21  * 3. Neither the name of the University nor the names of its contributors
   22  *    may be used to endorse or promote products derived from this software
   23  *    without specific prior written permission.
   24  *
   25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   35  * SUCH DAMAGE.
   36  *
   37  * from: Utah $Hdr: hpux_net.c 1.8 93/08/02$
   38  *
   39  *      @(#)hpux_net.c  8.2 (Berkeley) 9/9/93
   40  */
   41 
   42 /*
   43  * Network related HP-UX compatibility routines
   44  */
   45 
   46 #include <sys/param.h>
   47 #include <sys/systm.h>
   48 #include <sys/kernel.h>
   49 #include <sys/time.h>
   50 #include <sys/errno.h>
   51 #include <sys/proc.h>
   52 #include <sys/file.h>
   53 #include <sys/filedesc.h>
   54 #include <sys/mbuf.h>
   55 #include <sys/mount.h>
   56 #include <sys/socket.h>
   57 #include <sys/socketvar.h>
   58 #include <sys/uio.h>
   59 #include <sys/ktrace.h>
   60 #include <sys/syscallargs.h>
   61 
   62 #include <compat/hpux/hpux.h>
   63 #include <compat/hpux/hpux_util.h>
   64 #include <compat/hpux/m68k/hpux_syscallargs.h>
   65 
   66 struct hpux_sys_getsockopt_args {
   67         syscallarg(int) s;
   68         syscallarg(int) level;
   69         syscallarg(int) name;
   70         syscallarg(caddr_t) val;
   71         syscallarg(int *) avalsize;
   72 };
   73 
   74 int     hpux_sys_setsockopt2(struct proc *, void *, register_t *);
   75 int     hpux_sys_getsockopt(struct proc *, void *, register_t *);
   76 
   77 void    socksetsize(int, struct mbuf *);
   78 
   79 
   80 #define MINBSDIPCCODE   0x3EE
   81 #define NUMBSDIPC       32
   82 
   83 /*
   84  * HPUX netioctl() to BSD syscall map.
   85  * Indexed by callno - MINBSDIPCCODE
   86  */
   87 
   88 struct hpuxtobsdipc {
   89         int (*rout)(struct proc *, void *, register_t *);
   90         int nargs;
   91 } hpuxtobsdipc[NUMBSDIPC] = {
   92         { sys_socket,                   3 }, /* 3ee */
   93         { sys_listen,                   2 }, /* 3ef */
   94         { sys_bind,                     3 }, /* 3f0 */
   95         { compat_43_sys_accept,         3 }, /* 3f1 */
   96         { sys_connect,                  3 }, /* 3f2 */
   97         { compat_43_sys_recv,           4 }, /* 3f3 */
   98         { compat_43_sys_send,           4 }, /* 3f4 */
   99         { sys_shutdown,                 2 }, /* 3f5 */
  100         { compat_43_sys_getsockname,    3 }, /* 3f6 */
  101         { hpux_sys_setsockopt2,         5 }, /* 3f7 */
  102         { sys_sendto,                   6 }, /* 3f8 */
  103         { compat_43_sys_recvfrom,       6 }, /* 3f9 */
  104         { compat_43_sys_getpeername,    3 }, /* 3fa */
  105         { NULL,                         0 }, /* 3fb */
  106         { NULL,                         0 }, /* 3fc */
  107         { NULL,                         0 }, /* 3fd */
  108         { NULL,                         0 }, /* 3fe */
  109         { NULL,                         0 }, /* 3ff */
  110         { NULL,                         0 }, /* 400 */
  111         { NULL,                         0 }, /* 401 */
  112         { NULL,                         0 }, /* 402 */
  113         { NULL,                         0 }, /* 403 */
  114         { NULL,                         0 }, /* 404 */
  115         { NULL,                         0 }, /* 405 */
  116         { NULL,                         0 }, /* 406 */
  117         { NULL,                         0 }, /* 407 */
  118         { NULL,                         0 }, /* 408 */
  119         { NULL,                         0 }, /* 409 */
  120         { NULL,                         0 }, /* 40a */
  121         { hpux_sys_getsockopt,          5 }, /* 40b */
  122         { NULL,                         0 }, /* 40c */
  123         { NULL,                         0 }, /* 40d */
  124 };
  125 
  126 /*
  127  * Single system call entry to BSD style IPC.
  128  * Gleened from disassembled libbsdipc.a syscall entries.
  129  */
  130 int
  131 hpux_sys_netioctl(p, v, retval)
  132         struct proc *p;
  133         void *v;
  134         register_t *retval;
  135 {
  136         struct hpux_sys_netioctl_args *uap = v;
  137         int *args, i;
  138         int code;
  139         int error;
  140 
  141         args = SCARG(uap, args);
  142         code = SCARG(uap, call) - MINBSDIPCCODE;
  143         if (code < 0 || code >= NUMBSDIPC || hpuxtobsdipc[code].rout == NULL)
  144                 return (EINVAL);
  145         if ((i = hpuxtobsdipc[code].nargs * sizeof (int)) &&
  146             (error = copyin((caddr_t)args, (caddr_t)uap, (u_int)i))) {
  147 #ifdef KTRACE
  148                 if (KTRPOINT(p, KTR_SYSCALL))
  149                         ktrsyscall(p, code + MINBSDIPCCODE,
  150                                    hpuxtobsdipc[code].nargs,
  151                                    (register_t *)uap);
  152 #endif
  153                 return (error);
  154         }
  155 #ifdef KTRACE
  156         if (KTRPOINT(p, KTR_SYSCALL))
  157                 ktrsyscall(p, code + MINBSDIPCCODE,
  158                            hpuxtobsdipc[code].nargs,
  159                            (register_t *)uap);
  160 #endif
  161         return ((*hpuxtobsdipc[code].rout)(p, uap, retval));
  162 }
  163 
  164 void
  165 socksetsize(size, m)
  166         int size;
  167         struct mbuf *m;
  168 {
  169         int tmp;
  170 
  171         if (size < sizeof(int)) {
  172                 switch(size) {
  173                 case 1:
  174                         tmp = (int) *mtod(m, char *);
  175                         break;
  176                 case 2:
  177                         tmp = (int) *mtod(m, short *);
  178                         break;
  179                 case 3:
  180                 default:        /* XXX uh, what if sizeof(int) > 4? */
  181                         tmp = (((int) *mtod(m, int *)) >> 8) & 0xffffff;
  182                         break;
  183                 }
  184                 *mtod(m, int *) = tmp;
  185                 m->m_len = sizeof(int);
  186         } else {
  187                 m->m_len = size;
  188         }
  189 }
  190 
  191 /* ARGSUSED */
  192 int
  193 hpux_sys_setsockopt2(p, v, retval)
  194         struct proc *p;
  195         void *v;
  196         register_t *retval;
  197 {
  198         struct hpux_sys_setsockopt_args *uap = v;
  199         struct file *fp;
  200         struct mbuf *m = NULL;
  201         int tmp, error;
  202 
  203         if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
  204                 return (error);
  205         if (SCARG(uap, valsize) > MLEN) {
  206                 error = EINVAL;
  207                 goto bad;
  208         }
  209         if (SCARG(uap, val)) {
  210                 m = m_get(M_WAIT, MT_SOOPTS);
  211                 if ((error = copyin(SCARG(uap, val), mtod(m, caddr_t),
  212                     (u_int)SCARG(uap, valsize)))) {
  213                         (void) m_free(m);
  214                         goto bad;
  215                 }
  216                 if (SCARG(uap, name) == SO_LINGER) {
  217                         tmp = *mtod(m, int *);
  218                         mtod(m, struct linger *)->l_onoff = 1;
  219                         mtod(m, struct linger *)->l_linger = tmp;
  220                         m->m_len = sizeof(struct linger);
  221                 } else
  222                         socksetsize(SCARG(uap, valsize), m);
  223         } else if (SCARG(uap, name) == ~SO_LINGER) {
  224                 m = m_get(M_WAIT, MT_SOOPTS);
  225                 SCARG(uap, name) = SO_LINGER;
  226                 mtod(m, struct linger *)->l_onoff = 0;
  227                 m->m_len = sizeof(struct linger);
  228         }
  229         error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
  230             SCARG(uap, name), m);
  231 bad:
  232         FRELE(fp);
  233         return (error);
  234 }
  235 
  236 /* ARGSUSED */
  237 int
  238 hpux_sys_setsockopt(p, v, retval)
  239         struct proc *p;
  240         void *v;
  241         register_t *retval;
  242 {
  243         struct hpux_sys_setsockopt_args *uap = v;
  244         struct file *fp;
  245         struct mbuf *m = NULL;
  246         int error;
  247 
  248         if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
  249                 return (error);
  250         if (SCARG(uap, valsize) > MLEN) {
  251                 error = EINVAL;
  252                 goto bad;
  253         }
  254         if (SCARG(uap, val)) {
  255                 m = m_get(M_WAIT, MT_SOOPTS);
  256                 if ((error = copyin(SCARG(uap, val), mtod(m, caddr_t),
  257                     (u_int)SCARG(uap, valsize)))) {
  258                         m_free(m);
  259                         goto bad;
  260                 }
  261                 socksetsize(SCARG(uap, valsize), m);
  262         }
  263         error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
  264             SCARG(uap, name), m);
  265 bad:
  266         FRELE(fp);
  267         return (error);
  268 }
  269 
  270 int
  271 hpux_sys_getsockopt(p, v, retval)
  272         struct proc *p;
  273         void *v;
  274         register_t *retval;
  275 {
  276         struct hpux_sys_getsockopt_args *uap = v;
  277         struct file *fp;
  278         struct mbuf *m = NULL;
  279         int valsize, error;
  280 
  281         if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
  282                 return (error);
  283         if (SCARG(uap, val)) {
  284                 if ((error = copyin((caddr_t)SCARG(uap, avalsize),
  285                     (caddr_t)&valsize, sizeof (valsize)))) {
  286                         goto bad;
  287                 }
  288         } else
  289                 valsize = 0;
  290         if ((error = sogetopt((struct socket *)fp->f_data, SCARG(uap, level),
  291             SCARG(uap, name), &m)))
  292                 goto bad;
  293         if (SCARG(uap, val) && valsize && m != NULL) {
  294                 if (SCARG(uap, name) == SO_LINGER) {
  295                         if (mtod(m, struct linger *)->l_onoff)
  296                                 *mtod(m, int *) = mtod(m, struct linger *)->l_linger;
  297                         else
  298                                 *mtod(m, int *) = 0;
  299                         m->m_len = sizeof(int);
  300                 }
  301                 if (valsize > m->m_len)
  302                         valsize = m->m_len;
  303                 error = copyout(mtod(m, caddr_t), SCARG(uap, val),
  304                     (u_int)valsize);
  305                 if (error == 0)
  306                         error = copyout((caddr_t)&valsize,
  307                             (caddr_t)SCARG(uap, avalsize), sizeof (valsize));
  308         }
  309 bad:
  310         FRELE(fp);
  311         if (m != NULL)
  312                 m_free(m);
  313         return (error);
  314 }

/* [<][>][^][v][top][bottom][index][help] */