Date: Mon, 16 Sep 2002 17:05:05 +0100 From: Bruce M Simpson <bms@spc.org> To: Leslie Jackson <int@softhome.net> Cc: freebsd-hackers@freebsd.org Subject: Re: ioctl & SIOCDIFADDR Message-ID: <20020916160505.GB11460@spc.org> In-Reply-To: <20020916224146.52e31c8c.int@softhome.net> References: <20020916114315.7feb4bac.int@softhome.net> <20020916085445.GA11460@spc.org> <20020916224146.52e31c8c.int@softhome.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Sep 16, 2002 at 10:41:46PM +0800, Leslie Jackson wrote: > > Try 0.0.0.0. (aka INADDR_ANY). > Failed using that way. (SIOCDIFADDR: can't assign requested addressed) My bad... a hasty answer to a hastily read question. Quick answer:- man 4 networking. Long answer:- Your best option is probably to issue an SIOCGIFCONF and walk the list. This should give you the default addresses assigned to each interface. If you need to look at aliases, use SIOCAIFCONF for the interface you're interested in. Look at netinet/in.c:in_control(). SIOCSIFADDR is now deprecated, so in a way you were right to watch what ifconfig was doing. If you need code examples, have a look in /usr/ports/mbone as some programs which need to determine multicast capabilities of each configured interface will have to walk the ifreq/ifconf list. You'll need to play an elastic buffer game where you specify the size of the chunk of memory you've allocated for the ifconf array, and if it's bigger, reallocate it and ask again. Also if portability is an issue note that Solaris and Linux do it slightly differently now. We haven't picked up that change yet (...scribbles in TODO list..) but what it boils down to is this:- instead of playing elastic buffer games to get the size of the list, you just ask how big the list is. BMS To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020916160505.GB11460>