Subject: Re: Question regarding ifconfig.
To: Shankar Agarwal <shankar_agarwal@net.com>
From: Bill Studenmund <wrstuden@zembu.com>
List: tech-kern
Date: 04/19/2001 14:08:54
On Wed, 18 Apr 2001, Shankar Agarwal wrote:

> Hi All,

First off, you have sent mail to two different *BSD groups. While we have
a common history and share features back and forth over time, you really
should limit this message to the group from which you are using code.

> I have a doubt about the ifconfig file. when i am trying to configure or
> change ip address on the interface. The main calls setifaddr function
> which calls ioctl function with command as SIOCGIFADDR by the following
> lines
> ifr->ifr_addr.sa_family = afp->af_af;
> if (ioctl(s, afp->af_gifaddr, afp->af_ridreq) == 0)
>     clearaddr = 1;
> Now i don't understand why the ioctl is called by SIOCGIFADDR when i am
> configuring an ip address on the interface. Moreover i believe that when

That's because that ioctl is not adding the new address, it is looking to
see if there is an existing one.

> ioctl returns successfully it returns 0 so the clearaddr will be set and
> later on the ip address will be deleted.

Any existing IP address will be deleted. If there already is an address,
you need to get rid of it before you can add/set the new one.

> Please help me out if i am interpreting it wrong as i am not able to
> assign an ip address to the interface in my ported code.

At least in the NetBSD version, I think the action is in the code block
right after the if (clearaddr) { }. That next block is the one which will
set the address.

Take care,

Bill