From c4d8fbd4df9ac930ed898c40044e59465cc1509e Mon Sep 17 00:00:00 2001 From: Geno Date: Tue, 21 Mar 2017 00:53:02 +0100 Subject: [PATCH] [TASK] Allow binding to arbitrary ports for respondd querying (#48) Allow binding respondd to a specific port --- cmd/yanic-query/main.go | 2 +- cmd/yanic/main.go | 2 +- config_example.toml | 3 +++ models/config.go | 1 + respond/collector.go | 3 ++- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/yanic-query/main.go b/cmd/yanic-query/main.go index 516a262..2b8969c 100644 --- a/cmd/yanic-query/main.go +++ b/cmd/yanic-query/main.go @@ -19,7 +19,7 @@ func main() { nodes := models.NewNodes(&models.Config{}) - collector := respond.NewCollector(nil, nodes, iface) + collector := respond.NewCollector(nil, nodes, iface, 0) collector.SendPacket(net.ParseIP(dstAddress)) time.Sleep(time.Second) diff --git a/cmd/yanic/main.go b/cmd/yanic/main.go index 251a4b7..552fb26 100644 --- a/cmd/yanic/main.go +++ b/cmd/yanic/main.go @@ -50,7 +50,7 @@ func main() { nodes.Start() if config.Respondd.Enable { - collector = respond.NewCollector(db, nodes, config.Respondd.Interface) + collector = respond.NewCollector(db, nodes, config.Respondd.Interface, config.Respondd.Port) collector.Start(config.Respondd.CollectInterval.Duration) defer collector.Close() } diff --git a/config_example.toml b/config_example.toml index f542814..bcdb4cb 100644 --- a/config_example.toml +++ b/config_example.toml @@ -5,6 +5,9 @@ enable = true collect_interval = "1m" # on which interface interface = "eth0" +# define a port to listen +# (no or 0 would choose at port at his own) +#port = 10001 # A little build-in webserver, which statically serves a directory. diff --git a/models/config.go b/models/config.go index 3793a76..45aac0f 100644 --- a/models/config.go +++ b/models/config.go @@ -11,6 +11,7 @@ type Config struct { Respondd struct { Enable bool Interface string + Port int CollectInterval Duration } Webserver struct { diff --git a/respond/collector.go b/respond/collector.go index f13f6fb..c9489d1 100644 --- a/respond/collector.go +++ b/respond/collector.go @@ -27,7 +27,7 @@ type Collector struct { } // NewCollector creates a Collector struct -func NewCollector(db *database.DB, nodes *models.Nodes, iface string) *Collector { +func NewCollector(db *database.DB, nodes *models.Nodes, iface string, port int) *Collector { linkLocalAddr, err := getLinkLocalAddr(iface) if err != nil { log.Panic(err) @@ -36,6 +36,7 @@ func NewCollector(db *database.DB, nodes *models.Nodes, iface string) *Collector // Open socket conn, err := net.ListenUDP("udp", &net.UDPAddr{ IP: linkLocalAddr, + Port: port, Zone: iface, }) if err != nil {