-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootp.go
55 lines (47 loc) · 1.36 KB
/
bootp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
type bootpMessage struct {
Opcode uint8
HardwareType uint8
HardwareAddrLength uint8
Hops uint8
Xid uint32
Seconds uint16
Flags uint16
ClientIPAddr [4]byte
YourIPAddr [4]byte
ServerIPAddr [4]byte
GatewayIPAddr [4]byte
ClientHardwareAddr [16]byte
ServerName [64]byte
BootFilename [128]byte
VendorSpecific [64]byte
}
type incompleteBootpMessage struct {
Opcode uint8
HardwareType uint8
HardwareAddrLength uint8
Hops uint8
Xid uint32
Seconds uint16
Flags uint16
ClientIPAddr [4]byte
YourIPAddr [4]byte
ServerIPAddr [4]byte
GatewayIPAddr [4]byte
ClientHardwareAddr [16]byte
}
func makeBootpPacket(servername string, id uint32, clientHwAddr [6]byte, yourIp [4]byte, serverIp [4]byte, bootfile string) bootpMessage {
var ret bootpMessage
ret.Opcode = 2
ret.HardwareType = 1
ret.HardwareAddrLength = 6
copy(ret.ClientHardwareAddr[:], clientHwAddr[:])
ret.Xid = id
ret.YourIPAddr = yourIp
ret.ServerIPAddr = serverIp
ret.GatewayIPAddr = serverIp
ret.VendorSpecific = [64]byte{99, 130, 83, 99, 1, 4, 255, 255, 255, 0, 3, 4, 192, 168, 1, 9, 0xFF}
copy(ret.ServerName[:], servername)
copy(ret.BootFilename[:], bootfile)
return ret
}