-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (62 loc) · 1.4 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"encoding/base64"
"flag"
"log"
"github.com/songgao/water"
"os"
"bufio"
"strings"
"fmt"
)
func createInterface(id int) *water.Interface {
config := water.Config{
DeviceType: water.TUN,
}
config.Name = fmt.Sprint("IPoDC", id)
// setup the tun interface
ifce, err := water.New(config)
if err != nil {
if (strings.Contains(fmt.Sprint(err), "device or resource busy")){
log.Printf(fmt.Sprint(err))
return createInterface(id+1)
} else {
log.Fatal(err)
os.Exit(3)
}
}
return ifce
}
func main() {
flag.Parse()
ifce := createInterface(0)
// just log the interface name
log.Printf("if: %s\n", ifce.Name())
go reader(ifce)
listener(ifce)
}
func reader(ifce *water.Interface){
reader := bufio.NewReader(os.Stdin)
for {
text, _ := reader.ReadString('\n')
cleaned := strings.TrimSuffix(text, "\n")
packet, err := base64.StdEncoding.DecodeString(cleaned)
log.Printf("Packet recv: % x\n", packet)
_, err = ifce.Write(packet)
if err != nil {
log.Println("failed to write to if")
}
}
}
func listener(ifce *water.Interface){
log.Printf("LISTENING")
// listen for packets to send to irc
packet := make([]byte, 2000)
for {
n, err := ifce.Read(packet)
if err != nil {
log.Fatal(err)
}
log.Printf("PACKET %s", base64.StdEncoding.EncodeToString(packet[:n]))
}
}