130 |
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) && |
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) && |
131 |
(ip_addr_isany(&pcb->local_ip) || |
(ip_addr_isany(&pcb->local_ip) || |
132 |
ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) { |
ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) { |
133 |
break; |
break; |
134 |
} |
} |
135 |
} |
} |
136 |
} |
} |
137 |
} |
} |
186 |
udp_debug_print(udphdr); |
udp_debug_print(udphdr); |
187 |
#endif /* UDP_DEBUG */ |
#endif /* UDP_DEBUG */ |
188 |
|
|
189 |
|
/* print the UDP source and destination */ |
190 |
|
DEBUGF(UDP_DEBUG, ("udp (%u.%u.%u.%u, %u) <-- (%u.%u.%u.%u, %u)\n", |
191 |
|
ip4_addr1(&iphdr->dest), ip4_addr2(&iphdr->dest), |
192 |
|
ip4_addr3(&iphdr->dest), ip4_addr4(&iphdr->dest), ntohs(udphdr->dest), |
193 |
|
ip4_addr1(&iphdr->src), ip4_addr2(&iphdr->src), |
194 |
|
ip4_addr3(&iphdr->src), ip4_addr4(&iphdr->src), ntohs(udphdr->src))); |
195 |
/* Iterate through the UDP pcb list for a fully matching pcb */ |
/* Iterate through the UDP pcb list for a fully matching pcb */ |
196 |
for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) { |
for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) { |
197 |
DEBUGF(UDP_DEBUG, ("udp_input: pcb local port %u, dgram dest port %u)\n", |
/* print the PCB local and remote address */ |
198 |
pcb->local_port, ntohs(udphdr->dest))); |
DEBUGF(UDP_DEBUG, ("pcb (%u.%u.%u.%u, %u) --- (%u.%u.%u.%u, %u)\n", |
|
DEBUGF(UDP_DEBUG, (" pcb remote ip: %d.%d.%d.%d, dgram src: %d.%d.%d.%d,\n", |
|
|
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip), |
|
|
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), |
|
|
ip4_addr1(&iphdr->src), ip4_addr2(&iphdr->src), |
|
|
ip4_addr3(&iphdr->src), ip4_addr4(&iphdr->src))); |
|
|
DEBUGF(UDP_DEBUG, (" pcb local ip: %d.%d.%d.%d, dgram dest: %d.%d.%d.%d\n", |
|
199 |
ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip), |
ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip), |
200 |
ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), |
ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), pcb->local_port, |
201 |
ip4_addr1(&iphdr->dest), ip4_addr2(&iphdr->dest), |
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip), |
202 |
ip4_addr3(&iphdr->dest), ip4_addr4(&iphdr->dest))); |
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port)); |
203 |
|
|
204 |
/* Do both local and remote addresses match? */ |
/* PCB remote port matches UDP source port? */ |
205 |
if(pcb->remote_port == src && |
if((pcb->remote_port == src) && |
206 |
pcb->local_port == dest && |
/* PCB local port matches UDP destination port? */ |
207 |
|
(pcb->local_port == dest) && |
208 |
|
/* accepting from any remote (source) IP address? or... */ |
209 |
(ip_addr_isany(&pcb->remote_ip) || |
(ip_addr_isany(&pcb->remote_ip) || |
210 |
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) && |
/* PCB remote IP address matches UDP source IP address? */ |
211 |
|
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) && |
212 |
|
/* accepting on any local (netif) IP address? or... */ |
213 |
(ip_addr_isany(&pcb->local_ip) || |
(ip_addr_isany(&pcb->local_ip) || |
214 |
ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) { |
/* PCB local IP address matches UDP destination IP address? */ |
215 |
|
ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) { |
216 |
break; |
break; |
217 |
} |
} |
218 |
} |
} |
219 |
/* no fully matching pcb found? then look for an unconnected pcb */ |
/* no fully matching pcb found? then look for an unconnected pcb */ |
220 |
if(pcb == NULL) { |
if (pcb == NULL) { |
221 |
/* Iterate through the UDP pcb list for a pcb that matches |
/* Iterate through the UDP PCB list for a pcb that matches |
222 |
the local address. */ |
the local address. */ |
223 |
for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) { |
for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) { |
224 |
DEBUGF(UDP_DEBUG, ("udp_input: pcb local port %d (dgram %d)\n", |
DEBUGF(UDP_DEBUG, ("pcb (%u.%u.%u.%u, %u) --- (%u.%u.%u.%u, %u)\n", |
225 |
pcb->local_port, dest)); |
ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip), |
226 |
|
ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), pcb->local_port, |
227 |
|
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip), |
228 |
|
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port)); |
229 |
/* unconnected? */ |
/* unconnected? */ |
230 |
if((pcb->flags & UDP_FLAGS_CONNECTED) == 0 && |
if(((pcb->flags & UDP_FLAGS_CONNECTED) == 0) && |
231 |
/* destination port matches? */ |
/* destination port matches? */ |
232 |
pcb->local_port == dest && |
(pcb->local_port == dest) && |
233 |
/* not bound to a specific (local) interface address? or... */ |
/* not bound to a specific (local) interface address? or... */ |
234 |
(ip_addr_isany(&pcb->local_ip) || |
(ip_addr_isany(&pcb->local_ip) || |
235 |
/* ...matching interface address? */ |
/* ...matching interface address? */ |
236 |
ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) { |
ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) { |
237 |
break; |
break; |
238 |
} |
} |
239 |
} |
} |
240 |
} |
} |
241 |
|
|
|
|
|
242 |
/* Check checksum if this is a match or if it was directed at us. */ |
/* Check checksum if this is a match or if it was directed at us. */ |
243 |
if(pcb != NULL || ip_addr_cmp(&inp->ip_addr, &iphdr->dest)) |
if(pcb != NULL || ip_addr_cmp(&inp->ip_addr, &iphdr->dest)) |
244 |
{ |
{ |
245 |
DEBUGF(UDP_DEBUG, ("udp_input: calculating checksum\n")); |
DEBUGF(UDP_DEBUG, ("udp_input: calculating checksum\n")); |
246 |
pbuf_header(p, UDP_HLEN); |
pbuf_header(p, UDP_HLEN); |
251 |
#endif /* IPv4 */ |
#endif /* IPv4 */ |
252 |
/* Do the UDP Lite checksum */ |
/* Do the UDP Lite checksum */ |
253 |
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), |
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), |
254 |
(struct ip_addr *)&(iphdr->dest), |
(struct ip_addr *)&(iphdr->dest), |
255 |
IP_PROTO_UDPLITE, ntohs(udphdr->len)) != 0) { |
IP_PROTO_UDPLITE, ntohs(udphdr->len)) != 0) { |
256 |
DEBUGF(UDP_DEBUG, ("udp_input: UDP Lite datagram discarded due to failing checksum\n")); |
DEBUGF(UDP_DEBUG, ("udp_input: UDP Lite datagram discarded due to failing checksum\n")); |
257 |
#ifdef UDP_STATS |
#ifdef UDP_STATS |
258 |
++lwip_stats.udp.chkerr; |
++lwip_stats.udp.chkerr; |
267 |
} else { |
} else { |
268 |
if(udphdr->chksum != 0) { |
if(udphdr->chksum != 0) { |
269 |
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), |
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), |
270 |
(struct ip_addr *)&(iphdr->dest), |
(struct ip_addr *)&(iphdr->dest), |
271 |
IP_PROTO_UDP, p->tot_len) != 0) { |
IP_PROTO_UDP, p->tot_len) != 0) { |
272 |
DEBUGF(UDP_DEBUG, ("udp_input: UDP datagram discarded due to failing checksum\n")); |
DEBUGF(UDP_DEBUG, ("udp_input: UDP datagram discarded due to failing checksum\n")); |
273 |
|
|
274 |
#ifdef UDP_STATS |
#ifdef UDP_STATS |
512 |
void |
void |
513 |
udp_disconnect(struct udp_pcb *pcb) |
udp_disconnect(struct udp_pcb *pcb) |
514 |
{ |
{ |
515 |
pcb->flags &= ~UDP_FLAGS_CONNECTED; |
pcb->flags &= ~UDP_FLAGS_CONNECTED; |
516 |
} |
} |
517 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
518 |
void |
void |