Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tun device in windows can't read data. #39

Open
zboya opened this issue Mar 7, 2018 · 14 comments
Open

tun device in windows can't read data. #39

zboya opened this issue Mar 7, 2018 · 14 comments

Comments

@zboya
Copy link

zboya commented Mar 7, 2018

package main

import (
	"log"

	"github.com/songgao/water"
)

func main() {
	ifce, err := water.New(water.Config{
		DeviceType: water.TUN,
		PlatformSpecificParams: water.PlatformSpecificParams{
			ComponentID: "tap0901",
			Network:     "192.168.1.10/24",
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	frame := make([]byte, 1<<12)
	for {
		n, err := ifce.Read(frame)
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("data: %v\n", frame[:n])

	}
}

after run this program, I ping 192.168.1.10, but program print nothing. Please help!

@zboya
Copy link
Author

zboya commented Mar 7, 2018

@lixin9311

1 similar comment
@JavinYang
Copy link

@lixin9311

@JavinYang
Copy link

JavinYang commented Mar 10, 2018

package main

import (
	"log"

	"github.com/songgao/packets/ethernet"
	"github.com/songgao/water"
)

func main() {
	ifce, err := water.New(water.Config{
		DeviceType: water.TAP,
		PlatformSpecificParams: water.PlatformSpecificParams{
			ComponentID: "tap0901",
			Network:     "10.8.0.6/30",
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	var frame ethernet.Frame

	for {
		frame.Resize(1500)
		n, err := ifce.Read([]byte(frame))
		if err != nil {
			log.Fatal(err)
		}

		frame = frame[:n]
		log.Printf("Dst: %s\n", frame.Destination())
		log.Printf("Src: %s\n", frame.Source())
		log.Printf("Ethertype: % x\n", frame.Ethertype())
		log.Printf("Payload %s\n", frame.Payload())
	}
}

go run main.go
netsh interface ip set address name="Ehternet 2" source=static addr=10.8.0.6 mask=255.255.255.252 gateway=none
ping 10.8.0.6

no printing. Orz

@lixin9311
Copy link
Collaborator

you should run the program as admin on UAC enabled Windows

@lixin9311
Copy link
Collaborator

And if you ping the address of the virtual nic on the local machine, the NT kernel will intercept and reply the ping, you can try to ping the gateway via the tun device

@JavinYang
Copy link

JavinYang commented Mar 11, 2018

how do i send all data to Virtual Ethernet Adapter?
when I send the command “route add 0.0.0.0 mask 0.0.0.0 10.8.0.6" in cmd tools and then visit the website .I can catch data from wireshark ,but can't read data from main program

@zboya
Copy link
Author

zboya commented Mar 12, 2018

@JavinYang when I using TAP device, it can read data from main program. using TUN device don't work.

@lixin9311
Copy link
Collaborator

set the address of the adapter to 192.168.1.10/24 and the gateway 192.168.1.1/24. you ping the gateway, then you can read the data.

@zboya
Copy link
Author

zboya commented Mar 12, 2018

@lixin9311 I had set the address of the adapter to 192.168.1.10/24 and the gateway 192.168.1.1/24. but using the TUN device still can't read data. using TAP device can read data.

@lixin9311
Copy link
Collaborator

it's working on my pc, I'll look into this later

@zboya
Copy link
Author

zboya commented Mar 12, 2018

I run this program in windows 10 in parallels desktop. maybe the vm has some different.

@zboya
Copy link
Author

zboya commented Mar 12, 2018

I run this program in real windows 10, and found the Nic can't set IP address to 192.168.1.10, it set the IP address to 169.254.x.x, this IP address is assigned by system, not my program.

@lixin9311
Copy link
Collaborator

there's some issue with netsh, you can try to set the ip by right clicking on the adapter icon.

@zboya
Copy link
Author

zboya commented Apr 20, 2018

@lixin9311 how did you set windows gateway?what cmd you used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants