load default values from config

This commit is contained in:
Martin/Geno 2019-05-03 17:48:17 +02:00 committed by genofire
parent b6072a3b48
commit 95ae82fa06
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
1 changed files with 14 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/bdlm/log" "github.com/bdlm/log"
"github.com/FreifunkBremen/yanic/data" "github.com/FreifunkBremen/yanic/data"
"github.com/FreifunkBremen/yanic/respond"
) )
func (d *Daemon) Start() { func (d *Daemon) Start() {
@ -21,7 +22,17 @@ func (d *Daemon) Start() {
for _, listen := range d.Listen { for _, listen := range d.Listen {
var socket *net.UDPConn var socket *net.UDPConn
var err error var err error
addr := net.ParseIP(listen.Address) addrString := listen.Address
if addrString == "" {
addrString = respond.MulticastAddressDefault
}
port := listen.Port
if port == 0 {
port = respond.PortDefault
} else if port < 0 {
port = 0
}
addr := net.ParseIP(addrString)
if addr.IsMulticast() { if addr.IsMulticast() {
var iface *net.Interface var iface *net.Interface
@ -33,14 +44,14 @@ func (d *Daemon) Start() {
} }
if socket, err = net.ListenMulticastUDP("udp6", iface, &net.UDPAddr{ if socket, err = net.ListenMulticastUDP("udp6", iface, &net.UDPAddr{
IP: addr, IP: addr,
Port: listen.Port, Port: port,
}); err != nil { }); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} else { } else {
if socket, err = net.ListenUDP("udp6", &net.UDPAddr{ if socket, err = net.ListenUDP("udp6", &net.UDPAddr{
IP: addr, IP: addr,
Port: listen.Port, Port: port,
}); err != nil { }); err != nil {
log.Fatal(err) log.Fatal(err)
} }