mirror of
https://github.com/danderson/netboot.git
synced 2025-10-15 01:21:40 +02:00
dhcp4: parse transaction ID as a byte slice
This commit is contained in:
parent
bc300c7140
commit
c41aa79265
@ -36,7 +36,7 @@ func testConn(t *testing.T, impl conn, addr string) {
|
||||
|
||||
p := &Packet{
|
||||
Type: MsgDiscover,
|
||||
TransactionID: "1234",
|
||||
TransactionID: []byte("1234"),
|
||||
Broadcast: true,
|
||||
HardwareAddr: mac,
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ func (mt MessageType) String() string {
|
||||
// Packet represents a DHCP packet.
|
||||
type Packet struct {
|
||||
Type MessageType
|
||||
TransactionID string
|
||||
TransactionID []byte // Always 4 bytes
|
||||
Broadcast bool
|
||||
HardwareAddr net.HardwareAddr // Only ethernet supported at the moment
|
||||
|
||||
@ -175,7 +175,7 @@ func (p *Packet) Marshal() ([]byte, error) {
|
||||
// Hops = 0
|
||||
ret.WriteByte(0)
|
||||
// Transaction ID
|
||||
ret.WriteString(p.TransactionID)
|
||||
ret.Write(p.TransactionID)
|
||||
// Seconds elapsed
|
||||
ret.Write([]byte{0, 0})
|
||||
// Broadcast flag
|
||||
@ -267,7 +267,7 @@ func Unmarshal(bs []byte) (*Packet, error) {
|
||||
return nil, fmt.Errorf("packet has unsupported hardware address type/length %d/%d", bs[1], bs[2])
|
||||
}
|
||||
ret.HardwareAddr = net.HardwareAddr(bs[28:34])
|
||||
ret.TransactionID = string(bs[4:8])
|
||||
ret.TransactionID = bs[4:8]
|
||||
if binary.BigEndian.Uint16(bs[10:12])&0x8000 != 0 {
|
||||
ret.Broadcast = true
|
||||
}
|
||||
|
8
dhcp4/testdata/dhcp.parsed
vendored
8
dhcp4/testdata/dhcp.parsed
vendored
@ -1,5 +1,5 @@
|
||||
DHCPDISCOVER
|
||||
"\x9bN\x05W"
|
||||
[]byte{0x9b, 0x4e, 0x5, 0x57}
|
||||
Broadcast
|
||||
MAC: d0:50:99:4e:05:57
|
||||
ClientIP: 0.0.0.0
|
||||
@ -19,7 +19,7 @@ DHCPDISCOVER
|
||||
97: []byte{0x0, 0x0, 0x2, 0x0, 0x3, 0x0, 0x4, 0x0, 0x5, 0x0, 0x6, 0x0, 0x7, 0x0, 0x8, 0x0, 0x9}
|
||||
======
|
||||
DHCPOFFER
|
||||
"\x9bN\x05W"
|
||||
[]byte{0x9b, 0x4e, 0x5, 0x57}
|
||||
Broadcast
|
||||
MAC: d0:50:99:4e:05:57
|
||||
ClientIP: 0.0.0.0
|
||||
@ -37,7 +37,7 @@ DHCPOFFER
|
||||
97: []byte{0x0, 0x0, 0x2, 0x0, 0x3, 0x0, 0x4, 0x0, 0x5, 0x0, 0x6, 0x0, 0x7, 0x0, 0x8, 0x0, 0x9}
|
||||
======
|
||||
DHCPOFFER
|
||||
"\x9bN\x05W"
|
||||
[]byte{0x9b, 0x4e, 0x5, 0x57}
|
||||
Broadcast
|
||||
MAC: d0:50:99:4e:05:57
|
||||
ClientIP: 0.0.0.0
|
||||
@ -61,7 +61,7 @@ DHCPOFFER
|
||||
59: []byte{0x0, 0x0, 0xc, 0x4e}
|
||||
======
|
||||
DHCPREQUEST
|
||||
"R\xcf\xf0\a"
|
||||
[]byte{0x52, 0xcf, 0xf0, 0x7}
|
||||
Unicast
|
||||
MAC: 00:24:d7:ba:0b:20
|
||||
ClientIP: 0.0.0.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user