From e799b6e1ab7aed8544fef4c975d5ded174edd5ea Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 27 Feb 2016 22:36:49 -0800 Subject: [PATCH] Correct the parsing of the server IP address. It's the address of the responding server, not the boot server. Which makes sense, since there's another field for the boot server name. --- dhcp/dhcp.go | 10 +++++----- dhcp/testdata/dhcp.parsed | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dhcp/dhcp.go b/dhcp/dhcp.go index cab1ee0..f0390fd 100644 --- a/dhcp/dhcp.go +++ b/dhcp/dhcp.go @@ -60,9 +60,9 @@ type Packet struct { ClientAddr net.IP // Client's current IP address (it will respond to ARP for this IP) YourAddr net.IP // Client IP address offered/assigned by server + ServerAddr net.IP // Responding server's IP address RelayAddr net.IP // IP address of DHCP relay agent, if an agent forwarded the request - BootServerAddr net.IP // "Next bootstrap server" IP address, used for netbooting BootServerName string BootFilename string @@ -82,14 +82,14 @@ func (p *Packet) testString() string { MAC: %s ClientIP: %s YourIP: %s + ServerIP: %s RelayIP: %s - BootServerIP: %s BootServerName: %s BootFilename: %s Options: -`, p.Type, p.TransactionID, bcast, p.HardwareAddr, p.ClientAddr, p.YourAddr, p.RelayAddr, p.BootServerAddr, p.BootServerName, p.BootFilename) +`, p.Type, p.TransactionID, bcast, p.HardwareAddr, p.ClientAddr, p.YourAddr, p.ServerAddr, p.RelayAddr, p.BootServerName, p.BootFilename) var opts []int for n := range p.Options { @@ -156,7 +156,7 @@ func (p *Packet) Marshal() ([]byte, error) { writeIP(ret, p.ClientAddr) writeIP(ret, p.YourAddr) - writeIP(ret, p.BootServerAddr) + writeIP(ret, p.ServerAddr) writeIP(ret, p.RelayAddr) // MAC address + 10 bytes of padding @@ -236,7 +236,7 @@ func Unmarshal(bs []byte) (*Packet, error) { ret.ClientAddr = net.IP(bs[12:16]) ret.YourAddr = net.IP(bs[16:20]) - ret.BootServerAddr = net.IP(bs[20:24]) + ret.ServerAddr = net.IP(bs[20:24]) ret.RelayAddr = net.IP(bs[24:28]) if err := ret.Options.Unmarshal(bs[240:]); err != nil { diff --git a/dhcp/testdata/dhcp.parsed b/dhcp/testdata/dhcp.parsed index 014621a..c1707b2 100644 --- a/dhcp/testdata/dhcp.parsed +++ b/dhcp/testdata/dhcp.parsed @@ -5,9 +5,9 @@ DHCPDISCOVER MAC: d0:50:99:4e:05:57 ClientIP: 0.0.0.0 YourIP: 0.0.0.0 + ServerIP: 0.0.0.0 RelayIP: 0.0.0.0 - BootServerIP: 0.0.0.0 BootServerName: BootFilename: @@ -27,9 +27,9 @@ DHCPOFFER MAC: d0:50:99:4e:05:57 ClientIP: 0.0.0.0 YourIP: 0.0.0.0 + ServerIP: 0.0.0.0 RelayIP: 0.0.0.0 - BootServerIP: 0.0.0.0 BootServerName: BootFilename: @@ -47,9 +47,9 @@ DHCPOFFER MAC: d0:50:99:4e:05:57 ClientIP: 0.0.0.0 YourIP: 192.168.16.12 + ServerIP: 192.168.16.1 RelayIP: 0.0.0.0 - BootServerIP: 192.168.16.1 BootServerName: BootFilename: