1 /* raw_pup.c 4.4 82/03/03 */ 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 "/usr/include/errno.h" 13 14 /* 15 * Raw PUP protocol interface. 16 */ 17 18 /*ARGSUSED*/ 19 rpup_ctlinput(m) 20 struct mbuf *m; 21 { 22 COUNT(RPUP_CTLINPUT); 23 } 24 25 /* 26 * Encapsulate packet in PUP header which is supplied by the 27 * user. This is done to allow user to specify PUP identifier. 28 */ 29 rpup_output(m0, so) 30 struct mbuf *m0; 31 struct socket *so; 32 { 33 register struct rawcb *rp = sotorawcb(so); 34 register struct pup_header *pup; 35 int len; 36 struct mbuf *n; 37 struct sockaddr_pup *spup; 38 struct ifnet *ifp; 39 40 COUNT(RPUP_OUTPUT); 41 /* 42 * Verify user has supplied necessary space 43 * for the header and check parameters in it. 44 */ 45 if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct pup_header)) && 46 (m = m_pullup(m, sizeof(struct pup_header)) == 0) { 47 goto bad; 48 pup = mtod(m, struct pup_header *); 49 if (pup->pup_type == 0) 50 goto bad; 51 if (pup->pup_tcontrol && (pup->pup_tcontrol & ~PUP_TRACE)) 52 goto bad; 53 for (len = 0, n = m; n; n = n->m_next) 54 len += n->m_len; 55 pup->pup_length = len; 56 spup = (struct sockaddr_pup *)&rp->rcb_addr; 57 pup->pup_dport = spup->spup_addr; 58 59 /* 60 * Insure proper source address is included. 61 */ 62 spup = (struct sockadrr_pup *)rp->rcb_socket->so_addr; 63 pup->pup_sport = spup->spup_addr; 64 /* for now, assume user generates PUP checksum. */ 65 66 ifp = if_ifonnetof(&rp->rcb_addr); 67 if (ifp == 0) { 68 ifp = if_gatewayfor(&rp->rcb_addr); 69 if (ifp == 0) 70 goto bad; 71 } 72 return (enoutput((struct ifnet *)rp->rcb_pcb, m, PF_PUP)); 73 74 bad: 75 m_freem(m); 76 return (0); 77 } 78