Annotation of Net2/arch/hp300/hpux/hpux_net.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1988 University of Utah.
                      3:  * Copyright (c) 1990 The Regents of the University of California.
                      4:  * All rights reserved.
                      5:  *
                      6:  * This code is derived from software contributed to Berkeley by
                      7:  * the Systems Programming Group of the University of Utah Computer
                      8:  * Science Department.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *     This product includes software developed by the University of
                     21:  *     California, Berkeley and its contributors.
                     22:  * 4. Neither the name of the University nor the names of its contributors
                     23:  *    may be used to endorse or promote products derived from this software
                     24:  *    without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36:  * SUCH DAMAGE.
                     37:  *
                     38:  * from: Utah $Hdr: hpux_net.c 1.33 89/08/23$
                     39:  *
                     40:  *     @(#)hpux_net.c  7.7 (Berkeley) 2/13/91
                     41:  */
                     42: 
                     43: /*
                     44:  * Network related HP-UX compatibility routines
                     45:  */
                     46: 
                     47: #ifdef HPUXCOMPAT
                     48: 
                     49: #include "sys/param.h"
                     50: #include "sys/systm.h"
                     51: #include "sys/kernel.h"
                     52: #include "sys/time.h"
                     53: #include "sys/errno.h"
                     54: #include "sys/proc.h"
                     55: #include "sys/file.h"
                     56: #include "sys/mbuf.h"
                     57: #include "sys/socket.h"
                     58: #include "sys/socketvar.h"
                     59: #include "sys/uio.h"
                     60: #include "sys/ktrace.h"
                     61: #include "hpux.h"
                     62: 
                     63: #define MINBSDIPCCODE  0x3EE
                     64: #define NUMBSDIPC      32
                     65: 
                     66: /*
                     67:  * HPUX netioctl() to BSD syscall map.
                     68:  * Indexed by callno - MINBSDIPCCODE
                     69:  */
                     70: extern int socket(), listen(), bind(), oaccept(), connect(), orecv();
                     71: extern int osend(), shutdown(), ogetsockname(), sendto();
                     72: extern int orecvfrom(), ogetpeername();
                     73: int hpuxgetsockopt(), hpuxsetsockopt();
                     74: 
                     75: struct hpuxtobsdipc {
                     76:        int (*rout)();
                     77:        int nargs;
                     78: } hpuxtobsdipc[NUMBSDIPC] = {
                     79:        socket,         3, /* 3ee */    listen,         2, /* 3ef */
                     80:        bind,           3, /* 3f0 */    oaccept,        3, /* 3f1 */
                     81:        connect,        3, /* 3f2 */    orecv,          4, /* 3f3 */
                     82:        osend,          4, /* 3f4 */    shutdown,       2, /* 3f5 */
                     83:        ogetsockname,   3, /* 3f6 */    hpuxsetsockopt, 5, /* 3f7 */
                     84:        sendto,         6, /* 3f8 */    orecvfrom,      6, /* 3f9 */
                     85:        ogetpeername,   3, /* 3fa */    NULL,           0, /* 3fb */
                     86:        NULL,           0, /* 3fc */    NULL,           0, /* 3fd */
                     87:        NULL,           0, /* 3fe */    NULL,           0, /* 3ff */
                     88:        NULL,           0, /* 400 */    NULL,           0, /* 401 */
                     89:        NULL,           0, /* 402 */    NULL,           0, /* 403 */
                     90:        NULL,           0, /* 404 */    NULL,           0, /* 405 */
                     91:        NULL,           0, /* 406 */    NULL,           0, /* 407 */
                     92:        NULL,           0, /* 408 */    NULL,           0, /* 409 */
                     93:        NULL,           0, /* 40a */    hpuxgetsockopt, 5, /* 40b */
                     94:        NULL,           0, /* 40c */    NULL,           0, /* 40d */
                     95: };
                     96: 
                     97: /*
                     98:  * Single system call entry to BSD style IPC.
                     99:  * Gleened from disassembled libbsdipc.a syscall entries.
                    100:  */
                    101: hpuxnetioctl(p, uap, retval)
                    102:        struct proc *p;
                    103:        struct args {
                    104:                int     call;
                    105:                int     *args;
                    106:        } *uap;
                    107:        int *retval;
                    108: {
                    109:        int *args, i;
                    110:        register int code;
                    111:        int error;
                    112: 
                    113:        args = uap->args;
                    114:        code = uap->call - MINBSDIPCCODE;
                    115:        if (code < 0 || code >= NUMBSDIPC || hpuxtobsdipc[code].rout == NULL)
                    116:                return (EINVAL);
                    117:        if ((i = hpuxtobsdipc[code].nargs * sizeof (int)) &&
                    118:            (error = copyin((caddr_t)args, (caddr_t)uap, (u_int)i))) {
                    119: #ifdef KTRACE
                    120:                 if (KTRPOINT(p, KTR_SYSCALL))
                    121:                         ktrsyscall(p->p_tracep, code + MINBSDIPCCODE,
                    122:                                   hpuxtobsdipc[code].nargs);
                    123: #endif
                    124:                return (error);
                    125:        }
                    126: #ifdef KTRACE
                    127:         if (KTRPOINT(p, KTR_SYSCALL))
                    128:                 ktrsyscall(p->p_tracep, code + MINBSDIPCCODE,
                    129:                           hpuxtobsdipc[code].nargs);
                    130: #endif
                    131:        return ((*hpuxtobsdipc[code].rout)(p, uap, retval));
                    132: }
                    133: 
                    134: hpuxsetsockopt(p, uap, retval)
                    135:        struct proc *p;
                    136:        struct args {
                    137:                int     s;
                    138:                int     level;
                    139:                int     name;
                    140:                caddr_t val;
                    141:                int     valsize;
                    142:        } *uap;
                    143:        int *retval;
                    144: {
                    145:        struct file *fp;
                    146:        struct mbuf *m = NULL;
                    147:        int tmp, error;
                    148: 
                    149:        if (error = getsock(p->p_fd, uap->s, &fp))
                    150:                return (error);
                    151:        if (uap->valsize > MLEN)
                    152:                return (EINVAL);
                    153:        if (uap->val) {
                    154:                m = m_get(M_WAIT, MT_SOOPTS);
                    155:                if (m == NULL)
                    156:                        return (ENOBUFS);
                    157:                if (error = copyin(uap->val, mtod(m, caddr_t),
                    158:                    (u_int)uap->valsize)) {
                    159:                        (void) m_free(m);
                    160:                        return (error);
                    161:                }
                    162:                if (uap->name == SO_LINGER) {
                    163:                        tmp = *mtod(m, int *);
                    164:                        mtod(m, struct linger *)->l_onoff = 1;
                    165:                        mtod(m, struct linger *)->l_linger = tmp;
                    166:                        m->m_len = sizeof(struct linger);
                    167:                } else
                    168:                        m->m_len = uap->valsize;
                    169:        } else if (uap->name == ~SO_LINGER) {
                    170:                m = m_get(M_WAIT, MT_SOOPTS);
                    171:                if (m) {
                    172:                        uap->name = SO_LINGER;
                    173:                        mtod(m, struct linger *)->l_onoff = 0;
                    174:                        m->m_len = sizeof(struct linger);
                    175:                }
                    176:        }
                    177:        return (sosetopt((struct socket *)fp->f_data, uap->level,
                    178:            uap->name, m));
                    179: }
                    180: 
                    181: hpuxgetsockopt(p, uap, retval)
                    182:        struct proc *p;
                    183:        struct args {
                    184:                int     s;
                    185:                int     level;
                    186:                int     name;
                    187:                caddr_t val;
                    188:                int     *avalsize;
                    189:        } *uap;
                    190:        int *retval;
                    191: {
                    192:        struct file *fp;
                    193:        struct mbuf *m = NULL;
                    194:        int valsize, error;
                    195: 
                    196:        if (error = getsock(p->p_fd, uap->s, &fp))
                    197:                return (error);
                    198:        if (uap->val) {
                    199:                if (error = copyin((caddr_t)uap->avalsize, (caddr_t)&valsize,
                    200:                    sizeof (valsize)))
                    201:                        return (error);
                    202:        } else
                    203:                valsize = 0;
                    204:        if (error = sogetopt((struct socket *)fp->f_data, uap->level,
                    205:            uap->name, &m))
                    206:                goto bad;
                    207:        if (uap->val && valsize && m != NULL) {
                    208:                if (uap->name == SO_LINGER) {
                    209:                        if (mtod(m, struct linger *)->l_onoff)
                    210:                                *mtod(m, int *) = mtod(m, struct linger *)->l_linger;
                    211:                        else
                    212:                                *mtod(m, int *) = 0;
                    213:                        m->m_len = sizeof(int);
                    214:                }
                    215:                if (valsize > m->m_len)
                    216:                        valsize = m->m_len;
                    217:                error = copyout(mtod(m, caddr_t), uap->val, (u_int)valsize);
                    218:                if (error == 0)
                    219:                        error = copyout((caddr_t)&valsize,
                    220:                            (caddr_t)uap->avalsize, sizeof (valsize));
                    221:        }
                    222: bad:
                    223:        if (m != NULL)
                    224:                (void) m_free(m);
                    225:        return (error);
                    226: }
                    227: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.