Subject: Re: Adding an IP Address to an Interface
To: Rajnish Madan <rajnishm@delhi.tcs.co.in>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: netbsd-help
Date: 01/15/2001 21:38:12
On Mon, Jan 15, 2001 at 11:09:08AM +0530, Rajnish Madan wrote:
> Hi,
>
> I am trying to add an IP Address to an Interface.
> I am using SIOCAIFADDR ioctl. But it doesn't seem to work.
>
> Here is what i have tried to do.
>
> sock = socket(AF_INET, SOCK_DGRAM, 0);
>
> strncpy(iar.ifra_name,"ex0", strlen("ex0"));
> iar.ifra_addr.sa_family = AF_INET;
>
> strcpy(iar.ifra_addr.sa_data, ip_addr);
>
> ret_val = ioctl(sock, SIOCAIFADDR, &iar);
I think you're missing the netmask, and maybe broadcast too.
Also, ifra_addr shoud be interperded as a sockaddr_in in this case, and
as such the IP address shoud be entered as a u_int32_t, not a string.
See the code of ifconfig for examples.
>
> Ioctl returns success, when i checked using ifconfig -a -A some junk alias was set.
> Also if i try to delete this entry using ifconfig ex0 delete XX, the NetBSD is crashing.
Can you give the stack trace ?
--
Manuel Bouyer <bouyer@antioche.eu.org>
--