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

Ioctl problem



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;
}



With Regards,
Kanhu



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


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