Example #1
0
func main() {
	if err := tap.CreateBridge(*br); err != nil {
		log.Fatal("Failed to create bridge", err)
	}
	t, err := tap.CreateTap(*tp)
	if err != nil {
		log.Fatal("Failed to create tap manager")
	}
	if err := t.AddToBridge(*br); err != nil {
		log.Fatal("Failed to add tap to bridge", err)
	}
	conn, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", *port))
	if err != nil {
		log.Fatal("Failed to dial server:", err)
	}
	defer conn.Close()

	for {
		c, err := conn.Accept()
		if err != nil {
			fmt.Printf("Failed to accept connection: %v\n", err)
			continue
		}
		if err := t.Relay(c); err != nil {
			log.Fatal("Failed to relay tap connection")
		}
		c.Close()
	}
	fmt.Printf("DONE\n")
}
Example #2
0
func main() {
	conn, err := net.Dial("tcp", *remote)
	if err != nil {
		log.Fatal("Failed to dial server:", err)
	}
	defer conn.Close()
	if err := tap.CreateBridge(*br); err != nil {
		log.Fatal("Failed to create bridge", err)
	}
	t, err := tap.CreateTap(*tp)
	if err != nil {
		log.Fatal("Failed to create tap manager")
	}
	if err := t.AddToBridge(*br); err != nil {
		log.Fatal("Failed to add tap to bridge", err)
	}
	if err := t.Relay(conn); err != nil {
		log.Fatal("Failed to relay tap connection")
	}
	fmt.Printf("DONE\n")
}