forked from BellerophonMobile/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 42
/
DHCP4Config.go
56 lines (43 loc) · 1.14 KB
/
DHCP4Config.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
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus/v5"
)
const (
DHCP4ConfigInterface = NetworkManagerInterface + ".DHCP4Config"
// Properties
DHCP4ConfigPropertyOptions = DHCP4ConfigInterface + ".Options"
)
type DHCP4Options map[string]interface{}
type DHCP4Config interface {
// GetPropertyOptions GetOptions gets options map of configuration returned by the IPv4 DHCP server.
GetPropertyOptions() (DHCP4Options, error)
MarshalJSON() ([]byte, error)
}
func NewDHCP4Config(objectPath dbus.ObjectPath) (DHCP4Config, error) {
var c dhcp4Config
return &c, c.init(NetworkManagerInterface, objectPath)
}
type dhcp4Config struct {
dbusBase
}
func (c *dhcp4Config) GetPropertyOptions() (DHCP4Options, error) {
options, err := c.getMapStringVariantProperty(DHCP4ConfigPropertyOptions)
rv := make(DHCP4Options)
if err != nil {
return rv, err
}
for k, v := range options {
rv[k] = v.Value()
}
return rv, nil
}
func (c *dhcp4Config) MarshalJSON() ([]byte, error) {
Options, err := c.GetPropertyOptions()
if err != nil {
return nil, err
}
return json.Marshal(map[string]interface{}{
"Options": Options,
})
}