1 /* raw_pup.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/pup.h" 11 #include "../net/raw_cb.h" 12 #include "../net/if.h" 13 #include "../errno.h" 14 15 /* 16 * Raw PUP protocol interface. 17 */ 18 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 */ 23 rpup_output(m, so) 24 register struct mbuf *m; 25 struct socket *so; 26 { 27 register struct rawcb *rp = sotorawcb(so); 28 register struct pup_header *pup; 29 int len; 30 struct mbuf *n; 31 struct sockaddr_pup *spup; 32 struct ifnet *ifp; 33 34 COUNT(RPUP_OUTPUT); 35 /* 36 * Verify user has supplied necessary space 37 * for the header and check parameters in it. 38 */ 39 if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct pup_header)) && 40 (m = m_pullup(m, sizeof(struct pup_header))) == 0) 41 goto bad; 42 pup = mtod(m, struct pup_header *); 43 if (pup->pup_type == 0) 44 goto bad; 45 if (pup->pup_tcontrol && (pup->pup_tcontrol & ~PUP_TRACE)) 46 goto bad; 47 for (len = 0, n = m; n; n = n->m_next) 48 len += n->m_len; 49 pup->pup_length = len; 50 spup = (struct sockaddr_pup *)&(rp->rcb_socket->so_addr); 51 pup->pup_sport = spup->spup_addr; 52 /* for now, assume user generates PUP checksum. */ 53 spup = (struct sockaddr_pup *)&rp->rcb_addr; 54 pup->pup_dport = spup->spup_addr; 55 56 ifp = if_ifonnetof(pup->pup_dnet); 57 if (ifp == 0) 58 goto bad; 59 return (enoutput(ifp, m, (struct sockaddr *)spup)); 60 61 bad: 62 m_freem(m); 63 return (0); 64 } 65