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