|
|
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 is only permitted until one year after the first shipment ! 11: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and ! 12: * binary forms are permitted provided that: (1) source distributions retain ! 13: * this entire copyright notice and comment, and (2) distributions including ! 14: * binaries display the following acknowledgement: This product includes ! 15: * software developed by the University of California, Berkeley and its ! 16: * contributors'' in the documentation or other materials provided with the ! 17: * distribution and in all advertising materials mentioning features or use ! 18: * of this software. Neither the name of the University nor the names of ! 19: * its contributors may be used to endorse or promote products derived from ! 20: * this software without specific prior written permission. ! 21: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 22: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 23: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 24: * ! 25: * from: Utah $Hdr: hpux_net.c 1.33 89/08/23$ ! 26: * ! 27: * @(#)hpux_net.c 7.3 (Berkeley) 6/28/90 ! 28: */ ! 29: ! 30: /* ! 31: * Network related HP-UX compatibility routines ! 32: */ ! 33: ! 34: #ifdef HPUXCOMPAT ! 35: ! 36: #include "param.h" ! 37: #include "systm.h" ! 38: #include "kernel.h" ! 39: #include "time.h" ! 40: #include "errno.h" ! 41: #include "proc.h" ! 42: #include "file.h" ! 43: #include "mbuf.h" ! 44: #include "socket.h" ! 45: #include "socketvar.h" ! 46: #include "uio.h" ! 47: #include "ktrace.h" ! 48: #include "hpux.h" ! 49: ! 50: #define MINBSDIPCCODE 0x3EE ! 51: #define NUMBSDIPC 32 ! 52: ! 53: /* ! 54: * HPUX netioctl() to BSD syscall map. ! 55: * Indexed by callno - MINBSDIPCCODE ! 56: */ ! 57: extern int socket(), listen(), bind(), accept(), connect(), orecv(); ! 58: extern int osend(), shutdown(), getsockname(), sendto(); ! 59: extern int recvfrom(), getpeername(); ! 60: int hpuxgetsockopt(), hpuxsetsockopt(); ! 61: struct file *getsock(); ! 62: ! 63: struct hpuxtobsdipc { ! 64: int (*rout)(); ! 65: int nargs; ! 66: } hpuxtobsdipc[NUMBSDIPC] = { ! 67: socket, 3, /* 3ee */ listen, 2, /* 3ef */ ! 68: bind, 3, /* 3f0 */ accept, 3, /* 3f1 */ ! 69: connect, 3, /* 3f2 */ orecv, 4, /* 3f3 */ ! 70: osend, 4, /* 3f4 */ shutdown, 2, /* 3f5 */ ! 71: getsockname, 3, /* 3f6 */ hpuxsetsockopt, 5, /* 3f7 */ ! 72: sendto, 6, /* 3f8 */ recvfrom, 6, /* 3f9 */ ! 73: getpeername, 3, /* 3fa */ NULL, 0, /* 3fb */ ! 74: NULL, 0, /* 3fc */ NULL, 0, /* 3fd */ ! 75: NULL, 0, /* 3fe */ NULL, 0, /* 3ff */ ! 76: NULL, 0, /* 400 */ NULL, 0, /* 401 */ ! 77: NULL, 0, /* 402 */ NULL, 0, /* 403 */ ! 78: NULL, 0, /* 404 */ NULL, 0, /* 405 */ ! 79: NULL, 0, /* 406 */ NULL, 0, /* 407 */ ! 80: NULL, 0, /* 408 */ NULL, 0, /* 409 */ ! 81: NULL, 0, /* 40a */ hpuxgetsockopt, 5, /* 40b */ ! 82: NULL, 0, /* 40c */ NULL, 0, /* 40d */ ! 83: }; ! 84: ! 85: /* ! 86: * Single system call entry to BSD style IPC. ! 87: * Gleened from disassembled libbsdipc.a syscall entries. ! 88: */ ! 89: hpuxnetioctl(p, uap, retval) ! 90: struct proc *p; ! 91: struct args { ! 92: int call; ! 93: int *args; ! 94: } *uap; ! 95: int *retval; ! 96: { ! 97: int *args, i; ! 98: register int code; ! 99: int error; ! 100: ! 101: args = uap->args; ! 102: code = uap->call - MINBSDIPCCODE; ! 103: if (code < 0 || code >= NUMBSDIPC || hpuxtobsdipc[code].rout == NULL) ! 104: return (EINVAL); ! 105: if ((i = hpuxtobsdipc[code].nargs * sizeof (int)) && ! 106: (error = copyin((caddr_t)args, (caddr_t)uap, (u_int)i))) { ! 107: #ifdef KTRACE ! 108: if (KTRPOINT(p, KTR_SYSCALL)) ! 109: ktrsyscall(p->p_tracep, code + MINBSDIPCCODE, ! 110: hpuxtobsdipc[code].nargs); ! 111: #endif ! 112: return (error); ! 113: } ! 114: #ifdef KTRACE ! 115: if (KTRPOINT(p, KTR_SYSCALL)) ! 116: ktrsyscall(p->p_tracep, code + MINBSDIPCCODE, ! 117: hpuxtobsdipc[code].nargs); ! 118: #endif ! 119: return ((*hpuxtobsdipc[code].rout)(p, uap, retval)); ! 120: } ! 121: ! 122: hpuxsetsockopt(p, uap, retval) ! 123: struct proc *p; ! 124: struct args { ! 125: int s; ! 126: int level; ! 127: int name; ! 128: caddr_t val; ! 129: int valsize; ! 130: } *uap; ! 131: int *retval; ! 132: { ! 133: struct file *fp; ! 134: struct mbuf *m = NULL; ! 135: int tmp, error; ! 136: ! 137: fp = getsock(uap->s, &error); ! 138: if (fp == 0) ! 139: return (error); ! 140: if (uap->valsize > MLEN) ! 141: return (EINVAL); ! 142: if (uap->val) { ! 143: m = m_get(M_WAIT, MT_SOOPTS); ! 144: if (m == NULL) ! 145: return (ENOBUFS); ! 146: if (error = copyin(uap->val, mtod(m, caddr_t), ! 147: (u_int)uap->valsize)) { ! 148: (void) m_free(m); ! 149: return (error); ! 150: } ! 151: if (uap->name == SO_LINGER) { ! 152: tmp = *mtod(m, int *); ! 153: mtod(m, struct linger *)->l_onoff = 1; ! 154: mtod(m, struct linger *)->l_linger = tmp; ! 155: m->m_len = sizeof(struct linger); ! 156: } else ! 157: m->m_len = uap->valsize; ! 158: } else if (uap->name == ~SO_LINGER) { ! 159: m = m_get(M_WAIT, MT_SOOPTS); ! 160: if (m) { ! 161: uap->name = SO_LINGER; ! 162: mtod(m, struct linger *)->l_onoff = 0; ! 163: m->m_len = sizeof(struct linger); ! 164: } ! 165: } ! 166: return (sosetopt((struct socket *)fp->f_data, uap->level, ! 167: uap->name, m)); ! 168: } ! 169: ! 170: hpuxgetsockopt(p, uap, retval) ! 171: struct proc *p; ! 172: struct args { ! 173: int s; ! 174: int level; ! 175: int name; ! 176: caddr_t val; ! 177: int *avalsize; ! 178: } *uap; ! 179: int *retval; ! 180: { ! 181: struct file *fp; ! 182: struct mbuf *m = NULL; ! 183: int valsize, error; ! 184: ! 185: fp = getsock(uap->s, &error); ! 186: if (fp == 0) ! 187: return (error); ! 188: if (uap->val) { ! 189: if (error = copyin((caddr_t)uap->avalsize, (caddr_t)&valsize, ! 190: sizeof (valsize))) ! 191: return (error); ! 192: } else ! 193: valsize = 0; ! 194: if (error = sogetopt((struct socket *)fp->f_data, uap->level, ! 195: uap->name, &m)) ! 196: goto bad; ! 197: if (uap->val && valsize && m != NULL) { ! 198: if (uap->name == SO_LINGER) { ! 199: if (mtod(m, struct linger *)->l_onoff) ! 200: *mtod(m, int *) = mtod(m, struct linger *)->l_linger; ! 201: else ! 202: *mtod(m, int *) = 0; ! 203: m->m_len = sizeof(int); ! 204: } ! 205: if (valsize > m->m_len) ! 206: valsize = m->m_len; ! 207: error = copyout(mtod(m, caddr_t), uap->val, (u_int)valsize); ! 208: if (error == 0) ! 209: error = copyout((caddr_t)&valsize, ! 210: (caddr_t)uap->avalsize, sizeof (valsize)); ! 211: } ! 212: bad: ! 213: if (m != NULL) ! 214: (void) m_free(m); ! 215: return (error); ! 216: } ! 217: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.