|Subject:||Re: [lwip-users] EDIT problem configuring two Ehternet ports|
|Date:||Thu, 23 Jun 2011 10:56:34 +1200|
rocco brandi wrote:
i'm trying to configure a microcontroller that have two ethernet ports.so, i create two netif, assign to each one different IP address and differentMAC address, the same input functions and the two different version of thesame output function (the difference is only in the port number). here is the code:struct netif netif0; struct netif netif1; int InitPhy( void ); int InitMac( void ); err_t myif_link_output0(struct netif *netif, struct pbuf *p); err_t myif_link_output1(struct netif *netif, struct pbuf *p); static struct ip_addr ipaddr0, netmask0, gw0,ipaddr1, netmask1, gw1; IP4_ADDR(&gw0, 192,168,1,240); IP4_ADDR(&ipaddr0, 192,168,0,141); IP4_ADDR(&netmask0, 255,255,255,0); IP4_ADDR(&gw1, 192,168,1,240); IP4_ADDR(&ipaddr1, 192,168,0,140); IP4_ADDR(&netmask1, 255,255,255,0);
Hi Rocco.There are a couple of issues with your IP address configuration. Neither of these are specific to LWIP.
1. You have two network interfaces which are configured with addresses on the same subnet (192.168.0.x). If you send data to any address in 192.168.0.x, the default routing rules for IP will pick the first interface with an address in that range, effectively preventing the second interface from being used for outgoing traffic. With both interfaces using a subnet mask of 255.255.255.0, you must have different values somewhere in the first three octets of the address, e.g. 192.168.0.x for one interface and 192.168.1.x for the other interface.
2. You have an unusual configuration for your gateway address. It should normally be on the same subnet as your device, e.g. if your device is 192.168.0.140 with a subnet mask of 255.255.255.0, then your gateway should be in the 192.168.0.x range. Having the gateway router in a different subnet will only work if the router is on the same physical network as your device, and is configured in some way which allows it to correctly handle your device being in a different subnet from the router (e.g. the router is using a wider subnet mask, or has an explicit routing rule for 192.168.0.x). Some operating systems or IP stacks may not allow this sort of configuration, but LWIP lets you get away with it.
|[Prev in Thread]||Current Thread||[Next in Thread]|