The problem with this solution is that there is no way (to my knowledge)
to figure out from which ip address (and port) the incoming udp data
came from. Further on there is no way to send back data to that address.
If uip_send() is called from within UIP_UDP_APPCALL() the data is sent
to the address that the UDP connection is created for (i.e. 0.0.0.0 port
0), which is hardly any good.
I have made a little "hack" to uip that uses the address of the sender
if the address of the created udp connection is set up as you described.
In most cases I guess that this is the wanted behaviour.

I have replaced the lines (line 1152):

  BUF->srcport  = uip_udp_conn->lport;
  BUF->destport = uip_udp_conn->rport;

  uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
  uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr);

with the following code:

  /* If "any" remote port allowed, respond to sender */
  if (uip_udp_conn->rport == 0) {   
     BUF->destport = BUF->srcport;
  }
  else {
     BUF->destport = uip_udp_conn->rport;
  }
  BUF->srcport  = uip_udp_conn->lport;

  /* If "any" remote addr allowed, respond to sender */
  if (uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_zeroes_addr)) {
     uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
  }
  else {
     uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr);
  }
  uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);


Adam, if you think that this is a good change, feel free to add it to
the uip code. I'm also interested in if Johnny has an even nicer
solution.

/Daniel


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Adam Dunkels
Sent: den 26 november 2006 21:11
To: uip-users@sics.se
Subject: Re: [uip-users] listening UDP connection

Hi!

It is possible to create a listening UDP connection in uIP, but it is a 
little tricky. Create a new UDP connection with a remote address of all 
zeros or all ones (link local broadcast) and a remote port of 0. Bind 
the connection to a local port with uip_udp_bind(). If you have a 
cleaner solution, please post it here for acception into the uIP code.

/adam

Johnny Karlsson wrote:
> Hi!
> 
>  
> 
>  From what i gather, uIP doesn't support listening UDP connections,
i'm 
> writing a tftp-server for uIP and i need that functionality. Would a 
> patch (assuming it's clean and working properly) that enables that 
> functionality in uIP be accepted in the main uIP code?
> 
> Best Regards
> 
> Johnny Karlsson
> 

-- 
Adam Dunkels <[EMAIL PROTECTED]>
http://www.sics.se/~adam/


Reply via email to