scroot / gopacket

Automatically exported from code.google.com/p/gopacket
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

pcap.FindAllDevs() does not have valid netmask #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run following code:

package main

import (
    "fmt"
    "code.google.com/p/gopacket/pcap"
)

func main() {
    if ifs, err := pcap.FindAllDevs(); err != nil {
        fmt.Print(err)
    } else {
        for _,nif := range ifs {
            fmt.Println(nif.Name)
            for _,net := range nif.Addresses {
                fmt.Println(">", net.IP, "/", net.Netmask)
            }
        }
    }
}

What is the expected output? What do you see instead?

root@ubuntu:~# go run e.go
nflog
nfqueue
p5p1
  192.168.1.204 / c0a801cc
  fe80::ea40:f2ff:fe09:652a / fe80000000000000ea40f2fffe09652a
any
lo
  127.0.0.1 / 7f000001
  ::1 / 00000000000000000000000000000001

What version of the product are you using? On what operating system?

root@ubuntu:~# go version
go version go1.2.1 linux/amd64
root@ubuntu:~# go get code.google.com/p/gopacket

Please provide any additional information below.

---------
diff --git a/pcap/pcap.go b/pcap/pcap.go
index 358c04e..1ecec84 100644
--- a/pcap/pcap.go
+++ b/pcap/pcap.go
@@ -384,7 +384,7 @@ func findalladdresses(addresses *_Ctype_struct_pcap_addr) 
(retval []InterfaceAdd
                if a.IP, err = sockaddr_to_IP((*syscall.RawSockaddr)(unsafe.Pointer(curaddr.addr))); err != nil {
                        continue
                }
-               if a.Netmask, err = 
sockaddr_to_IP((*syscall.RawSockaddr)(unsafe.Pointer(curaddr.addr))); err != 
nil {
+               if a.Netmask, err = 
sockaddr_to_IP((*syscall.RawSockaddr)(unsafe.Pointer(curaddr.netmask))); err != 
nil {
                        continue
                }
                retval = append(retval, a)

---------

This fix cause another issue with WinPcap(WpdPack_4_1_2.zip), that IPv6 netmask 
returned from the C library is not a valid. For that reason, sockaddr_to_IP 
drops IPv6 address and we only see IPv4 addrs.

Original issue reported on code.google.com by Hiroaki.Kawai@gmail.com on 28 Jun 2014 at 1:50

GoogleCodeExporter commented 9 years ago
I've rolled out your fix for netmask, can you provide more details on winpcap 
IPv6 error?

Original comment by gconnell@google.com on 28 Jun 2014 at 3:47

GoogleCodeExporter commented 9 years ago
WinPcap returns all zero netmask and broadcast for IPv6 address for 
_Ctype_struct_pcap_addr(*1), and sockaddr_to_IP() call for IPv6 netmask returns 
error.
The findalladdresses loop continues without appending IPv6 because of netmask 
error.

*) The following code PacketAddIP6Addresses in winpcap/packetNtx/Dll/AdInfo.c 
in WpcapSrc_4_1_3.zip

                        memcpy(&pItem->Addr.IPAddress, Addr, AddrLen);
                        memset(&pItem->Addr.SubnetMask, 0, sizeof(struct sockaddr_storage));
                        memset(&pItem->Addr.Broadcast, 0, sizeof(struct sockaddr_storage));

Original comment by Hiroaki.Kawai@gmail.com on 28 Jun 2014 at 11:24

GoogleCodeExporter commented 9 years ago
https://code.google.com/p/gopacket/source/detail?r=679b12ca0aa44896666432e4123dc
50342f9dc21

Original comment by gconnell@google.com on 1 Jul 2014 at 4:40