fix: Fix connection interface binding, JSON lease DB

This commit is contained in:
Adrian Rumpold
2024-01-09 12:23:41 +01:00
parent cb8b6c03b6
commit ac7185bfb5
8 changed files with 277 additions and 75 deletions

46
pkg/types/json.go Normal file
View File

@@ -0,0 +1,46 @@
package types
import (
"fmt"
"net"
"strconv"
util "github.com/adrianokf/go-dhcp/pkg/util"
)
func (txid *TxId) UnmarshalText(text []byte) (err error) {
result, err := strconv.ParseUint(string(text), 16, 32)
if err != nil {
return err
}
copy(txid[:], util.U32ToByte(uint32(result)))
return nil
}
func (id TxId) MarshalText() ([]byte, error) {
return []byte(fmt.Sprintf("%x", id)), nil
}
func (addr *Ipv4Addr) UnmarshalText(text []byte) (err error) {
ip := net.ParseIP(string(text))
fmt.Println(ip)
if ip == nil {
return fmt.Errorf("could not parse IP address: '%s'", text)
}
*addr = Ipv4AddrFromNetIP(ip)
return nil
}
func (addr Ipv4Addr) MarshalText() ([]byte, error) {
return addr.ToNetIPv4().MarshalText()
}
func (addr HwAddr) MarshalText() ([]byte, error) {
return []byte(addr.String()), nil
}
func (addr *HwAddr) UnmarshalText(text []byte) (err error) {
*addr, err = HwAddrFromString(string(text))
return err
}