diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2018-04-10 14:24:15 +0100 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-04-10 15:24:15 +0200 |
commit | 1de25212265384535c68b145fc73f6085342ce23 (patch) | |
tree | 2e6bc6197f9926c103f0821265d3590e504245b5 | |
parent | f21e6dcfef98bc64d829e8650f897ff2e1641c56 (diff) |
add GetInnerPeerAddr (#33)
-rw-r--r-- | dhcpv6/dhcpv6relay.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go index d7dc4b9..513d25a 100644 --- a/dhcpv6/dhcpv6relay.go +++ b/dhcpv6/dhcpv6relay.go @@ -143,3 +143,27 @@ func (d *DHCPv6Relay) GetInnerMessage() (DHCPv6, error) { } } } + +// GetInnerPeerAddr returns the peer address in the inner most relay info +// header, this is typically the IP address of the client making the request. +func (r *DHCPv6Relay) GetInnerPeerAddr() (net.IP, error) { + var ( + p DHCPv6 + err error + ) + p = r + hops := r.HopCount() + addr := r.PeerAddr() + for i := uint8(0); i < hops; i++ { + p, err = DecapsulateRelay(p) + if err != nil { + return nil, err + } + if p.IsRelay() { + addr = p.(*DHCPv6Relay).PeerAddr() + } else { + return nil, fmt.Errorf("Wrong Hop count") + } + } + return addr, nil +} |