Annotation of kernel/bsd/kern/sys_socket.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
        !            26: /*
        !            27:  * Copyright (c) 1982, 1986, 1990, 1993
        !            28:  *     The Regents of the University of California.  All rights reserved.
        !            29:  *
        !            30:  * Redistribution and use in source and binary forms, with or without
        !            31:  * modification, are permitted provided that the following conditions
        !            32:  * are met:
        !            33:  * 1. Redistributions of source code must retain the above copyright
        !            34:  *    notice, this list of conditions and the following disclaimer.
        !            35:  * 2. Redistributions in binary form must reproduce the above copyright
        !            36:  *    notice, this list of conditions and the following disclaimer in the
        !            37:  *    documentation and/or other materials provided with the distribution.
        !            38:  * 3. All advertising materials mentioning features or use of this software
        !            39:  *    must display the following acknowledgement:
        !            40:  *     This product includes software developed by the University of
        !            41:  *     California, Berkeley and its contributors.
        !            42:  * 4. Neither the name of the University nor the names of its contributors
        !            43:  *    may be used to endorse or promote products derived from this software
        !            44:  *    without specific prior written permission.
        !            45:  *
        !            46:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            47:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            48:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            49:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            50:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            51:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            52:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            53:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            54:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            55:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            56:  * SUCH DAMAGE.
        !            57:  *
        !            58:  *     @(#)sys_socket.c        8.1 (Berkeley) 6/10/93
        !            59:  */
        !            60: 
        !            61: #include <sys/param.h>
        !            62: #include <sys/systm.h>
        !            63: #include <sys/file.h>
        !            64: #include <sys/mbuf.h>
        !            65: #include <sys/protosw.h>
        !            66: #include <sys/socket.h>
        !            67: #include <sys/socketvar.h>
        !            68: #include <sys/ioctl.h>
        !            69: #include <sys/stat.h>
        !            70: 
        !            71: #include <net/if.h>
        !            72: #include <net/route.h>
        !            73: 
        !            74: struct fileops socketops =
        !            75:     { soo_read, soo_write, soo_ioctl, soo_select, soo_close };
        !            76: 
        !            77: /* ARGSUSED */
        !            78: int
        !            79: soo_read(fp, uio, cred)
        !            80:        struct file *fp;
        !            81:        struct uio *uio;
        !            82:        struct ucred *cred;
        !            83: {
        !            84: 
        !            85:        return (soreceive((struct socket *)fp->f_data, (struct mbuf **)0,
        !            86:                uio, (struct mbuf **)0, (struct mbuf **)0, (int *)0));
        !            87: }
        !            88: 
        !            89: /* ARGSUSED */
        !            90: int
        !            91: soo_write(fp, uio, cred)
        !            92:        struct file *fp;
        !            93:        struct uio *uio;
        !            94:        struct ucred *cred;
        !            95: {
        !            96: 
        !            97:        return (sosend((struct socket *)fp->f_data, (struct mbuf *)0,
        !            98:                uio, (struct mbuf *)0, (struct mbuf *)0, 0));
        !            99: }
        !           100: 
        !           101: int
        !           102: soo_ioctl(fp, cmd, data, p)
        !           103:        struct file *fp;
        !           104:        u_long cmd;
        !           105:        register caddr_t data;
        !           106:        struct proc *p;
        !           107: {
        !           108:        register struct socket *so = (struct socket *)fp->f_data;
        !           109: 
        !           110:        switch (cmd) {
        !           111: 
        !           112:        case FIONBIO:
        !           113:                if (*(int *)data)
        !           114:                        so->so_state |= SS_NBIO;
        !           115:                else
        !           116:                        so->so_state &= ~SS_NBIO;
        !           117:                return (0);
        !           118: 
        !           119:        case FIOASYNC:
        !           120:                if (*(int *)data) {
        !           121:                        so->so_state |= SS_ASYNC;
        !           122:                        so->so_rcv.sb_flags |= SB_ASYNC;
        !           123:                        so->so_snd.sb_flags |= SB_ASYNC;
        !           124:                } else {
        !           125:                        so->so_state &= ~SS_ASYNC;
        !           126:                        so->so_rcv.sb_flags &= ~SB_ASYNC;
        !           127:                        so->so_snd.sb_flags &= ~SB_ASYNC;
        !           128:                }
        !           129:                return (0);
        !           130: 
        !           131:        case FIONREAD:
        !           132:                *(int *)data = so->so_rcv.sb_cc;
        !           133:                return (0);
        !           134: 
        !           135:        case SIOCSPGRP:
        !           136:                so->so_pgid = *(int *)data;
        !           137:                return (0);
        !           138: 
        !           139:        case SIOCGPGRP:
        !           140:                *(int *)data = so->so_pgid;
        !           141:                return (0);
        !           142: 
        !           143:        case SIOCATMARK:
        !           144:                *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
        !           145:                return (0);
        !           146:        }
        !           147:        /*
        !           148:         * Interface/routing/protocol specific ioctls:
        !           149:         * interface and routing ioctls should have a
        !           150:         * different entry since a socket's unnecessary
        !           151:         */
        !           152:        if (IOCGROUP(cmd) == 'i')
        !           153:                return (ifioctl(so, cmd, data, p));
        !           154:        if (IOCGROUP(cmd) == 'r')
        !           155:                return (rtioctl(cmd, data, p));
        !           156:        return ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, 
        !           157:            (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0));
        !           158: }
        !           159: 
        !           160: int
        !           161: soo_select(fp, which, p)
        !           162:        struct file *fp;
        !           163:        int which;
        !           164:        struct proc *p;
        !           165: {
        !           166:        register struct socket *so = (struct socket *)fp->f_data;
        !           167:        register int s = splnet();
        !           168: 
        !           169:        switch (which) {
        !           170: 
        !           171:        case FREAD:
        !           172:                if (soreadable(so)) {
        !           173:                        splx(s);
        !           174:                        return (1);
        !           175:                }
        !           176:                selrecord(p, &so->so_rcv.sb_sel);
        !           177:                so->so_rcv.sb_flags |= SB_SEL;
        !           178:                break;
        !           179: 
        !           180:        case FWRITE:
        !           181:                if (sowriteable(so)) {
        !           182:                        splx(s);
        !           183:                        return (1);
        !           184:                }
        !           185:                selrecord(p, &so->so_snd.sb_sel);
        !           186:                so->so_snd.sb_flags |= SB_SEL;
        !           187:                break;
        !           188: 
        !           189:        case 0:
        !           190:                if (so->so_oobmark || (so->so_state & SS_RCVATMARK)) {
        !           191:                        splx(s);
        !           192:                        return (1);
        !           193:                }
        !           194:                selrecord(p, &so->so_rcv.sb_sel);
        !           195:                so->so_rcv.sb_flags |= SB_SEL;
        !           196:                break;
        !           197:        }
        !           198:        splx(s);
        !           199:        return (0);
        !           200: }
        !           201: 
        !           202: int
        !           203: soo_stat(so, ub)
        !           204:        register struct socket *so;
        !           205:        register struct stat *ub;
        !           206: {
        !           207: 
        !           208:        bzero((caddr_t)ub, sizeof (*ub));
        !           209:        ub->st_mode = S_IFSOCK;
        !           210:        return ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
        !           211:            (struct mbuf *)ub, (struct mbuf *)0, 
        !           212:            (struct mbuf *)0));
        !           213: }
        !           214: 
        !           215: /* ARGSUSED */
        !           216: int
        !           217: soo_close(fp, p)
        !           218:        struct file *fp;
        !           219:        struct proc *p;
        !           220: {
        !           221:        int error = 0;
        !           222: 
        !           223:        if (fp->f_data)
        !           224:                error = soclose((struct socket *)fp->f_data);
        !           225:        fp->f_data = 0;
        !           226:        return (error);
        !           227: }

unix.superglobalmegacorp.com

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