📄 raw_ip.c
字号:
#ifndef lintstatic char *sccsid = "@(#)raw_ip.c 4.1 (ULTRIX) 7/2/90";#endif lint/************************************************************************ * * * Copyright (c) 1985 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//************************************************************************ * Modification History * * * * Uttam Shikarpur - 10/17/89 * * Changed the value of MAXTTL from a manifest constant * * to an variable (an integer.) * * * 30-May-89 U. Sinkewicz * Added support for asymmetric network drivers. * * 15-Jan-88 lp * Merge of final 43BSD changes. * * Larry Cohen - 09/16/85 * * Add 43bsd alpha tape changes for subnet routing * * * ************************************************************************//* * Copyright (c) 1982 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * * raw_ip.c 6.6 (Berkeley) 6/8/85 */#include "../h/param.h"#include "../h/mbuf.h"#include "../h/socket.h"#include "../h/protosw.h"#include "../h/socketvar.h"#include "../h/errno.h"#include "../net/net/if.h"#include "../net/net/route.h"#include "../net/net/raw_cb.h"#include "../net/netinet/in.h"#include "../net/netinet/in_systm.h"#include "../net/netinet/ip.h"#include "../net/netinet/ip_var.h"/* * Raw interface to IP protocol. */struct sockaddr_in ripdst = { AF_INET };struct sockaddr_in ripsrc = { AF_INET };struct sockproto ripproto = { PF_INET };/* * Setup generic address and protocol structures * for raw_input routine, then pass them along with * mbuf chain. */rip_input(m) struct mbuf *m;{ register struct ip *ip = mtod(m, struct ip *); ripproto.sp_protocol = ip->ip_p; ripdst.sin_addr = ip->ip_dst; ripsrc.sin_addr = ip->ip_src; raw_input(m, &ripproto, (struct sockaddr *)&ripsrc, (struct sockaddr *)&ripdst);}/* * Generate IP header and pass packet to ip_output. * Tack on options user may have setup with control call. */rip_output(m, so) register struct mbuf *m; struct socket *so;{ register struct ip *ip; int error; struct rawcb *rp = sotorawcb(so); struct sockaddr_in *sin; short proto = rp->rcb_proto.sp_protocol; if (smp_debug){ if ( !smp_owner(&so->lk_socket) ) panic("rip_output: not lock owner\n"); } /* * if the protocol is IPPROTO_RAW, the user handed us a * complete IP packet. Otherwise, allocate an mbuf for a * header and fill it in as needed. */ if (proto != IPPROTO_RAW) { /* * Calculate data length and get an mbuf * for IP header. */ int len = 0; struct mbuf *m0; for (m0 = m; m; m = m->m_next) len += m->m_len; m = m_get(M_DONTWAIT, MT_HEADER); if (m == 0) { m = m0; error = ENOBUFS; goto bad; } /* * Fill in IP header as needed. */ m->m_off = MMAXOFF - sizeof(struct ip); m->m_len = sizeof(struct ip); m->m_next = m0; ip = mtod(m, struct ip *); ip->ip_tos = 0; ip->ip_off = 0; ip->ip_p = proto; ip->ip_len = sizeof(struct ip) + len; ip->ip_ttl = maxttl; } else ip = mtod(m, struct ip *); if (rp->rcb_flags & RAW_LADDR) { sin = (struct sockaddr_in *)&rp->rcb_laddr; if (sin->sin_family != AF_INET) { error = EAFNOSUPPORT; goto bad; } ip->ip_src.s_addr = sin->sin_addr.s_addr; } else ip->ip_src.s_addr = 0; ip->ip_dst = ((struct sockaddr_in *)&rp->rcb_faddr)->sin_addr; return (ip_output(m, rp->rcb_options, &rp->rcb_route, (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST, so));bad: m_freem(m); return (error);}/* * Raw IP socket option processing. */rip_ctloutput(op, so, level, optname, m) int op; struct socket *so; int level, optname; struct mbuf **m;{ int error = 0; register struct rawcb *rp = sotorawcb(so); if (level != IPPROTO_IP) error = EINVAL; else switch (op) { case PRCO_SETOPT: switch (optname) { case IP_OPTIONS: return (ip_pcbopts(&rp->rcb_options, *m)); default: error = EINVAL; break; } break; case PRCO_GETOPT: switch (optname) { case IP_OPTIONS: *m = m_get(M_DONTWAIT, MT_SOOPTS); /* SMP */ if (*m == NULL){ error = ENOBUFS; break; } if (rp->rcb_options) { (*m)->m_off = rp->rcb_options->m_off; (*m)->m_len = rp->rcb_options->m_len; bcopy(mtod(rp->rcb_options, caddr_t), mtod(*m, caddr_t), (unsigned)(*m)->m_len); } else (*m)->m_len = 0; break; default: error = EINVAL; break; } break; } if (op == PRCO_SETOPT && *m != NULL) (void)m_free(*m); return (error);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -