-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
57 lines (44 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"net"
"os"
"github.com/vvelikodny/udprelay/server"
)
func printConnInfo(inputStreamPort int, outputStreamPort int) {
addrs, err := net.InterfaceAddrs()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Incoming stream can be send at the following addresses:")
printAddrPortInfo(addrs, inputStreamPort)
fmt.Println("Clients canconnect at the following addresses:")
printAddrPortInfo(addrs, outputStreamPort)
}
func printAddrPortInfo(addrs []net.Addr, port int) {
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
fmt.Printf("%v:%v\n", ipnet.IP, port)
}
}
}
}
func main() {
var help bool
flag.BoolVar(&help, "h", false, "Show help")
var incomingStreamPort int
var outgoingStreamPort int
flag.IntVar(&incomingStreamPort, "incoming-port", 6666, "Incoming stream port")
flag.IntVar(&outgoingStreamPort, "outgoing-port", 7777, "Outgoing stream port")
flag.Parse()
if help {
flag.Usage()
os.Exit(0)
}
printConnInfo(incomingStreamPort, outgoingStreamPort)
server := server.New()
server.Run(incomingStreamPort, outgoingStreamPort)
}