Re: autoconfiguration of network
On Tue, Oct 05, 1999 at 11:54:11PM +0200, Eric Delaunay wrote:
> I'm thinking about a way to fill the fields of the boxes in the network
> configuration step with good default values. They are actually static values,
> like 192.168.1.1 for inet addr.
> As many sparc are installed from network (rarp, bootp, tftp) the net device is
> already configured and I guess this configuration could be extracted.
> However I don't have much experience on net programming, so I would want to
> know how I could get this configuration from the kernel. I would want to do
> something like ifconfig does when displaying net device informations.
> I started with the following block of code:
> #include "net/if.h"
> struct ifreq ifrs;
> int fd = socket(AF_INET,SOCK_DGRAM,0);
> Then I could get inet addr from "ifrs.ifr_addr" but it's sockattr structure.
> How do I convert it to quad dotted string format ?
ISTR that you can do something like:
struct in_addr addr;
addr = ((sockaddr_in) ifrs.ifr_addr).sin_addr
/* since sockaddr_in is one of a union of types that sockaddr can be
and since AF_INET gets you this flavor of socket - see sys/socket.h
Then there are some macros (I think) to convert to different formats.
I don't remember which exactly, check htonl and friends. ISTR that you
end up converting to host order then picking the bytes out to convert
to ASCII. The 3 least significant bytes (x.y.y.y - the y's) are easy.
The most significant byte is something like 255-x or 256-x before
you convert to ASCII (don't ask me why - it's apparently one of those
I have some old network code around somewhere that does exactly what
you're looking for in the way of conversion, although I get a struct
sockaddr from somewhere different than your ioctl, let me see if I can
find it for you. It may take a few days, though, so maybe you'll have
it cracked by then :-).
> The next step could be doing NIS requests to get hostname & domainname.
> Any pointers greatly appreciated.
> Thanks in advance.
> Eric Delaunay | "La guerre justifie l'existence des militaires.
> email@example.com | En les supprimant." Henri Jeanson (1900-1970)
> To UNSUBSCRIBE, email to firstname.lastname@example.org
> with a subject of "unsubscribe". Trouble? Contact email@example.com
Steve Bowman <firstname.lastname@example.org><email@example.com>
Powered by Debian GNU/Linux <http://www.debian.org>