2021-12-20 14:53:42 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-12-20 16:46:26 -05:00
|
|
|
fmt.Println("Usage: pndpd respond <interface>")
|
|
|
|
fmt.Println("Usage: pndpd proxy <interface1> <interface2>")
|
|
|
|
|
2021-12-20 14:53:42 -05:00
|
|
|
if len(os.Args) <= 1 {
|
2021-12-20 16:46:26 -05:00
|
|
|
fmt.Println("Specify command")
|
2021-12-20 14:53:42 -05:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2021-12-20 16:46:26 -05:00
|
|
|
if os.Args[1] == "respond" {
|
|
|
|
simpleRespond(os.Args[2])
|
|
|
|
}
|
|
|
|
if os.Args[1] == "proxy" {
|
|
|
|
proxy(os.Args[2], os.Args[3])
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func simpleRespond(iface string) {
|
2021-12-20 14:53:42 -05:00
|
|
|
requests := make(chan *NDRequest, 100)
|
|
|
|
defer close(requests)
|
2021-12-20 16:46:26 -05:00
|
|
|
go respond(iface, requests, NDP_ADV)
|
|
|
|
go listen(iface, requests, NDP_SOL)
|
|
|
|
select {}
|
|
|
|
//TODO os.signal
|
|
|
|
}
|
|
|
|
|
|
|
|
func proxy(iface1, iface2 string) {
|
|
|
|
req_iface1_sol_iface2 := make(chan *NDRequest, 100)
|
|
|
|
defer close(req_iface1_sol_iface2)
|
|
|
|
go listen(iface1, req_iface1_sol_iface2, NDP_SOL)
|
|
|
|
go respond(iface2, req_iface1_sol_iface2, NDP_SOL)
|
|
|
|
|
|
|
|
req_iface2_sol_iface1 := make(chan *NDRequest, 100)
|
|
|
|
defer close(req_iface2_sol_iface1)
|
|
|
|
go listen(iface2, req_iface2_sol_iface1, NDP_SOL)
|
|
|
|
go respond(iface1, req_iface2_sol_iface1, NDP_SOL)
|
|
|
|
|
|
|
|
req_iface1_adv_iface2 := make(chan *NDRequest, 100)
|
|
|
|
defer close(req_iface1_adv_iface2)
|
|
|
|
go listen(iface1, req_iface1_adv_iface2, NDP_ADV)
|
|
|
|
go respond(iface2, req_iface1_adv_iface2, NDP_ADV)
|
|
|
|
|
|
|
|
req_iface2_adv_iface1 := make(chan *NDRequest, 100)
|
|
|
|
defer close(req_iface2_adv_iface1)
|
|
|
|
go listen(iface2, req_iface2_adv_iface1, NDP_ADV)
|
|
|
|
go respond(iface1, req_iface2_adv_iface1, NDP_ADV)
|
|
|
|
|
|
|
|
select {}
|
|
|
|
// TODO os.signal
|
2021-12-20 14:53:42 -05:00
|
|
|
|
|
|
|
}
|