mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-20 00:45:09 +03:00
darwin: Detects IP Ver. for NULL Header on Write
Adds the ability for both IPv4 and IPv6 to be written to the TUN device.
This commit is contained in:
parent
66c5b2f72c
commit
da7e7e0a3e
1 changed files with 10 additions and 1 deletions
|
@ -159,7 +159,16 @@ func (t *tunReadCloser) Write(from []byte) (int, error) {
|
||||||
}
|
}
|
||||||
t.wBuf = t.wBuf[:len(from)+4]
|
t.wBuf = t.wBuf[:len(from)+4]
|
||||||
|
|
||||||
t.wBuf[3] = 2 // Family: IP (2)
|
// Determine the IP Family for the NULL L2 Header
|
||||||
|
ipVer := from[0] >> 4
|
||||||
|
if ipVer == 4 {
|
||||||
|
t.wBuf[3] = syscall.AF_INET
|
||||||
|
} else if ipVer == 6 {
|
||||||
|
t.wBuf[3] = syscall.AF_INET6
|
||||||
|
} else {
|
||||||
|
return 0, errors.New("Unable to determine IP version from packet.")
|
||||||
|
}
|
||||||
|
|
||||||
copy(t.wBuf[4:], from)
|
copy(t.wBuf[4:], from)
|
||||||
|
|
||||||
n, err := t.f.Write(t.wBuf)
|
n, err := t.f.Write(t.wBuf)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue