lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] How do I send a UDP packet to a target in the LAN via r


From: K.J. Mansley
Subject: Re: [lwip-users] How do I send a UDP packet to a target in the LAN via router????
Date: 01 Apr 2004 09:05:40 +0100

On Wed, 2004-03-31 at 19:39, Kelly Chan wrote:
> Hello, 
> 
> Can anyone tell me how do I route a UDP packet from a PC
> (199.207.2.50:5000) outside the LAN to a PC (e.g. 192.168.1.52:5000)
> resided in a LAN via the router (199.207.2.70) assuming I know the
> other PC's MAC address?  

Do you know the IP address of the machine you are trying to send to?  I
only ask as your earlier question would suggest not.

If you do, and assuming you're using Ethernet, you send a UDP datagram
with the IP address source and destination set to (using the above
example) 199.207.2.50 and 192.168.1.52 respectively.  However, in the
Ethernet header, the destination address should be set to that of the
router.  To encourage this to happen automatically, you can add a route
to the route table.  For example - I do this:

  /* set up my own IP address */
  gethostname(host, 255);
  hostent = gethostbyname(host);  
  ipaddr.addr = ((struct in_addr *)hostent->h_addr_list[0])->s_addr;
  
  /* standard netmask */
  IP4_ADDR(&netmask, 255,255,255,0);

  /* the IP address of the gateway/router */
  IP4_ADDR(&gw, 192,168,96,133);
  
  /* set the default route to be the gateway */
  netif_set_default(netif_add(&ipaddr, &netmask, &gw, your_netif_init_function,
                              tcpip_input));

(I'm not sure if this will work exactly with the latest version of lwIP,
but it should be easy to translate)

This sets 192.168.96.133 to be the default route, so if the destination
IP address is outside the LAN, it will get sent to the gateway to be
forwarded on.

Hope that helps,

Kieran





reply via email to

[Prev in Thread] Current Thread [Next in Thread]