-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.go
74 lines (61 loc) · 1.14 KB
/
packet.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
const (
REQUEST uint8 = 1
RESPONSE uint8 = 2
)
type Data_t interface {
}
type Packet struct {
Port int
Dest uint32
Sender uint32
hopCount uint32
Data Data_t
}
func NewPacket(data Data_t, dest uint32, port int) (p Packet) {
p.Port = port
p.Dest = dest
p.Data = data
p.hopCount = 16
return
}
type RipEntry struct {
addressFamily uint16 // IGONER
routeTag uint16 // IGNORE
ipv4Address uint32
subnetMast uint32
nextHop uint32 // IGNORE
metric uint32
}
func NewRipEntry(ip, mask, metric uint32) (entry RipEntry) {
entry.addressFamily = 0x0000
entry.ipv4Address = ip
entry.subnetMast = mask
entry.metric = metric
return
}
type RipData struct {
command uint8
version uint8
zero uint16
entries []RipEntry
}
func NewRipData(command uint8) (packet RipData) {
packet.entries = make([]RipEntry, 0)
packet.zero = 0x0000
packet.command = command
return
}
func (packet *RipData) AddEntry(entry RipEntry) {
if len(packet.entries) >= 25 {
return
}
packet.entries = append(packet.entries, entry)
}
type Text struct {
text string
}
func NewText(msg string) (t Text) {
t.text = msg
return
}