Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using the device MAC address #3

Open
yan12125 opened this issue Feb 15, 2015 · 5 comments
Open

Support using the device MAC address #3

yan12125 opened this issue Feb 15, 2015 · 5 comments

Comments

@yan12125
Copy link

I would like to use device MAC address in the --mac option. For example, on Linux, a possible usage may be:

$ sudo ./dhcptest --quiet
d @eth0
  op=BOOTREPLY chaddr=[MAC address of device eth0] hops=1 xid=D772D15D secs=0 flags=8000
  ciaddr=0.0.0.0 yiaddr=[my IP] siaddr=0.0.0.0 giaddr=[my IP] sname= file=
  10 options:
     53 (DHCP Message Type): offer
     54 (Server Identifier): [DHCP server IP]
     51 (IP Address Lease Time): 86400 (1 day)
      1 (Subnet Mask): 255.255.255.0
      3 (Router Option): [Router IP]
      6 (Domain Name Server Option): [DNS servers' IPs]
     58 (Renewal (T1) Time Value): 43200 (12 hours)
     59 (Rebinding (T2) Time Value): 75600 (21 hours)
     28 (Broadcast Address Option): [Broadcast address]
     15 (Domain Name): [Domain name]
q

I have an implementation at https://github.com/yan12125/dhcptest, however, I'm not familiar with D and the implementation is naive. Could you add the support?

@CyberShadow
Copy link
Owner

Why not use dhclient?
And, why not run ./dhcptest --mac $(ip link show eth0 | tail -1 | cut -d ' ' -f 6) OSLT?

@CyberShadow
Copy link
Owner

I am hesitant to add platform-specific functionality to this tool. I think there are many Linux-specific tools, e.g.: https://github.com/saravana815/dhtest

@scotepi
Copy link

scotepi commented Feb 16, 2015

I would love to something added such as --clientmac that would allow using the client mac without having to look it up first on windows or remember that string on linux.

Having a random mac is great for some networks but others that are slightly locked down using the clients is a lot more reliable.

@yan12125
Copy link
Author

dhtest and other linux-specific tools are also great tools on testing DHCP functionality. However, dhcptest is more handy becuase it dumps all DHCP options. I may try to implement the Windows corresponding part if I have time. After all, still many thanks to the information!

@CyberShadow
Copy link
Owner

Here is some Windows code:

struct NetworkInterface
{
    string name;
    ubyte[] mac;
    string[] ips;
}

NetworkInterface[] getInterfaces()
{
    version (Windows)
    {
        // For this functionality, the Windows bindings are required:
        // $ git clone https://github.com/CS-svnmirror/dsource-bindings-win32 win32
        version(HAVE_WIN32)
        {
            import win32.windef;
            import win32.iphlpapi;
            import win32.iptypes;
            import std.windows.syserror;

            DWORD dwBufLen = 0;
            GetAdaptersInfo(null,  &dwBufLen);
            PIP_ADAPTER_INFO adapterInfo = cast(PIP_ADAPTER_INFO)new ubyte[dwBufLen];
            GetAdaptersInfo(adapterInfo, &dwBufLen).wenforce("GetAdaptersInfo");

            NetworkInterface[] result;
            for (; adapterInfo; adapterInfo = adapterInfo.Next)
            {
                NetworkInterface iface;
                iface.name = adapterInfo.AdapterName.to!string();
                iface.mac = adapterInfo.Address[0..adapterInfo.AddressLength];
                for (auto addr = &adapterInfo.IpAddressList; addr; addr = addr.Next)
                    iface.ips ~= addr.IpAddress.String.to!string();
            }
            return result;
        }
    }
    version (linux)
    {
        // ...
    }

    assert(false, "This functionality is not available in this version or on this platform");
}

Windows interface names are long and don't make much sense, so it would be good to also allow using the interface IP address, using the same syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants