[TASK] Allow binding to arbitrary ports for respondd querying (#48)

Allow binding respondd to a specific port
This commit is contained in:
Geno 2017-03-21 00:53:02 +01:00 committed by Julian K
parent 4550887f69
commit c4d8fbd4df
5 changed files with 8 additions and 3 deletions

View File

@ -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)

View File

@ -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()
}

View File

@ -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.

View File

@ -11,6 +11,7 @@ type Config struct {
Respondd struct {
Enable bool
Interface string
Port int
CollectInterval Duration
}
Webserver struct {

View File

@ -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 {