Exemple #1
0
func setupTun(tun *tuntap.Interface, addr *net.IPNet) error {
	if err := exec.Command("sudo", "ip", "-6", "addr", "add", "dev", tun.Name(), "local", addr.String()).Run(); err != nil {
		return err
	}
	if err := exec.Command("sudo", "ip", "link", "set", tun.Name(), "mtu", "1280", "up").Run(); err != nil {
		return err
	}
	return nil
}
Exemple #2
0
func runPacketCaptureLoop(iface *tuntap.Interface, tunio *TunIO) {
	for {
		packet, err := iface.ReadPacket()
		if err != nil {
			log.Fatalf("ReadPacket: %q", err)
		}
		if err := tunio.HandlePacket(iface, packet); err != nil {
			log.Fatalf("handlePacket: %q", err)
		}
	}
}