Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Oct 1996 22:19:14 +0200 (MET DST)
From:      J Wunsch <j@uriah.heep.sax.de>
To:        freebsd-hackers@freebsd.org (FreeBSD hackers)
Cc:        msmith@atrad.adelaide.edu.au (Michael Smith)
Subject:   Re: Linux emulation, gethostid()
Message-ID:  <199610232019.WAA27409@uriah.heep.sax.de>
In-Reply-To: <199610230908.SAA26604@genesis.atrad.adelaide.edu.au> from Michael Smith at "Oct 23, 96 06:38:26 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
As Michael Smith wrote:

> > Grab the number you like by any means you like somewhere in rc.local,
> > and issue a sethostid(3) with it.  No need to bloat the kernel for
> > this.
> 
> Gotcha; I hadn't seen kern.hostid before.  Anyone recommend a quick example
> I can look at for retrieving a sysctl value from inside an LKM?

What do you need it for in an LKM?

Put this as, say, /usr/sbin/sethostid, and invoke it from rc.local.
It tries to find out the lower 32 bit of the (first) ethernet address,
and failing to find any ethernet interfaces, it uses the first four
bytes of the MD5 checksum of the hostname.

#!/bin/sh

export PATH="/bin:/usr/bin:/sbin:/usr/sbin"

hostid=$(ifconfig -a | awk -F : '/ether/ {printf $3 $4 $5 $6; exit}')

if [ "$hostid" = "" ]
then
	hostid=$(hostname | md5 | sed -e 's/\(........\).*/\1/')
fi

hostid=$( (echo ibase=16; echo $hostid | tr '[a-z]' '[A-Z]') | bc)
sysctl -wn kern.hostid=$hostid >/dev/null


-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610232019.WAA27409>