-/* raw_ip.c 4.13 82/06/20 */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ * @(#)raw_ip.c 7.2 (Berkeley) %G%
+ */
+
+#include "param.h"
+#include "mbuf.h"
+#include "socket.h"
+#include "protosw.h"
+#include "socketvar.h"
+#include "errno.h"
-#include "../h/param.h"
-#include "../h/mbuf.h"
-#include "../h/socket.h"
-#include "../h/protosw.h"
-#include "../h/socketvar.h"
#include "../net/if.h"
-#include "../net/in.h"
-#include "../net/in_systm.h"
-#include "../net/ip.h"
-#include "../net/ip_var.h"
-#include "../net/raw_cb.h"
#include "../net/route.h"
-#include <errno.h>
+#include "../net/raw_cb.h"
+
+#include "in.h"
+#include "in_systm.h"
+#include "ip.h"
+#include "ip_var.h"
/*
* Raw interface to IP protocol.
*/
-static struct sockaddr_in ripdst = { AF_INET };
-static struct sockaddr_in ripsrc = { AF_INET };
-static struct sockproto ripproto = { PF_INET };
+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
register struct ip *ip;
int len = 0, error;
struct rawcb *rp = sotorawcb(so);
- struct ifnet *ifp;
struct sockaddr_in *sin;
/*
*/
for (m = m0; m; m = m->m_next)
len += m->m_len;
- m = m_get(M_DONTWAIT);
+ m = m_get(M_DONTWAIT, MT_HEADER);
if (m == 0) {
error = ENOBUFS;
goto bad;
m->m_len = sizeof(struct ip);
m->m_next = m0;
ip = mtod(m, struct ip *);
- ip->ip_p = so->so_proto->pr_protocol;
+ ip->ip_tos = 0;
+ ip->ip_off = 0;
+ ip->ip_p = rp->rcb_proto.sp_protocol;
ip->ip_len = sizeof(struct ip) + len;
if (rp->rcb_flags & RAW_LADDR) {
sin = (struct sockaddr_in *)&rp->rcb_laddr;
ip->ip_src.s_addr = 0;
ip->ip_dst = ((struct sockaddr_in *)&rp->rcb_faddr)->sin_addr;
ip->ip_ttl = MAXTTL;
- return (ip_output(m, (struct mbuf *)0, &routetoif, 1));
+ return (ip_output(m, rp->rcb_options, &rp->rcb_route,
+ (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST));
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_WAIT, MT_SOOPTS);
+ 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)
+ (void)m_free(*m);
+ return (error);
+}