lwip-users
[Top][All Lists]
Advanced

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

AW: [lwip-users] using 2 IP numbers at the same time


From: Goldschmidt Simon
Subject: AW: [lwip-users] using 2 IP numbers at the same time
Date: Wed, 7 Nov 2007 12:36:05 +0100

Beware that you are mixing lwIP core functions (netif_add() / netif_set_default()) with socket API functions. While the socket API functions are always thread-safe, the core functions are not! You may not call netif_add/netif_set_default directly from an application thread! This might result in 2 threads accessing lwIP internal structures at the same time which might result in a corrupted netif list.
 
Instead add the network interfaces from the point/task where you initialize lwIP and let the application threads use sockets only!
 
As to the actual issue, I also don't know whether this really works. You might have to design your driver in a way it knows both interfaces and calls tcpip_input() with the correct netif based on the destination IP of received packets. This is to let the stack know for which netif/IP the packet was received.
 
But I didn't test this, either.
 
Simon
 

Von: address@hidden [mailto:address@hidden Im Auftrag von KORAY KORKMAZER (MIKES INTERNET)
Gesendet: Mittwoch, 7. November 2007 10:21
An: address@hidden
Betreff: [lwip-users] using 2 IP numbers at the same time

Hello,

 

I am pretty new in using lwip and  want to ask your recommendations on an issue about using 2 IP numbers at the same time.

 

Let me describe my design first:

I am working on an Xilinx ML-403 platform and writing code for PPC inside the FGPGA. I have an ethernet interface for communication and using LwIP(LwIP 2.00.a version) for it.

Also using Xilinx MicroKernel.

Simply my application will have a static IP number and will communicate with another system which has a static IP number too.

 

But now another requirement has been arised. That is my application must communicate  with a second  system from an another IP number. And I still have one physical ethernet port.

This means that my application must  have 2 IP numbers. And it must listen both connections at the same time.

 

From mail group , I read that this  is possible with creating seperate network interfaces with ‘netif_add’ function.

In my design , I thought of creating two threads which  will establish two sockets and add seperate network interfaces at the same time.

But it didn`t work. While I  could communicate with one IP number , the other connection could not be established.

Here is my thread that I use for creating socket:

 

void *socket_app_thread( void *arg )

{

.....//declarations an initializations  IP, port , MAC, subnet, gw

 

   xtemacif_setmac( 0, ( u8_t* )fullmac ); //Set MAC

   IP4_ADDR( &gw, gateway[ 0 ], gateway[ 1 ], gateway[ 2 ], gateway[ 3 ] );

   //Set gateway

   IP4_ADDR( &ipaddr, ip[ 0 ], ip[ 1 ], ip[ 2 ], ip[ 3 ] ); //Set ip

   IP4_ADDR( &netmask, subnet[ 0 ], subnet[ 1 ], subnet[ 2 ], subnet[ 3 ] );

   //Set subnet msk

 

   /* allocate netif structure */

   default_netif = mem_malloc( sizeof( struct netif ) );

   if ( default_netif == NULL )

   {

      return NULL;

   }

   default_netif = netif_add( default_netif,

                              &ipaddr,

                              &netmask,

                              NULL,

                              &XTemacIf_ConfigTable[ 0 ],

                              xtemacif_init,

                              tcpip_input );

 

   netif_set_default( default_netif );

 

   /* Register XEmacHandler with interrupt controller and enable interrupts

    * with XMK

    */

   register_int_handler( XPAR_OPB_INTC_0_TRIMODE_MAC_GMII_IP2INTC_IRPT_INTR,

                         (XInterruptHandler )XTemac_IntrFifoHandler,

                         xtemacif_ptr->instance_ptr );

 

   /* Enable EMAC interrupts in XMK */

   enable_interrupt( XPAR_OPB_INTC_0_TRIMODE_MAC_GMII_IP2INTC_IRPT_INTR );

   /*-----------------------------------------------------------------------*/

   /* create socket and start application                                   */

   /*-----------------------------------------------------------------------*/

   sock = socket( AF_INET, SOCK_STREAM, 0 );

   addr.sin_family = AF_INET;

   addr.sin_port = htons( port );

   addr.sin_addr.s_addr = INADDR_ANY;

   bind( sock, ( struct sockaddr* ) &addr, sizeof( addr ) );

   listen( sock, 7);

 

   SockDesc = accept( sock, ( struct sockaddr* ) &rem, &lensock );

 

}

 

 

The second thread is similar with this one, only IP  and port number is different.

Do you have any idea where I am having mistakes?

I really appreciate for your help.

 

Thanks in advance.

Koray.

 


reply via email to

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