diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-09-24 21:35:25 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-09-24 21:35:25 +0200 |
commit | eefa47b0f91416a3435102f89339b3ec4fcdd672 (patch) | |
tree | 704e1f38f5e0cf8bba15607c16f2e2d1c23baedb /src/conn.go | |
parent | c545d63bb93b8192dfdc7037952fc2661dd1222b (diff) |
Begin work on source address caching (linux)
Diffstat (limited to 'src/conn.go')
-rw-r--r-- | src/conn.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/conn.go b/src/conn.go index 7b35829..41a5b85 100644 --- a/src/conn.go +++ b/src/conn.go @@ -1,9 +1,31 @@ package main import ( + "errors" "net" ) +func parseEndpoint(s string) (*net.UDPAddr, error) { + + // ensure that the host is an IP address + + host, _, err := net.SplitHostPort(s) + if err != nil { + return nil, err + } + if ip := net.ParseIP(host); ip == nil { + return nil, errors.New("Failed to parse IP address: " + host) + } + + // parse address and port + + addr, err := net.ResolveUDPAddr("udp", s) + if err != nil { + return nil, err + } + return addr, err +} + func updateUDPConn(device *Device) error { netc := &device.net netc.mutex.Lock() |