mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-05 06:39:52 +00:00
Disabled too restrictive behaviour in _bind() and _connect(). Reimplementation pending.
This commit is contained in:
parent
de29a0818e
commit
cb6cec0404
@ -28,7 +28,7 @@
|
|||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
*
|
*
|
||||||
* $Id: udp.c,v 1.19 2003/02/10 21:58:34 davidhaas Exp $
|
* $Id: udp.c,v 1.20 2003/02/14 15:49:02 likewise Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
@ -440,57 +440,68 @@ err_t
|
|||||||
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)
|
||||||
{
|
{
|
||||||
struct udp_pcb *ipcb;
|
struct udp_pcb *ipcb;
|
||||||
u8_t rebind = 0;
|
u8_t rebind;
|
||||||
|
|
||||||
|
rebind = 0;
|
||||||
/* Check for double bind and rebind of the same pcb */
|
/* Check for double bind and rebind of the same pcb */
|
||||||
for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
|
for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
|
||||||
/* is this UDP PCB already on active list? */
|
/* is this UDP PCB already on active list? */
|
||||||
if (pcb == ipcb) {
|
if (pcb == ipcb) {
|
||||||
|
/* TODO: add assert that rebind is 0 here (pcb may
|
||||||
|
occur at most once in list) */
|
||||||
rebind = 1;
|
rebind = 1;
|
||||||
}
|
}
|
||||||
|
/* this code does not allow upper layer to share a UDP port for
|
||||||
|
listening to broadcast or multicast traffic (See SO_REUSE_ADDR and
|
||||||
|
SO_REUSE_PORT under *BSD). TODO: See where it fits instead, OR
|
||||||
|
combine with implementation of UDP PCB flags. Leon Woestenberg. */
|
||||||
|
#if 0
|
||||||
/* port matches that of PCB in list? */
|
/* port matches that of PCB in list? */
|
||||||
if ((ipcb->local_port == port) &&
|
else if ((ipcb->local_port == port) &&
|
||||||
/* IP address matches, or one is IP_ADDR_ANY? */
|
/* IP address matches, or one is IP_ADDR_ANY? */
|
||||||
(ip_addr_isany(&(ipcb->local_ip)) ||
|
(ip_addr_isany(&(ipcb->local_ip)) ||
|
||||||
ip_addr_isany(ipaddr) ||
|
ip_addr_isany(ipaddr) ||
|
||||||
ip_addr_cmp(&(ipcb->local_ip), ipaddr))) {
|
ip_addr_cmp(&(ipcb->local_ip), ipaddr))) {
|
||||||
/* other PCB already binds to this local IP and port */
|
/* other PCB already binds to this local IP and port */
|
||||||
|
DEBUGF(UDP_DEBUG, ("udp_bind: local port %u already bound by another pcb\n", port));
|
||||||
return ERR_USE;
|
return ERR_USE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
/* bind local address */
|
/* bind local address */
|
||||||
ip_addr_set(&pcb->local_ip, ipaddr);
|
ip_addr_set(&pcb->local_ip, ipaddr);
|
||||||
if(port == 0) {
|
if (port == 0) {
|
||||||
#ifndef UDP_LOCAL_PORT_RANGE_START
|
#ifndef UDP_LOCAL_PORT_RANGE_START
|
||||||
#define UDP_LOCAL_PORT_RANGE_START 4096
|
#define UDP_LOCAL_PORT_RANGE_START 4096
|
||||||
#define UDP_LOCAL_PORT_RANGE_END 0x7fff
|
#define UDP_LOCAL_PORT_RANGE_END 0x7fff
|
||||||
#endif
|
#endif
|
||||||
port = UDP_LOCAL_PORT_RANGE_START;
|
port = UDP_LOCAL_PORT_RANGE_START;
|
||||||
ipcb = udp_pcbs;
|
ipcb = udp_pcbs;
|
||||||
while((ipcb != NULL) && (port != UDP_LOCAL_PORT_RANGE_END)) {
|
while((ipcb != NULL) && (port != UDP_LOCAL_PORT_RANGE_END)) {
|
||||||
if(ipcb->local_port == port) {
|
if(ipcb->local_port == port) {
|
||||||
port++;
|
port++;
|
||||||
ipcb = udp_pcbs;
|
ipcb = udp_pcbs;
|
||||||
} else
|
} else
|
||||||
ipcb = ipcb->next;
|
ipcb = ipcb->next;
|
||||||
}
|
}
|
||||||
if(ipcb) /* no more ports available in local range */
|
if(ipcb) /* no more ports available in local range */
|
||||||
return ERR_USE;
|
DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
|
||||||
|
return ERR_USE;
|
||||||
}
|
}
|
||||||
pcb->local_port = port;
|
pcb->local_port = port;
|
||||||
|
|
||||||
/* We need to place the PCB on the list if not already there. */
|
/* We need to place the PCB on the list if not already there. */
|
||||||
if (rebind == 0) {
|
if (rebind == 0) {
|
||||||
pcb->next = udp_pcbs;
|
pcb->next = udp_pcbs;
|
||||||
udp_pcbs = pcb;
|
udp_pcbs = pcb;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUGF(UDP_DEBUG, ("udp_bind: bound to port %u\n", port));
|
DEBUGF(UDP_DEBUG, ("udp_bind: bound to port %u\n", port));
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Connect an UDP PCB.
|
* Connect an UDP PCB.
|
||||||
*
|
*
|
||||||
|
* This will associate the UDP PCB with the remote address.
|
||||||
|
*
|
||||||
* @param pcb UDP PCB to be connected with remote address ipaddr and port.
|
* @param pcb UDP PCB to be connected with remote address ipaddr and port.
|
||||||
* @param ipaddr remote IP address to connect with.
|
* @param ipaddr remote IP address to connect with.
|
||||||
* @param port remote UDP port to connect with.
|
* @param port remote UDP port to connect with.
|
||||||
@ -512,7 +523,9 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
|
|||||||
|
|
||||||
ip_addr_set(&pcb->remote_ip, ipaddr);
|
ip_addr_set(&pcb->remote_ip, ipaddr);
|
||||||
pcb->remote_port = port;
|
pcb->remote_port = port;
|
||||||
#if 1
|
/** TODO: this functionality belongs in upper layers */
|
||||||
|
#if 0
|
||||||
|
|
||||||
pcb->flags |= UDP_FLAGS_CONNECTED;
|
pcb->flags |= UDP_FLAGS_CONNECTED;
|
||||||
/* Nail down local IP for netconn_addr()/getsockname() */
|
/* Nail down local IP for netconn_addr()/getsockname() */
|
||||||
if(ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
|
if(ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
|
||||||
@ -525,7 +538,9 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
|
|||||||
#endif /* UDP_STATS */
|
#endif /* UDP_STATS */
|
||||||
return ERR_RTE;
|
return ERR_RTE;
|
||||||
}
|
}
|
||||||
|
/** TODO: this will bind the udp pcb locally, to the interface which
|
||||||
|
is used to route output packets to the remote address. However, we
|
||||||
|
might want to accept incoming packets on any interface! */
|
||||||
pcb->local_ip = netif->ip_addr;
|
pcb->local_ip = netif->ip_addr;
|
||||||
} else if(ip_addr_isany(&pcb->remote_ip)) {
|
} else if(ip_addr_isany(&pcb->remote_ip)) {
|
||||||
pcb->local_ip.addr = 0;
|
pcb->local_ip.addr = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user