1 #ifndef lint 2 static char rcsid[] = "$Header$"; 3 #endif 4 5 #include "defs.h" 6 7 /* 8 * Address family support routines 9 */ 10 int null_hash(), null_netmatch(), null_output(), 11 null_portmatch(), null_portcheck(), 12 null_checkhost(), null_ishost(), null_canon(); 13 int xnnet_hash(), xnnet_netmatch(), xnnet_output(), 14 xnnet_portmatch(); 15 xnnet_checkhost(), xnnet_ishost(), xnnet_canon(); 16 #define NIL \ 17 { null_hash, null_netmatch, null_output, \ 18 null_portmatch, null_portcheck, null_checkhost, \ 19 null_ishost, null_canon } 20 #define XNSNET \ 21 { xnnet_hash, xnnet_netmatch, xnnet_output, \ 22 xnnet_portmatch, xnnet_portmatch, xnnet_checkhost, \ 23 xnnet_ishost, xnnet_canon } 24 25 struct afswitch afswitch[AF_MAX] = 26 { NIL, NIL, NIL, NIL, NIL, NIL, XNSNET, NIL, NIL, NIL, NIL }; 27 28 struct sockaddr_ns xnnet_default = { AF_NS }; 29 30 xnnet_hash(sns, hp) 31 register struct sockaddr_ns *sns; 32 struct afhash *hp; 33 { 34 register long hash = 0; 35 register u_short *s = sns->sns_addr.x_host.s_host; 36 hp->afh_nethash = xnnet(sns->sns_addr.x_net); 37 hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s; 38 hp->afh_hosthash = hash; 39 } 40 41 xnnet_netmatch(sxn1, sxn2) 42 struct sockaddr_ns *sxn1, *sxn2; 43 { 44 45 return (xnnet(sxn1->sns_addr.x_net) == xnnet(sxn2->sns_addr.x_net)); 46 } 47 48 /* 49 * Verify the message is from the right port. 50 */ 51 xnnet_portmatch(sns) 52 register struct sockaddr_ns *sns; 53 { 54 55 return (ntohs(sns->sns_addr.x_port) == IDPPORT_RIF ); 56 } 57 58 59 /* 60 * xns output routine. 61 */ 62 #ifdef DEBUG 63 int do_output = 0; 64 #endif 65 xnnet_output(flags, sns, size) 66 int flags; 67 struct sockaddr_ns *sns; 68 int size; 69 { 70 struct sockaddr_ns dst; 71 72 dst = *sns; 73 sns = &dst; 74 if (sns->sns_addr.x_port == 0) 75 sns->sns_addr.x_port = htons(IDPPORT_RIF); 76 #ifdef DEBUG 77 if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST) 78 #endif 79 if (sendto(s, msg, size, flags, sns, sizeof (*sns)) < 0) 80 perror("sendto"); 81 } 82 83 /* 84 * Return 1 if the address is believed 85 * -- THIS IS A KLUDGE. 86 */ 87 xnnet_checkhost(sns) 88 struct sockaddr_ns *sns; 89 { 90 return (1); 91 } 92 93 /* 94 * Return 1 if the address is 95 * for a host, 0 for a network. 96 */ 97 xnnet_ishost(sns) 98 struct sockaddr_ns *sns; 99 { 100 register u_short *s = sns->sns_addr.x_host.s_host; 101 102 if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff)) 103 return (0); 104 else 105 return (1); 106 } 107 108 xnnet_canon(sns) 109 struct sockaddr_ns *sns; 110 { 111 112 sns->sns_addr.x_port = 0; 113 } 114 115 /*ARGSUSED*/ 116 null_hash(addr, hp) 117 struct sockaddr *addr; 118 struct afhash *hp; 119 { 120 121 hp->afh_nethash = hp->afh_hosthash = 0; 122 } 123 124 /*ARGSUSED*/ 125 null_netmatch(a1, a2) 126 struct sockaddr *a1, *a2; 127 { 128 129 return (0); 130 } 131 132 /*ARGSUSED*/ 133 null_output(s, f, a1, n) 134 int s, f; 135 struct sockaddr *a1; 136 int n; 137 { 138 139 ; 140 } 141 142 /*ARGSUSED*/ 143 null_portmatch(a1) 144 struct sockaddr *a1; 145 { 146 147 return (0); 148 } 149 150 /*ARGSUSED*/ 151 null_portcheck(a1) 152 struct sockaddr *a1; 153 { 154 155 return (0); 156 } 157 158 /*ARGSUSED*/ 159 null_ishost(a1) 160 struct sockaddr *a1; 161 { 162 163 return (0); 164 } 165 166 /*ARGSUSED*/ 167 null_checkhost(a1) 168 struct sockaddr *a1; 169 { 170 171 return (0); 172 } 173 174 /*ARGSUSED*/ 175 null_canon(a1) 176 struct sockaddr *a1; 177 { 178 179 ; 180 } 181