[TASK] Allow binding to arbitrary ports for respondd querying (#48)
Allow binding respondd to a specific port
This commit is contained in:
parent
4550887f69
commit
c4d8fbd4df
|
@ -19,7 +19,7 @@ func main() {
|
||||||
|
|
||||||
nodes := models.NewNodes(&models.Config{})
|
nodes := models.NewNodes(&models.Config{})
|
||||||
|
|
||||||
collector := respond.NewCollector(nil, nodes, iface)
|
collector := respond.NewCollector(nil, nodes, iface, 0)
|
||||||
collector.SendPacket(net.ParseIP(dstAddress))
|
collector.SendPacket(net.ParseIP(dstAddress))
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
|
@ -50,7 +50,7 @@ func main() {
|
||||||
nodes.Start()
|
nodes.Start()
|
||||||
|
|
||||||
if config.Respondd.Enable {
|
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)
|
collector.Start(config.Respondd.CollectInterval.Duration)
|
||||||
defer collector.Close()
|
defer collector.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ enable = true
|
||||||
collect_interval = "1m"
|
collect_interval = "1m"
|
||||||
# on which interface
|
# on which interface
|
||||||
interface = "eth0"
|
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.
|
# A little build-in webserver, which statically serves a directory.
|
||||||
|
|
|
@ -11,6 +11,7 @@ type Config struct {
|
||||||
Respondd struct {
|
Respondd struct {
|
||||||
Enable bool
|
Enable bool
|
||||||
Interface string
|
Interface string
|
||||||
|
Port int
|
||||||
CollectInterval Duration
|
CollectInterval Duration
|
||||||
}
|
}
|
||||||
Webserver struct {
|
Webserver struct {
|
||||||
|
|
|
@ -27,7 +27,7 @@ type Collector struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCollector creates a 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)
|
linkLocalAddr, err := getLinkLocalAddr(iface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
|
@ -36,6 +36,7 @@ func NewCollector(db *database.DB, nodes *models.Nodes, iface string) *Collector
|
||||||
// Open socket
|
// Open socket
|
||||||
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||||
IP: linkLocalAddr,
|
IP: linkLocalAddr,
|
||||||
|
Port: port,
|
||||||
Zone: iface,
|
Zone: iface,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue