ioctl problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  
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.
-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subjecthttps://www.redhat.com/mailman/listinfo/redhat-list


[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux