-
Notifications
You must be signed in to change notification settings - Fork 3
/
tuntuntun.go
65 lines (54 loc) · 1.23 KB
/
tuntuntun.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
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"log"
"net"
"os"
"strconv"
)
type UDPReadWrite interface {
WriteToUDP([]byte, *net.UDPAddr) (int, error)
ReadFromUDP([]byte) (int, *net.UDPAddr, error)
}
const TUNTUNTUN_CLIENT_PORT int = 55000
const TTT_CLIENT_IP string = "192.168.7.1"
const TTT_SERVER_IP string = "192.168.7.2"
const TUNTUNTUN_SERVER_PORT int = 71
const BUF_SIZE uint = 2048
var DEBUG_LEVEL int = 0
func main() {
if len(os.Args) < 2 {
fmt.Printf("server or client?")
return
}
// check if DEBUG is a valid number, and if so
// put it in the global DEBUG_LEVEL var
env_debug, err := strconv.ParseInt(os.Getenv("DEBUG_LEVEL"), 10, 32)
if err == nil && env_debug > 0 {
DEBUG_LEVEL = int(env_debug)
log.Printf("Setting debug level to %d", DEBUG_LEVEL)
}
if os.Args[1] == "client" {
if len(os.Args) < 3 {
fmt.Printf("Remote server addr?")
return
}
remote_addr, err := net.ResolveUDPAddr("udp", os.Args[2])
if err != nil {
log.Fatal(err)
}
client(remote_addr, os.Args[3:])
} else {
server()
}
}
func debug(lvl int, msg ...interface{}) {
if DEBUG_LEVEL >= lvl {
log.Print(msg...)
}
}
func debugf(lvl int, format string, stuff ...interface{}) {
if DEBUG_LEVEL >= lvl {
log.Printf(format, stuff...)
}
}