This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

i386-network problem( routing )


Following is the code that initalizes 2 realteak cards eth0 & eth1 ....

*********************************

 //#include <cyg/infra/testcase.h>
#include <network.h>
//#include <pkgconf/system.h>
//#include <pkgconf/net.h>

#include <sys/sockio.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>

#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.171
#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 ......

 and also i am using freebsd ( net template ) should if i go with 'lwip '
will i be sucessful....

 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.
>
> -- Matt
> --- rpai@it.iitb.ac.in wrote:
>>
>>  hello .....
>>
>>  I have made redboot of i386 in floppy ,I loaded my
>> application and executed
>>
>>     I have an application that should capture
>> packet..  i inialized 2 eth
>> card using config tool .. and in program just called
>> init_network_devices()... I have connected a system
>> to eth0 using
>> cross cable and another eth1 to the LAN .
>>
>>
>> (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 want my system to sys1 ping to sys3 , it is not
>> happeneing ...
>>
>>   sys1 is pinging to eth0 ..
>>   sys1 is not pinging to eth1 ..   here it shows '
>> host unreachable '
>>
>>   sys3 is not pinging to eth1 .... it transmists
>> packet ,nothing comes on
>> the screen I  kept transmitting 40 packets..
>>
>>   this messsage is apperaing in the redboot
>>            " arp: 10.168.12.169 is on eth0 but got
>> reply from 0x0017aa34
>> on eth1 "
>>   and also " arp: 10.168.12.172 is on eth0 but got
>> reply from 0x0017b334
>> on eth1 "
>> 	   "  arp: 10.168.12.106 is on eth0 but got reply
>> from 0x0017b334 on eth1 "
>>         mostly the messages of arp is from sys1 ()
>>
>>
>>
>>   my doubt -> why the sys2(eth1)(ip 10.168.12.171)
>> is not responding to
>> sys3 (10.168.12.172)
>>
>>
>>        is it bocoz i have set for both eth0 & 1 same
>> gateway ....
>>
>>         is there any routing protocol to be enabled
>> to pass packet through
>> one eth0 to eth1 another..
>>
>>   I also enabled the chek box in the INET .. "
>> multicast routing support "
>> but it showed me error
>>     when building library....
>>
>>     so what is the routing protocol in ecos and
>> where is it to be woken ..
>>      can any one get me a solution........
>>
>>
>>     thanks
>>
>>
>> --
>> Before posting, please read the FAQ:
>> http://ecos.sourceware.org/fom/ecos
>> and search the list archive:
>> http://ecos.sourceware.org/ml/ecos-discuss
>>
>>
>
>
>
> __________________________________
> Yahoo! Mail Mobile
> Take Yahoo! Mail with you! Check email on your mobile phone.
> http://mobile.yahoo.com/learn/mail
>


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]