-
Notifications
You must be signed in to change notification settings - Fork 1
/
clients.go
45 lines (37 loc) · 948 Bytes
/
clients.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
package godhcp
import (
"fmt"
"net"
"errors"
)
type Client struct {
State string
HType HType
CHAddr net.HardwareAddr
Hostname string
Options OptionMap
}
func (c *Client) ProcessMessage(m *Message) (*Message, error) {
//FIXME: Don't just overwrite our options, let's keep track of what we had before
// Options need some flag for which ones will be sent to server
c.Options = m.Options
switch m.Type {
case DHCPDISCOVER:
if c.State == "NEW" {
c.State = "DHCPDISCOVER"
}
resp := c.PrepareOffer()
return resp, nil
}
return nil, errors.New("Unknown Message Type Received")
}
func (c *Client) PrepareOffer() (*Message) {
r := new(Message)
r.Op = BOOTREPLY
return r
}
func (c *Client) String() string {
s := ""
s += fmt.Sprintf("[%v] %v - %v", c.CHAddr, c.Hostname, c.State)
return s
}