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