396 |
udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) |
udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) |
397 |
{ |
{ |
398 |
struct udp_pcb *ipcb; |
struct udp_pcb *ipcb; |
|
ip_addr_set(&pcb->local_ip, ipaddr); |
|
|
pcb->local_port = port; |
|
399 |
|
|
400 |
/* Insert UDP PCB into the list of active UDP PCBs. */ |
/* Insert UDP PCB into the list of active UDP PCBs. */ |
401 |
for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) { |
for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) { |
403 |
/* Already on the list, just return. */ |
/* Already on the list, just return. */ |
404 |
return ERR_OK; |
return ERR_OK; |
405 |
} |
} |
406 |
|
if (ipcb->local_port == port) { |
407 |
|
if(ip_addr_isany(&(ipcb->local_ip)) || |
408 |
|
ip_addr_isany(ipaddr) || |
409 |
|
ip_addr_cmp(&(ipcb->local_ip), ipaddr)) { |
410 |
|
/* Port/IP pair already bound */ |
411 |
|
return ERR_USE; |
412 |
|
} |
413 |
|
} |
414 |
} |
} |
415 |
|
|
416 |
|
ip_addr_set(&pcb->local_ip, ipaddr); |
417 |
|
pcb->local_port = port; |
418 |
|
|
419 |
/* We need to place the PCB on the list. */ |
/* We need to place the PCB on the list. */ |
420 |
pcb->next = udp_pcbs; |
pcb->next = udp_pcbs; |
421 |
udp_pcbs = pcb; |
udp_pcbs = pcb; |