Skip to content

Commit 2a4bc44

Browse files
committed
using syscall.RtMsg on Linux
1 parent b0b051f commit 2a4bc44

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

netroute_linux.go

+3-19
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ import (
2020
"github.com/google/gopacket/routing"
2121
)
2222

23-
// Pulled from http://man7.org/linux/man-pages/man7/rtnetlink.7.html
24-
// See the section on RTM_NEWROUTE, specifically 'struct rtmsg'.
25-
type routeInfoInMemory struct {
26-
Family byte
27-
DstLen byte
28-
SrcLen byte
29-
TOS byte
30-
31-
Table byte
32-
Protocol byte
33-
Scope byte
34-
Type byte
35-
36-
Flags uint32
37-
}
38-
3923
func New() (routing.Router, error) {
4024
rtr := &router{}
4125
rtr.ifaces = make(map[int]net.Interface)
@@ -54,7 +38,7 @@ loop:
5438
case syscall.NLMSG_DONE:
5539
break loop
5640
case syscall.RTM_NEWROUTE:
57-
rt := (*routeInfoInMemory)(unsafe.Pointer(&m.Data[0]))
41+
rt := (*syscall.RtMsg)(unsafe.Pointer(&m.Data[0]))
5842
routeInfo := rtInfo{}
5943
attrs, err := syscall.ParseNetlinkRouteAttr(&m)
6044
if err != nil {
@@ -68,12 +52,12 @@ loop:
6852
case syscall.RTA_DST:
6953
routeInfo.Dst = &net.IPNet{
7054
IP: net.IP(attr.Value),
71-
Mask: net.CIDRMask(int(rt.DstLen), len(attr.Value)*8),
55+
Mask: net.CIDRMask(int(rt.Dst_len), len(attr.Value)*8),
7256
}
7357
case syscall.RTA_SRC:
7458
routeInfo.Src = &net.IPNet{
7559
IP: net.IP(attr.Value),
76-
Mask: net.CIDRMask(int(rt.SrcLen), len(attr.Value)*8),
60+
Mask: net.CIDRMask(int(rt.Src_len), len(attr.Value)*8),
7761
}
7862
case syscall.RTA_GATEWAY:
7963
routeInfo.Gateway = net.IP(attr.Value)

0 commit comments

Comments
 (0)