1 /*	raw_imp.c	4.9	82/03/28	*/
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 "../net/in.h"
9 #include "../net/in_systm.h"
10 #include "../net/if.h"
11 #include "../net/if_imp.h"
12 #include "../net/raw_cb.h"
13 #include "../errno.h"
14 
15 /*
16  * Raw interface to IMP.
17  */
18 
19 struct	sockaddr_in rawimpaddr = { AF_IMPLINK };
20 /*
21  * Generate IMP leader and pass packet to impoutput.
22  * The user must create a skeletal leader in order to
23  * communicate message type, message subtype, etc.
24  * We fill in holes where needed and verify parameters
25  * supplied by user.
26  */
27 rimp_output(m, so)
28 	register struct mbuf *m;
29 	struct socket *so;
30 {
31 	struct mbuf *n;
32 	int len;
33 	register struct imp_leader *ip;
34 	register struct sockaddr_in *sin;
35 	register struct rawcb *rp = sotorawcb(so);
36 	struct ifnet *ifp;
37 	struct control_leader *cp;
38 
39 COUNT(RIMP_OUTPUT);
40 	/*
41 	 * Verify user has supplied necessary space
42 	 * for the leader and check parameters in it.
43 	 */
44 	if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct control_leader)) &&
45 	    (m = m_pullup(m, sizeof(struct control_leader))) == 0)
46 		return (0);
47 	cp = mtod(m, struct control_leader *);
48 	if (cp->dl_mtype == IMPTYPE_DATA)
49 		if (m->m_len < sizeof(struct imp_leader) &&
50 		    (m = m_pullup(m, sizeof(struct imp_leader))) == 0)
51 			return (0);
52 	ip = mtod(m, struct imp_leader *);
53 	if (ip->il_format != IMP_NFF)
54 		goto bad;
55 #ifdef notdef
56 	if (ip->il_link != IMPLINK_IP &&
57 	    (ip->il_link < IMPLINK_LOWEXPER || ip->il_link > IMPLINK_HIGHEXPER))
58 		goto bad;
59 #endif
60 
61 	/*
62 	 * Fill in IMP leader -- impoutput refrains from rebuilding
63 	 * the leader when it sees the protocol family PF_IMPLINK.
64 	 * (message size calculated by walking through mbuf's)
65 	 */
66 	for (len = 0, n = m; n; n = n->m_next)
67 		len += n->m_len;
68 	ip->il_length = htons((u_short)(len << 3));
69 	sin = (struct sockaddr_in *)&rp->rcb_addr;
70 	ip->il_network = sin->sin_addr.s_net;
71 	ip->il_host = sin->sin_addr.s_host;
72 	ip->il_imp = sin->sin_addr.s_imp;
73 	/* no routing here */
74 	ifp = if_ifonnetof(ip->il_network);
75 	if (ifp == 0)
76 		goto bad;
77 	return (impoutput(ifp, m, (struct sockaddr *)&rawimpaddr));
78 
79 bad:
80 	m_freem(m);
81 	return (0);
82 }
83