ioctl problem

kanhu rauta kanhu2004 at rediffmail.com
Wed Sep 28 12:02:45 UTC 2005


  
I want to add an alias IP into a particular interface through ioclt
call. I used SIOCSIFADDR and SIOCSIFNETMASK to add the IP with the
netmask. one problem here i am facing, instead of adding the alias IP it
replace the actual IP of that interface. In my code i gave the interface
name as "eth0" not "eth0:0 or eth0:1" due to some constrain.

int add_alias_ip(){
        struct ifreq   ifr;
        int sockfd;


        if( (sockfd=socket(AF_INET,SOCK_DGRAM,0))<0){
		.....................
		.....................                
        }
        memset (&ifr, '\0', sizeof (ifr));

        ifr.ifr_addr=AF_INET;
        ifr.ifr_dstaddr=AF_INET;
        ifr.ifr_netmask=AF_INET;

        strncpy (ifr.ifr_name, "eth0", 4);

        ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr =
inet_addr("192.168.50.11");

        if (ioctl(sockfd, SIOCSIFADDR, &ifr) < 0) {
                .................
		.................
        }

        ((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr.s_addr =
inet_addr("255.255.255.192");
        if (ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) {
        	...................
		...................
        }

        return 0;
}

pls give some suggestion.........



Kanhu Charan Rauta
Innomedia Techonologies Pvt. Ltd
#3278,12Th Main,
HAL 2nd stage.
Banglore-560008.


More information about the redhat-list mailing list