|
|
1.1 ! root 1: /* raw_ip.c 6.1 83/07/29 */ ! 2: ! 3: #include "../h/param.h" ! 4: #include "../h/mbuf.h" ! 5: #include "../h/socket.h" ! 6: #include "../h/protosw.h" ! 7: #include "../h/socketvar.h" ! 8: #include "../h/errno.h" ! 9: ! 10: #include "../net/if.h" ! 11: #include "../net/route.h" ! 12: #include "../net/raw_cb.h" ! 13: ! 14: #include "../netinet/in.h" ! 15: #include "../netinet/in_systm.h" ! 16: #include "../netinet/ip.h" ! 17: #include "../netinet/ip_var.h" ! 18: ! 19: /* ! 20: * Raw interface to IP protocol. ! 21: */ ! 22: ! 23: struct sockaddr_in ripdst = { AF_INET }; ! 24: struct sockaddr_in ripsrc = { AF_INET }; ! 25: struct sockproto ripproto = { PF_INET }; ! 26: /* ! 27: * Changes ! 28: * . clear the field ip_off in rip_output() after allocating ! 29: * the mbuf. ! 30: */ ! 31: /* ! 32: * Setup generic address and protocol structures ! 33: * for raw_input routine, then pass them along with ! 34: * mbuf chain. ! 35: */ ! 36: rip_input(m) ! 37: struct mbuf *m; ! 38: { ! 39: register struct ip *ip = mtod(m, struct ip *); ! 40: ! 41: ripproto.sp_protocol = ip->ip_p; ! 42: ripdst.sin_addr = ip->ip_dst; ! 43: ripsrc.sin_addr = ip->ip_src; ! 44: raw_input(m, &ripproto, (struct sockaddr *)&ripsrc, ! 45: (struct sockaddr *)&ripdst); ! 46: } ! 47: ! 48: /* ! 49: * Generate IP header and pass packet to ip_output. ! 50: * Tack on options user may have setup with control call. ! 51: */ ! 52: rip_output(m0, so) ! 53: struct mbuf *m0; ! 54: struct socket *so; ! 55: { ! 56: register struct mbuf *m; ! 57: register struct ip *ip; ! 58: int len = 0, error; ! 59: struct rawcb *rp = sotorawcb(so); ! 60: struct sockaddr_in *sin; ! 61: ! 62: /* ! 63: * Calculate data length and get an mbuf ! 64: * for IP header. ! 65: */ ! 66: for (m = m0; m; m = m->m_next) ! 67: len += m->m_len; ! 68: m = m_get(M_DONTWAIT, MT_HEADER); ! 69: MBUFNULL(10, m); /* for debugging */ ! 70: if (m == 0) { ! 71: error = ENOBUFS; ! 72: goto bad; ! 73: } ! 74: ! 75: /* ! 76: * Fill in IP header as needed. ! 77: */ ! 78: m->m_off = MMAXOFF - sizeof(struct ip); ! 79: m->m_len = sizeof(struct ip); ! 80: m->m_next = m0; ! 81: ip = mtod(m, struct ip *); ! 82: ip->ip_off = 0; ! 83: ip->ip_p = so->so_proto->pr_protocol; ! 84: ip->ip_len = sizeof(struct ip) + len; ! 85: if (rp->rcb_flags & RAW_LADDR) { ! 86: sin = (struct sockaddr_in *)&rp->rcb_laddr; ! 87: if (sin->sin_family != AF_INET) { ! 88: error = EAFNOSUPPORT; ! 89: goto bad; ! 90: } ! 91: ip->ip_src.s_addr = sin->sin_addr.s_addr; ! 92: } else ! 93: ip->ip_src.s_addr = 0; ! 94: ip->ip_dst = ((struct sockaddr_in *)&rp->rcb_faddr)->sin_addr; ! 95: ip->ip_ttl = MAXTTL; ! 96: return (ip_output(m, (struct mbuf *)0, &rp->rcb_route, ! 97: IP_ROUTETOIF|IP_ALLOWBROADCAST)); ! 98: bad: ! 99: m_freem(m); ! 100: return (error); ! 101: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.