Commit | Line | Data |
---|---|---|
fcfe450e | 1 | /* raw_pup.c 4.14 82/10/09 */ |
c2461425 SL |
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" | |
fcfe450e | 8 | #include "../netpup/pup.h" |
c2461425 | 9 | #include "../net/raw_cb.h" |
1e25d807 | 10 | #include "../net/if.h" |
c47a5909 | 11 | #include <errno.h> |
c2461425 SL |
12 | |
13 | /* | |
14 | * Raw PUP protocol interface. | |
15 | */ | |
16 | ||
c2461425 SL |
17 | /* |
18 | * Encapsulate packet in PUP header which is supplied by the | |
19 | * user. This is done to allow user to specify PUP identifier. | |
20 | */ | |
1e25d807 BJ |
21 | rpup_output(m, so) |
22 | register struct mbuf *m; | |
c2461425 SL |
23 | struct socket *so; |
24 | { | |
25 | register struct rawcb *rp = sotorawcb(so); | |
26 | register struct pup_header *pup; | |
126472ab | 27 | int len, error = 0; |
c2461425 | 28 | struct mbuf *n; |
126472ab | 29 | struct sockaddr_pup *dst; |
31c2345c | 30 | struct ifnet *ifp; |
c2461425 | 31 | |
c2461425 SL |
32 | /* |
33 | * Verify user has supplied necessary space | |
34 | * for the header and check parameters in it. | |
35 | */ | |
36 | if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct pup_header)) && | |
126472ab SL |
37 | (m = m_pullup(m, sizeof(struct pup_header))) == 0) { |
38 | error = EMSGSIZE; /* XXX */ | |
c2461425 | 39 | goto bad; |
126472ab | 40 | } |
c2461425 | 41 | pup = mtod(m, struct pup_header *); |
126472ab SL |
42 | if (pup->pup_type == 0) { |
43 | error = EPERM; /* XXX */ | |
c2461425 | 44 | goto bad; |
126472ab SL |
45 | } |
46 | if (pup->pup_tcontrol && (pup->pup_tcontrol & ~PUP_TRACE)) { | |
47 | error = EPERM; /* XXX */ | |
c2461425 | 48 | goto bad; |
126472ab | 49 | } |
c2461425 SL |
50 | for (len = 0, n = m; n; n = n->m_next) |
51 | len += n->m_len; | |
52 | pup->pup_length = len; | |
994855e3 BJ |
53 | #if vax || pdp11 |
54 | pup->pup_length = htons(pup->pup_length); | |
55 | #endif | |
126472ab SL |
56 | /* assume user generates PUP checksum. */ |
57 | dst = (struct sockaddr_pup *)&rp->rcb_faddr; | |
58 | pup->pup_dport = dst->spup_addr; | |
ee787340 | 59 | ifp = if_ifonnetof(pup->pup_dnet); |
126472ab SL |
60 | if (ifp) { |
61 | if (rp->rcb_flags & RAW_LADDR) { | |
62 | register struct sockaddr_pup *src; | |
c2461425 | 63 | |
126472ab SL |
64 | src = (struct sockaddr_pup *)&rp->rcb_laddr; |
65 | pup->pup_sport = src->spup_addr; | |
66 | } else { | |
67 | pup->pup_snet = ifp->if_net; | |
68 | pup->pup_shost = ifp->if_host[0]; | |
69 | /* socket is specified by user */ | |
70 | } | |
71 | return ((*ifp->if_output)(ifp, m, (struct sockaddr *)dst)); | |
72 | } | |
73 | error = ENETUNREACH; | |
c2461425 SL |
74 | bad: |
75 | m_freem(m); | |
126472ab | 76 | return (error); |
c2461425 | 77 | } |