Bochs is a x86 PC emulator which means that you have one real PC (lets call it the host) on which you can have multiple virtual PCs (aka guests). To the host, bochs is like a normal program, to the guest operating system it is like an almost real PC. It is even able to emulate a NE2000 compatible network adapter. On Linux hosts this is done via a tun network device. To setup the ip address of that tun device and to add an arp cache entry, one could use a shell script, which calls ifconfig and arp. But, if bochs runs as an unprivileged user you cannot use a shell script or any other method that depends on external programms like ifconfig and arp - even if you make that script setuid, since the effective user is not copied on fork(). Thus I wrote tunconfig which calls the appropriate ioctl()s. You can install it into /usr/bin with the setuid bit set. To avoid abuse you can only setup devices from tun0 to tun9 and even the ip and mac addresses are hacked into.
$ diet -Os gcc -W -Wall -Os -s -nostdinc -o tunconfig tunconfig.c $ su $ chown root.root tunconfig $ echo "Dont use setuid binaries - they lead to the dark side!" $ chmod 4755 tunconfig $ mv -iv tunconfig /usr/bin/ $ exit
Since the ip addresses and mac addresses are directly stored in the executable, you can configure tunconfig only by modifing the source and recompiling it. Assume you have the following in your ~/.bochsrc:
ne2k: ioaddr=0x240, irq=9, mac=de:ad:be:ef:ee:01, ethmod=tuntap, ethdev=tun0, script=/usr/bin/tunconfigThen you must change the mac_guest identifier to reflect this:
const unsigned char mac_guest[6] = { 0xde, 0xad, 0xbe, 0xef, 0xee, 0x01 };The ip_guest[4] identifier has to reflect the ip address you assigned to that emulated NE2000 nic of your guest operating system. ip_host[4] is the default gateway of your guest operating system and also the ip address that will be assigned to the tun device of the host OS.