* [ECOS] assign IP address to a specifig mac @ 2005-08-01 21:05 mkhoyila 2005-08-01 21:58 ` Gary Thomas 2005-08-02 7:27 ` Sébastien Couret 0 siblings, 2 replies; 4+ messages in thread From: mkhoyila @ 2005-08-01 21:05 UTC (permalink / raw) To: ecos-discuss can someone guide me on how to assign an IP address to a mac address from eCos ethernet driver? If so, is there a sample code I can look at. thanks. Michael -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [ECOS] assign IP address to a specifig mac 2005-08-01 21:05 [ECOS] assign IP address to a specifig mac mkhoyila @ 2005-08-01 21:58 ` Gary Thomas [not found] ` <21913.63.87.1.243.1122939985.squirrel@webmail.uci.edu> 2005-08-02 7:27 ` Sébastien Couret 1 sibling, 1 reply; 4+ messages in thread From: Gary Thomas @ 2005-08-01 21:58 UTC (permalink / raw) To: mkhoyila; +Cc: eCos Discussion On Mon, 2005-08-01 at 14:07 -0700, mkhoyila@uci.edu wrote: > can someone guide me on how to assign an IP address to a mac address from > eCos ethernet driver? If so, is there a sample code I can look at. thanks. It's unclear exactly what you mean here. * Are you looking for a way to force the IP that a particular interface uses (within an eCos application)? This is done using the CDL, selecting a fixed IP instead of using DHCP or BOOTP. * Perhaps you want for force the association between some external device's address (ESA) and a particular IP address. This is normally discovered via ARP (Address Resolution Protocol). It is possible to push such a relationship directly into the stack, but it's messy and I'm not sure why you would ever want to do so. -- ------------------------------------------------------------ Gary Thomas | Consulting for the MLB Associates | Embedded world ------------------------------------------------------------ -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <21913.63.87.1.243.1122939985.squirrel@webmail.uci.edu>]
* Re: [ECOS] assign IP address to a specifig mac [not found] ` <21913.63.87.1.243.1122939985.squirrel@webmail.uci.edu> @ 2005-08-02 0:28 ` Gary Thomas 0 siblings, 0 replies; 4+ messages in thread From: Gary Thomas @ 2005-08-02 0:28 UTC (permalink / raw) To: mkhoyila; +Cc: eCos Discussion Please copy your replies to the eCos mailing list. Private support is only available with a support contract. On Mon, 2005-08-01 at 16:46 -0700, mkhoyila@uci.edu wrote: > Sorry I did not provide enough info. > > 1) I have a DSL modem and I want to use eCos as embededed RTOS. > > 2) I have written an Ethernet drive for it under eCos and now I want to > assign a static IP to it (eth0 and eth1). I am using third party boot > loader to load eCos. I can see it is loading eCos and runs my "hello > world" applicaiton. > > [cyg_net_init] Init: loopattach(0x00000000) > [cyg_net_init] Init: ifinit(0x00000000) > [cyg_net_init] Init: domaininit(0x00000000) > [cyg_net_init] Init: cyg_net_add_domain(0x8004d638) > New domain internet at 0x00000000 > [cyg_net_init] Init: cyg_net_add_domain(0x8004d0e0) > New domain route at 0x00000000 > [cyg_net_init] Init: cyg_route_init(0x00000000) > [cyg_net_init] Done > > 3) once I can send and receie packets, I am going to do some benchmarks to > test the eCos performace. > > Right now I need to assign an IP address to my eth0 so I can at least ping > it and later create a bridge between two to send and receive packets. > Thanks. Why can't you use DHCP to get the IP address? If you must use a fixed IP, then try settings like these: cdl_component CYGPKG_NET_DHCP { user_value 0 }; cdl_component CYGHWR_NET_DRIVER_ETH0_MANUAL { user_value 0 }; cdl_component CYGHWR_NET_DRIVER_ETH0_BOOTP { user_value 0 }; cdl_component CYGHWR_NET_DRIVER_ETH0_ADDRS { user_value 1 }; cdl_option CYGHWR_NET_DRIVER_ETH0_ADDRS_IP { user_value 192.168.1.169 }; cdl_option CYGHWR_NET_DRIVER_ETH0_ADDRS_NETMASK { user_value 255.255.255.0 }; cdl_option CYGHWR_NET_DRIVER_ETH0_ADDRS_BROADCAST { user_value 192.168.1.255 }; cdl_option CYGHWR_NET_DRIVER_ETH0_ADDRS_SERVER { user_value 192.168.1.101 }; > > > On Mon, 2005-08-01 at 14:07 -0700, mkhoyila@uci.edu wrote: > >> can someone guide me on how to assign an IP address to a mac address > >> from > >> eCos ethernet driver? If so, is there a sample code I can look at. > >> thanks. > > > > It's unclear exactly what you mean here. > > > > * Are you looking for a way to force the IP that a particular > > interface uses (within an eCos application)? > > > > This is done using the CDL, selecting a fixed IP instead > > of using DHCP or BOOTP. > > > > * Perhaps you want for force the association between some external > > device's address (ESA) and a particular IP address. > > > > This is normally discovered via ARP (Address Resolution Protocol). > > It is possible to push such a relationship directly into the > > stack, but it's messy and I'm not sure why you would ever want > > to do so. > > > > -- > > ------------------------------------------------------------ > > Gary Thomas | Consulting for the > > MLB Associates | Embedded world > > ------------------------------------------------------------ > > > -- ------------------------------------------------------------ Gary Thomas | Consulting for the MLB Associates | Embedded world ------------------------------------------------------------ -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [ECOS] assign IP address to a specifig mac 2005-08-01 21:05 [ECOS] assign IP address to a specifig mac mkhoyila 2005-08-01 21:58 ` Gary Thomas @ 2005-08-02 7:27 ` Sébastien Couret 1 sibling, 0 replies; 4+ messages in thread From: Sébastien Couret @ 2005-08-02 7:27 UTC (permalink / raw) To: mkhoyila; +Cc: ecos-discuss [-- Attachment #1: Type: text/plain, Size: 4424 bytes --] Hi, May be it's not solving your issue but I can propose you a sample code that can change the MAC address annd IPv4 address for a specific network interface . This code is working well with the FreeBSP TCP/IP stack ported on eCOS and with ethernet devices/drivers that accept changing their MAC adress trough iotcl calls. The code was originaly written in french, I have translate it quickly without compiling so please forgive my mistakes if any. You could use the API like this : char mac[ETHER_ADDR_LEN]={0xDE,0xAD,0x00,0xBE,0xEF,0x00}; IP_SetMAC("eth0",mac); // Will set MAC adress of eth0 interface to DE:AD:00:BE:EF:00 IP_SetIP("eth0","192.168.0.1"); // Will set the IPv4 adress of eth0 interface to 192.168.0.1 ----------------------------------------------------- Here comes the code : Note: My own defines : #define MACSTRING 18 char* ether_print(const u_char cp[ETHER_ADDR_LEN], char *etheraddr,const unsigned int len) { snprintf(etheraddr,len,"%02x:%02x:%02x:%02x:%02x:%02x",cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]); return(etheraddr); } int IP_SetMAC(const char* interface,unsigned char mac[ETHER_ADDR_LEN]) { int test_sock=0; // Socket PF_INET/SOCK_DGRAM unsigned char i=0; struct ifreq ifr; unsigned char display[MACSTRING]; test_sock = socket( PF_INET, SOCK_DGRAM, 0 ); if( test_sock == -1 ) { diag_printf("Cannot obtain socket"); return (-1); } memset(&ifr,0,sizeof( struct ifreq ) ); strncpy(ifr.ifr_name,interface,IFNAMSIZ); for (i=0;i<ETHER_ADDR_LEN;i++) ifr.ifr_hwaddr.sa_data[i]=mac[i]; ether_print(mac,display,MACSTRING); if( ioctl( test_sock, SIOCSIFHWADDR, &ifr ) == -1 ) { diag_printf("Cannot set MAC adress for '%s' to '%s' because '%s'",interface,display,strerror(errno)); close(test_sock); return (-1); } else diag_printf("MAC Adress for '%s' set to %s'",interface,display); close(test_sock); return(0); } int IP_SetIP(const char* interface,const char * adresse) { int test_sock=0; struct sockaddr_in* addr=NULL; struct ifreq ifr; test_sock = socket( PF_INET, SOCK_DGRAM, 0 ); if( test_sock == -1 ) { fprintf(stderr,"Cannot obtain socket"); return (-1); } memset(&ifr,0,sizeof( struct ifreq ) ); strncpy(ifr.ifr_name,interface,IFNAMSIZ); if( ioctl( test_sock, SIOCGIFADDR, &ifr ) == -1 ) { diag_printf("Cannot obtain IP address of '%s' because '%s'",interface,strerror(errno)); } else { if( ioctl( test_sock, SIOCDIFADDR, &ifr ) != 0 ) { diag_printf("Cannot suppress old IP for '%s' because '%s'",interface,strerror(errno)); } } 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(adresse); strncpy(ifr.ifr_name,interface,IFNAMSIZ); if( ioctl( test_sock, SIOCSIFADDR, &ifr ) != 0 ) { diag_printf("Cannot set IP address of '%s' to '%s' because '%s'",interface,adresse,strerror(errno)); close(test_sock); return (-1); } else diag_printf("IP address for '%s' set '%s' ",interface,inet_ntoa(addr->sin_addr)); close(test_sock); return(0); } Note : I have used the following headers files , they are not all necessary as my original file was doing more work like changing routes and ARP entries.Anyway, I hope this helps. #include <cyg/kernel/kapi.h> #include <pkgconf/system.h> #include <network.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/sockio.h> #ifdef CYGPKG_NET_FREEBSD_SYSCTL #include <sys/sysctl.h> #endif #include <sys/param.h> #include <netdb.h> #include <arpa/inet.h> #include <net/if.h> #include <net/if_dl.h> #include <net/if_types.h> #include <net/route.h> #include <net/ethernet.h> #include <netinet/if_ether.h> #include <netinet/in.h> On Mon, 1 Aug 2005 14:07:51 -0700 (PDT) mkhoyila@uci.edu wrote: > can someone guide me on how to assign an IP address to a mac address from > eCos ethernet driver? If so, is there a sample code I can look at. thanks. > > Michael > > > -- > Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos > and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss > > -- [-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-08-02 7:27 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-08-01 21:05 [ECOS] assign IP address to a specifig mac mkhoyila 2005-08-01 21:58 ` Gary Thomas [not found] ` <21913.63.87.1.243.1122939985.squirrel@webmail.uci.edu> 2005-08-02 0:28 ` Gary Thomas 2005-08-02 7:27 ` Sébastien Couret
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).