[ECOS] Change IP during run-time (netmask change ...)

Richard Rauch Richard.Rauch@vipa.de
Thu Apr 15 09:35:00 GMT 2004


thanks for your reply.
When debugging the IP_SetMask(), I can see that the   s u b n e t m a s k
is changed but not the   n e t m a s k  . Why?
This behaviour can be seen as well with the printouts:

Network stack using 65536 bytes for misc space
                    65536 bytes for mbufs
                    131072 bytes for mbuf clusters
[cyg_net_init] Init: mbinit(0x00000000)
[cyg_net_init] Init: cyg_net_init_devs(0x00000000)
Init device 'emac_eth0'
got MAC from EEPROM: 00:20:d5:77:00:15
[cyg_net_init] Init: loopattach(0x00000000)
[cyg_net_init] Init: ifinit(0x00000000)
IFP: 0x20041530, next: 0x201900a0
IFP: 0x201900a0, next: 0x00000000
[cyg_net_init] Init: domaininit(0x00000000)
[cyg_net_init] Init: cyg_net_add_domain(0x20041f8c)
New domain internet at 0x00000000
[cyg_net_init] Init: cyg_net_add_domain(0x200419b4)
New domain route at 0x00000000
[cyg_net_init] Init: cyg_route_init(0x00000000)
[cyg_net_init] Done
BOOTP[eth0] op: REPLY
       htype: Ethernet
        hlen: 6
        hops: 0
         xid: 0x0
        secs: 0
       flags: 0x0
       hw_addr: 00:20:d5:77:00:15
     client IP: 172.16.129.217
         my IP: 172.16.129.217
     server IP: 0.0.0.0
    gateway IP: 0.0.0.0
  options:
        subnet mask: 255.255.224.0
       IP broadcast: 0.0.0.0
            gateway: 0.0.0.0

----------- 1 ------------
Routing tables
Destination     Gateway         Mask            Flags    Interface
127.0.0.0       127.0.0.1       255.0.0.0       UG       lo0
172.16.128.0    172.16.128.0    255.255.224.0   U        eth0
Interface statistics
eth0    IP: 172.16.129.217, Broadcast: 0.0.0.0, Netmask: 255.255.224.0
        UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
lo0     IP: 127.0.0.1, Broadcast: 127.0.0.1, Netmask: 255.0.0.0
        UP LOOPBACK RUNNING MULTICAST MTU: 16384, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
IP address of 'eth0' changed to '172.16.129.222'             <----- so with
IP_SetIP("eth0","172.16.129.222") we were successfull

----------- 2 ------------
Routing tables
Destination     Gateway         Mask            Flags    Interface
127.0.0.0       127.0.0.1       255.0.0.0       UG       lo0
172.16.0.0      172.16.0.0      255.255.0.0     U        eth0
Interface statistics
eth0    IP: 172.16.129.222, Broadcast: 172.16.255.255, Netmask: 255.255.0.0
        UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
lo0     IP: 127.0.0.1, Broadcast: 127.0.0.1, Netmask: 255.0.0.0
        UP LOOPBACK RUNNING MULTICAST MTU: 16384, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
netmask of 'eth0' changed to '255.255.224.0'          <------ so with
IP_SetMask("eth0","255.255.224.0") we were successfull

----------- 3 ------------
Routing tables
Destination     Gateway         Mask            Flags    Interface
127.0.0.0       127.0.0.1       255.0.0.0       UG       lo0
172.16.0.0      172.16.0.0      255.255.0.0     U        eth0
Interface statistics
eth0    IP: 172.16.129.222, Broadcast: 172.16.255.255, Netmask: 255.255.0.0
<------ why isn't there the new netmask?
        UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
lo0     IP: 127.0.0.1, Broadcast: 127.0.0.1, Netmask: 255.0.0.0
        UP LOOPBACK RUNNING MULTICAST MTU: 16384, Metric: 0
        Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0

Best regards

Richard

-----Original Message-----
From: sebastien Couret [mailto:sebastien.couret@elios-informatique.fr]
Sent: Mittwoch, 14. April 2004 17:56
To: Richard Rauch
Cc: ecos-discuss@sources.redhat.com
Subject: Re: [ECOS] Change IP during run-time (netmask change ...)


On Wednesday 14 April 2004 16:26, Richard Rauch wrote:
> Hi,
>
> we were also interested on this information. we implemented as described
> and it works,
> but with this solution it is not possible to change the network mask, too.
> How we have to do this?
>
> Best Regards
>
> Richard
>

It's almost the same for changing netmask, but you got to use a
SIOCSIFNETMASK call to ioctl instead of SIOCSIFADDR

Here is an example procedure I wrote for doing such thing
Parameter interface is a string like "eth0" and and adresse is a sub-netmask
such "255.255.255.0".
It returns 0 if all is right.

Sorry, comments are in French but I hope it helps.


int IP_SetMask(const char* interface,const char * adresse)
{
 int test_sock=0;
 struct sockaddr_in* addr=NULL;
 struct sockaddr * addrp=NULL;
 struct ifreq ifr;

 memset( &ifr, 0, sizeof( struct ifreq ) );
 addrp = (struct sockaddr *)&(ifr.ifr_addr);
 addr= (struct sockaddr_in *)addrp;
 memset(addr, 0, sizeof( struct sockaddr) );
 addr->sin_len=sizeof(struct sockaddr_in);
 addr->sin_family=AF_INET;
 addr->sin_addr.s_addr=inet_addr(adresse);

 test_sock = socket( PF_INET, SOCK_DGRAM, 0 );
 if( test_sock == -1 )
 {
  diag_printf("Impossible d'obtenir la socket :%s",strerror(errno));
  return (-1);
 }

 strncpy( ifr.ifr_name,interface,IFNAMSIZ);
 if( ioctl( test_sock, SIOCSIFNETMASK, &ifr ) == -1 )
 {
  diag_printf("Impossible de fixer le masque de sous-réseau de '%s' à '%s'
car '%s'",interface,adresse,strerror(errno));
  close(test_sock);
  return (-1);
 }
 diag_printf("Masque de sous-réseau de '%s' fixé à '%s'",interface,adresse);
 close(test_sock);
 return(0);
}


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



More information about the Ecos-discuss mailing list