1 /* in_pcb.c 4.1 81/11/15 */ 2 3 #include "../h/param.h" 4 #include "../h/mbuf.h" 5 #include "../h/socket.h" 6 #include "../h/socketvar.h" 7 #include "../net/inet.h" 8 #include "../net/inet_systm.h" 9 10 struct inpcb * 11 in_pcballoc() 12 { 13 14 struct mbuf *m; 15 16 m = m_getclr(M_WAIT); 17 m->m_off = MMINOFF; 18 return (mtod(m, struct inpcb *)); 19 } 20 21 in_pcbfree(inp) 22 struct inpcb *inp; 23 { 24 struct socket *so = inp->inp_socket; 25 26 if (so->so_isfilerefd == 0) 27 sofree(so); 28 else 29 so->so_pcb = 0; 30 if (inp->inp_lhost) 31 h_free(inp->inp_lhost); 32 if (inp->inp_fhost) 33 h_free(inp->inp_fhost); 34 m_free(dtom(inp)); 35 } 36 37 in_plookup(head, fhost, fport, lhost, lport) 38 struct inpcb *head; 39 struct ip_addr *fhost, *lhost; 40 u_short fport, lport; 41 { 42 register struct inpcb *inp; 43 44 for (inp = head->inp_next; inp != head; inp = inp->inp_next) { 45 if (inp->inp_fhost->s_addr == fhost->s_addr && 46 inp->inp_fport == fport && 47 inp->inp_lhost->s_addr == lhost->s_addr && 48 inp->inp_lport == lport) 49 return (inp); 50 for (inp = head->inp_next; inp != head; inp = inp->inp_next) { 51 if ((inp->inp_fhost->s_addr == fhost->s_addr || 52 inp->inp_fhost == 0) && 53 (inp->inp_fport == fport || inp->inp_fport == 0) && 54 inp->inp_lhost->s_addr == lhost->s_addr && 55 (inp->inp_lport == lport || inp->inp_lport == 0)) 56 return (inp); 57 return (0); 58 } 59 60 in_pcbgenport(head, ent) 61 struct inpcb *head, *ent; 62 { 63 register struct inpcb *inp; 64 65 again: 66 if (head->lport++ < 1024) 67 head->lport = 1024; 68 for (inp = head->inp_next; inp != head; inp = inp->inp_next) 69 if (inp->inp_lport == head->lport) 70 goto again; 71 return (head->lport); 72 } 73