From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32166 invoked by alias); 17 May 2005 05:02:19 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 32125 invoked from network); 17 May 2005 05:02:13 -0000 Received: from unknown (HELO smtp1.iitb.ac.in) (203.199.81.149) by sourceware.org with SMTP; 17 May 2005 05:02:13 -0000 Received: (qmail 18001 invoked from network); 17 May 2005 10:32:11 +0530 Received: from unknown (HELO ldns2.iitb.ac.in) (10.200.12.2) by smtp1.iitb.ac.in with SMTP; 17 May 2005 10:32:11 +0530 Received: (qmail 18347 invoked by uid 780); 17 May 2005 05:02:11 -0000 Received: from 10.129.1.2 by ldns2 (envelope-from , uid 502) with qmail-scanner-1.23 (spamassassin: 2.64. Clear:RC:1(10.129.1.2):. Processed in 0.172508 secs); 17 May 2005 05:02:11 -0000 Received: from unknown (HELO www.it.iitb.ac.in) (10.129.1.2) by ldns2.iitb.ac.in with SMTP; 17 May 2005 05:02:10 -0000 Received: from 10.129.11.162 (SquirrelMail authenticated user rpai) by www.it.iitb.ac.in with HTTP; Tue, 17 May 2005 10:32:10 +0530 (IST) Message-ID: <33102.10.129.11.162.1116306130.squirrel@www.it.iitb.ac.in> In-Reply-To: <20050516194201.78544.qmail@web14207.mail.yahoo.com> References: 6667 <20050516194201.78544.qmail@web14207.mail.yahoo.com> Date: Tue, 17 May 2005 10:38:00 -0000 From: rpai@it.iitb.ac.in To: "Matt Jerdonek" Cc: ecos-discuss@sources.redhat.com User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [ECOS] eCos- i386-network problem( routing ) X-SW-Source: 2005-05/txt/msg00220.txt.bz2 Following is the code that initalizes 2 realteak cards eth0 & eth1 .... ********************************* //#include #include //#include //#include #include #include #include #ifdef CYGBLD_DEVS_ETH_DEVICE_H // Get the device config if it exists #include CYGBLD_DEVS_ETH_DEVICE_H // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME #endif #ifndef CYGPKG_LIBC_STDIO #define perror(s) diag_printf(#s ": %s\n", strerror(errno)) #endif #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000) #define ETH0_ADDRS_IP 10.128.12.170 #define ETH0_ADDRS_NETMASK 255.255.128.0 #define ETH0_ADDRS_BROADCAST 10.127.129.255 #define ETH1_ADDRS_IP 10.128.12.166 #define ETH1_ADDRS_NETMASK 255.255.128.0 #define ETH1_ADDRS_BROADCAST 10.127.129.255 #define _string(s) #s #define string(s) _string(s) static char stack[STACK_SIZE]; static cyg_thread thread_data; static cyg_handle_t thread_handle; extern void cyg_test_exit(void); void pexit(char *s) { perror(s); cyg_test_exit(); } int SetIP(const char* interface, const char * ip_addr, const char * ntmsk_addr, const char * bcast_addr) { int test_sock=0; struct sockaddr_in* addr=NULL; struct ifreq ifr; test_sock = socket( PF_INET, SOCK_DGRAM, 0 ); if( test_sock == -1 ) { diag_printf("Cant create a socket"); return (0); } memset( &ifr, 0, sizeof( struct ifreq ) ); addr= (struct sockaddr_in *)&(ifr.ifr_addr); memset(addr, 0, sizeof( struct sockaddr_in) ); addr->sin_len=sizeof(struct sockaddr_in); addr->sin_family=AF_INET; addr->sin_addr.s_addr=inet_addr(ip_addr); strncpy(ifr.ifr_name,interface,IFNAMSIZ); if( ioctl( test_sock, SIOCSIFADDR, &ifr ) != 0 ) { diag_printf("Cant set IP of '%s' to '%s' Error :'%s'\n",interface,ip_addr,strerror(errno)); close(test_sock); return (0); } else diag_printf("IP : %s \n",inet_ntoa(addr->sin_addr)); //Setting Netmask Address addr->sin_addr.s_addr=inet_addr(ntmsk_addr); strncpy(ifr.ifr_name,interface,IFNAMSIZ); if( ioctl( test_sock,SIOCSIFNETMASK, &ifr ) != 0 ) { diag_printf("Net Mask Error : %s \n",strerror(errno)); close(test_sock); return (0); } else diag_printf("Nett Mask: %s \n",inet_ntoa(addr->sin_addr)); //Setting Broadcast Address addr->sin_addr.s_addr=inet_addr(bcast_addr); strncpy(ifr.ifr_name,interface,IFNAMSIZ); if( ioctl( test_sock,SIOCSIFBRDADDR, &ifr ) != 0 ) { diag_printf("BroadCast Error : %s \n",strerror(errno)); close(test_sock); return (0); } else diag_printf("BroadCast : %s \n",inet_ntoa(addr->sin_addr)); close(test_sock); return(1); } void Extract_Mac(char *interface) { int sfd,i; cyg_uint8 mac_address[6]; struct ifreq ifr; sfd = socket(AF_INET, SOCK_DGRAM, 0); if (sfd < 0) { perror("Error: socket"); } strcpy(ifr.ifr_name, interface); if (ioctl(sfd, SIOCGIFHWADDR, &ifr) < 0) { perror("Error: SIOCGIFHWADDR 2"); } for ( i = 0; i < ETHER_ADDR_LEN; i++ ) mac_address[i]=ifr.ifr_hwaddr.sa_data[i] ; diag_printf( "Mac addr %02x:%02x:%02x:%02x:%02x:%02x\n", mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5] ); close( sfd ); } void eth_init(cyg_addrword_t p) { // diag_printf("Start PING test\n"); // Initialinzing the ether net devices // init_all_network_interfaces(); char *interface="eth0",*interface1="eth1"; //Extracting Mac ID of eth0 Extract_Mac(interface); //setting IP for eth0 if(SetIP(interface, string(ETH0_ADDRS_IP), string(ETH0_ADDRS_NETMASK), string(ETH0_ADDRS_BROADCAST))) diag_printf("Setting of %s OK\n",interface); else diag_printf("Setting of %s Failed............\n",interface); //Extract Mac ID of eth1 Extract_Mac(interface1); //settint IP for eth1 if(SetIP(interface, string(ETH1_ADDRS_IP), string(ETH1_ADDRS_NETMASK), string(ETH1_ADDRS_BROADCAST))) diag_printf("Setting of %s OK\n",interface1); else diag_printf("Setting of %s Failed............\n",interface1); } void cyg_start(void) { // Create a main thread, so we can run the scheduler and have time 'pass' cyg_thread_create(10, // Priority - just a number eth_init, // entry 0, // entry parameter "Network test", // Name &stack[0], // Stack STACK_SIZE, // Size &thread_handle, // Handle &thread_data // Thread data structure ); cyg_thread_resume(thread_handle); // Start it cyg_scheduler_start(); } ********************** ( LAN bcoz sytem r far ) sys1 --> cross cable -->[(eth0) Sys2 (eth1)]--> LAN <--> sys3 (10.168.12.169) (10.168.12.170) || (10.168.12.171) (10.168.12.172) ( I will try with cross cable btween sys2 & sys3 ) i loaded this code into floppy and executed ... now the sys1 is pining both on eth0 and eth1 but sys3 is not pinging neither to both ... Actually I wanted to create a packet caputre application ..... which will captuure packet passing through this 2 eth(router)... can any one suggest how should i go further to achive this ...... thanks for your help...... > I think part of the problem is that you have both > interfaces on the same subnet. Try moving eth0 and > eth1 to different IP subnets (each with a different > gateway address) and try again. > > However, I still think you'll have trouble pinging > from sys1 to sys3 because I don't think eCos has any > routing support in it. -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss