From 1a1c38473709f69a75e1d90fb3b4ff63f7b8c2cd Mon Sep 17 00:00:00 2001 From: Chris Koch Date: Wed, 16 Sep 2020 01:18:14 -0700 Subject: 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 --- dhcpv4/nclient4/client.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'dhcpv4') 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) { -- cgit v1.2.3