RE: ioctl problem

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

 




-----Original Message-----
From: redhat-list-bounces@xxxxxxxxxx [mailto:redhat-list-bounces@xxxxxxxxxx]
On Behalf Of kanhu rauta
Sent: Wednesday, September 28, 2005 8:03 AM
To: redhat-list@xxxxxxxxxx
Subject: 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;
}

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?subject=subscribe
https://www.redhat.com/mailman/listinfo/redhat-list

Hello Kanhu,

For all alias IP addresses I've seen, netmask was always 255.255.255.255.

I guess the alias IP netmask should at least be different from the one for
your main IP address.  Have you tried that?

I may be barking up the wrong tree but it's worth a try.

Michael

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://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