Tunnel.py MAC address

When I run tunnel.py and configure the grX interface IP address I
noticedusing
ifconfigthat a seemingly random MAC address is assigned to the gr
interface.
Does ayone know if there is any logic to how the address is created?

Thanks,
Dave

On Thu, Mar 24, 2011 at 9:45 AM, David B.
[email protected]wrote:

When I run tunnel.py and configure the grX interface IP address I
noticed using ifconfig that a seemingly random MAC address is assigned to
the gr interface. Does ayone know if there is any logic to how the address
is created?

Thanks,
Dave

tunnel.py uses the TUN/TAP interface. From my understanding, the kernel
autogenerates a MAC address when you create a new tun/tap device. I
don’t
know the actual internals of how it is generated though.

You should be able to change the address using the SIOCSIFHWADDR option
for
ioctl(), though I haven’t tried this myself on the device.

Tom

the origin code in tunnel.py is

def open_tun_interface(tun_device_filename):
from fcntl import ioctl

mode = IFF_TAP | IFF_NO_PI
TUNSETIFF = 0x400454ca

tun = os.open(tun_device_filename, os.O_RDWR)
ifs = ioctl(tun, TUNSETIFF, struct.pack("16sH", "gr%d", mode))
ifname = ifs[:16].strip("\x00")
return (tun, ifnam

how to add the code:
ioctl(s, SIOCSIFHWADDR, struct.pack(“16sH6s”, ifname,
socket.AF_UNIX, hwaddr))
how can i get ifname and hwaddr?

thank you!!!

Here is what you need to do

 SIOCSIFHWADDR = 0x8924
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 ioctl(s, SIOCSIFHWADDR, struct.pack("16sH6s", ifname,

socket.AF_UNIX, hwaddr))

Andrew

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs