diff options
author | Chris Koch <chrisko@google.com> | 2020-09-16 01:18:14 -0700 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2020-09-16 08:13:09 -0700 |
commit | 1a1c38473709f69a75e1d90fb3b4ff63f7b8c2cd (patch) | |
tree | 7bb9f45445a29fb4d69eb964ff7bbf3eeab91d25 /dhcpv4/nclient4 | |
parent | 8900e1248467faa6c79387c2ff17e6bb165768fa (diff) |
nclients: export serverAddr and ifaceHWAddr
For any users to write their own Discover or Request methods, they need
access to the ifaceHWAddr and serverAddr.
Discovered while trying to move pinterest/bender to nclients.
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv4/nclient4')
-rw-r--r-- | dhcpv4/nclient4/client.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/dhcpv4/nclient4/client.go b/dhcpv4/nclient4/client.go index 41c7a73..8fedf4a 100644 --- a/dhcpv4/nclient4/client.go +++ b/dhcpv4/nclient4/client.go @@ -414,6 +414,21 @@ func IsMessageType(t dhcpv4.MessageType, tt ...dhcpv4.MessageType) Matcher { } } +// RemoteAddr is the default DHCP server address this client sends messages to. +func (c *Client) RemoteAddr() *net.UDPAddr { + // Make a copy so the caller cannot modify the address once the client + // is running. + cop := *c.serverAddr + return &cop +} + +// InterfaceAddr returns the MAC address of the client's interface. +func (c *Client) InterfaceAddr() net.HardwareAddr { + b := make(net.HardwareAddr, len(c.ifaceHWAddr)) + copy(b, c.ifaceHWAddr) + return b +} + // DiscoverOffer sends a DHCPDiscover message and returns the first valid offer // received. func (c *Client) DiscoverOffer(ctx context.Context, modifiers ...dhcpv4.Modifier) (offer *dhcpv4.DHCPv4, err error) { |