Annotation of Net2/netimp/raw_imp.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. All advertising materials mentioning features or use of this software
                     14:  *    must display the following acknowledgement:
                     15:  *     This product includes software developed by the University of
                     16:  *     California, Berkeley and its contributors.
                     17:  * 4. Neither the name of the University nor the names of its contributors
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
                     32:  *
                     33:  *     @(#)raw_imp.c   7.6 (Berkeley) 6/28/90
                     34:  */
                     35: 
                     36: #include "param.h"
                     37: #include "mbuf.h"
                     38: #include "socket.h"
                     39: #include "protosw.h"
                     40: #include "socketvar.h"
                     41: #include "errno.h"
                     42: 
                     43: #include "../net/if.h"
                     44: #include "../net/route.h"
                     45: #include "../net/raw_cb.h"
                     46: 
                     47: #include "../netinet/in.h"
                     48: #include "../netinet/in_systm.h"
                     49: #include "../netinet/in_var.h"
                     50: #include "../netinet/in_pcb.h"
                     51: #include "if_imp.h"
                     52: 
                     53: /*
                     54:  * Raw interface to IMP.
                     55:  */
                     56: 
                     57: /*
                     58:  * Generate IMP leader and pass packet to impoutput.
                     59:  * The user must create a skeletal leader in order to
                     60:  * communicate message type, message subtype, etc.
                     61:  * We fill in holes where needed and verify parameters
                     62:  * supplied by user.
                     63:  */
                     64: rimp_output(m, so)
                     65:        register struct mbuf *m;
                     66:        struct socket *so;
                     67: {
                     68:        struct mbuf *n;
                     69:        int len, error = 0;
                     70:        register struct imp_leader *ip;
                     71:        register struct sockaddr_in *sin;
                     72:        register struct raw_inpcb *rp = sotorawinpcb(so);
                     73:        struct in_ifaddr *ia;
                     74:        struct control_leader *cp;
                     75: 
                     76:        /*
                     77:         * Verify user has supplied necessary space
                     78:         * for the leader and check parameters in it.
                     79:         */
                     80:        if ((m->m_len < sizeof(struct control_leader)) &&
                     81:            (m = m_pullup(m, sizeof(struct control_leader))) == 0) {
                     82:                error = EMSGSIZE;       /* XXX */
                     83:                goto bad;
                     84:        }
                     85:        cp = mtod(m, struct control_leader *);
                     86:        if (cp->dl_mtype == IMPTYPE_DATA)
                     87:                if (m->m_len < sizeof(struct imp_leader) &&
                     88:                    (m = m_pullup(m, sizeof(struct imp_leader))) == 0) {
                     89:                        error = EMSGSIZE;       /* XXX */
                     90:                        goto bad;
                     91:                }
                     92:        ip = mtod(m, struct imp_leader *);
                     93:        if (ip->il_format != IMP_NFF) {
                     94:                error = EMSGSIZE;               /* XXX */
                     95:                goto bad;
                     96:        }
                     97: #ifdef notdef
                     98:        if (ip->il_link != IMPLINK_IP &&
                     99:            (ip->il_link<IMPLINK_LOWEXPER || ip->il_link>IMPLINK_HIGHEXPER)) {
                    100:                error = EPERM;
                    101:                goto bad;
                    102:        }
                    103: #endif
                    104: 
                    105:        /*
                    106:         * Fill in IMP leader -- impoutput refrains from rebuilding
                    107:         * the leader when it sees the protocol family PF_IMPLINK.
                    108:         * (message size calculated by walking through mbuf's)
                    109:         */
                    110:        for (len = 0, n = m; n; n = n->m_next)
                    111:                len += n->m_len;
                    112:        ip->il_length = htons((u_short)(len << 3));
                    113:        sin = (struct sockaddr_in *)rp->rinp_rcb.rcb_faddr;
                    114:        imp_addr_to_leader((struct control_leader *)ip, sin->sin_addr.s_addr);
                    115:        /* no routing here */
                    116:        ia = in_iaonnetof(in_netof(sin->sin_addr));
                    117:        if (ia)
                    118:                return (impoutput(ia->ia_ifp, m, (struct sockaddr *)sin));
                    119:        error = ENETUNREACH;
                    120: bad:
                    121:        m_freem(m);
                    122:        return (error);
                    123: }

unix.superglobalmegacorp.com

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