/[lwip]/lwip/src/core/udp.c
ViewVC logotype

Diff of /lwip/src/core/udp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by jani, Tue Jan 21 14:09:31 2003 UTC revision 1.11 by jani, Wed Jan 22 16:18:05 2003 UTC
# Line 199  udp_input(struct pbuf *p, struct netif * Line 199  udp_input(struct pbuf *p, struct netif *
199        break;        break;
200      }      }
201    }    }
202    /* no fully matching pcb found? */    /* no fully matching pcb found? then look for an unconnected pcb */
203    if(pcb == NULL) {    if(pcb == NULL) {
204      /* Iterate through the UDP pcb list for a pcb that matches      /* Iterate through the UDP pcb list for a pcb that matches
205         the local address. */         the local address. */
206      for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {      for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
207        DEBUGF(UDP_DEBUG, ("udp_input: pcb local port %d (dgram %d)\n",        DEBUGF(UDP_DEBUG, ("udp_input: pcb local port %d (dgram %d)\n",
208                           pcb->local_port, dest));                           pcb->local_port, dest));
209        if(pcb->local_port == dest &&        if((pcb->flags & UDP_FLAGS_CONNECTED) == 0 &&
210           (ip_addr_isany(&pcb->remote_ip) ||            pcb->local_port == dest &&
           ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) &&  
211           (ip_addr_isany(&pcb->local_ip) ||           (ip_addr_isany(&pcb->local_ip) ||
212            ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {            ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {
213          break;          break;
# Line 396  err_t Line 395  err_t
395  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)
396  {  {
397    struct udp_pcb *ipcb;    struct udp_pcb *ipcb;
398      u8_t rebind = 0;
399    /* Insert UDP PCB into the list of active UDP PCBs. */    
400      /* Check for double bind and rebind of the same pcb */
401    for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {    for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
402      if(pcb == ipcb) {      if (pcb == ipcb) {
403        /* Already on the list, just return. */           rebind = 1;
404        return ERR_OK;           break;
405      }      }  else      
406      if (ipcb->local_port == port) {      if (ipcb->local_port == port) {
407        if(ip_addr_isany(&(ipcb->local_ip)) ||        if(ip_addr_isany(&(ipcb->local_ip)) ||
408           ip_addr_isany(ipaddr) ||           ip_addr_isany(ipaddr) ||
# Line 416  udp_bind(struct udp_pcb *pcb, struct ip_ Line 416  udp_bind(struct udp_pcb *pcb, struct ip_
416    ip_addr_set(&pcb->local_ip, ipaddr);    ip_addr_set(&pcb->local_ip, ipaddr);
417    pcb->local_port = port;    pcb->local_port = port;
418        
419    /* We need to place the PCB on the list. */    /* We need to place the PCB on the list if not already there. */
420    pcb->next = udp_pcbs;    if (rebind == 0) {
421    udp_pcbs = pcb;      pcb->next = udp_pcbs;
422        udp_pcbs = pcb;
423      }  
424    
425    DEBUGF(UDP_DEBUG, ("udp_bind: bound to port %d\n", port));    DEBUGF(UDP_DEBUG, ("udp_bind: bound to port %d\n", port));
426    return ERR_OK;    return ERR_OK;
# Line 430  udp_connect(struct udp_pcb *pcb, struct Line 432  udp_connect(struct udp_pcb *pcb, struct
432    struct udp_pcb *ipcb;    struct udp_pcb *ipcb;
433    ip_addr_set(&pcb->remote_ip, ipaddr);    ip_addr_set(&pcb->remote_ip, ipaddr);
434    pcb->remote_port = port;    pcb->remote_port = port;
435      pcb->flags |= UDP_FLAGS_CONNECTED;
436    
437    /* Insert UDP PCB into the list of active UDP PCBs. */    /* Insert UDP PCB into the list of active UDP PCBs. */
438    for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {    for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
# Line 443  udp_connect(struct udp_pcb *pcb, struct Line 446  udp_connect(struct udp_pcb *pcb, struct
446    udp_pcbs = pcb;    udp_pcbs = pcb;
447    return ERR_OK;    return ERR_OK;
448  }  }
449    
450    void
451    udp_disconnect(struct udp_pcb *pcb)
452    {
453            pcb->flags &= ~UDP_FLAGS_CONNECTED;
454    }
455  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
456  void  void
457  udp_recv(struct udp_pcb *pcb,  udp_recv(struct udp_pcb *pcb,
# Line 474  struct udp_pcb * Line 483  struct udp_pcb *
483  udp_new(void) {  udp_new(void) {
484    struct udp_pcb *pcb;    struct udp_pcb *pcb;
485    pcb = memp_malloc(MEMP_UDP_PCB);    pcb = memp_malloc(MEMP_UDP_PCB);
486      pcb->flags = 0;
487    if(pcb != NULL) {    if(pcb != NULL) {
488      memset(pcb, 0, sizeof(struct udp_pcb));      memset(pcb, 0, sizeof(struct udp_pcb));
489      return pcb;      return pcb;

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26