summaryrefslogtreecommitdiffhomepage
path: root/src/conn.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/conn.go')
-rw-r--r--src/conn.go22
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()