Create a "dummy" `struct sockaddr_dl` for devices.

Aperta
#858 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c
Ambito
networking

Direzione di ricerca

Start by reading the pcap_findalldevs.3pcap documentation cited in the issue and inspect how Npcap currently populates each device's address list. Compare the Windows sockaddr_dl option with a Npcap-specific MAC address function and account for older Npcap versions. Done means choosing and implementing a documented way to expose device MAC addresses while preserving the stated compatibility expectations.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Inside a project so far, I've had to use GetAdaptersAddresses to retrieve PhysicalAddress and PhysicalAddressLength as a dirty workaround to retrieve the MAC address of each device. As WinPcap/Npcap does not fill out Data/Linklayer information.

However, like I suspected, it turns out the linked list between IP_ADAPTER_ADDRESSES and pcap_if are not always in the same order. Which means I'll either have to lazily loop over and match devices, or build something to make a lookup.

On the Linux end, I can simply go through the pcap_if_t's addresses linked list, checking if addr->sa_family matches the value of AF_PACKET, and if so, it should (probably) be the MAC address.

Despite Windows seemingly tries everything to avoid anything related to the datalink layer. WinSock2 (ws2def.h to be specific) does seem to include some barebone structure for it. The only caveat is that it's only available on Windows 7 and up (_WIN32_WINNT < 0x0601) inside the header, but that shouldn't really be an issue since Npcap is meant to run on that.

MS seems to be using AF_LINK and sockaddr_dl as their standard for datalink MAC addresses. I'm saying seem to because I was unable to find any official documentation about it from MS Learn.

sockaddr_dl seems to be the best match though, since the man pages for pcap_findalldevs.3pcap says:

Note that the addresses in the list of addresses might be IPv4 addresses, IPv6 addresses, or some other type of addresses, [...] Whether other addresses are returned, and what types they might have is platform-dependent. Namely, link-layer addresses, such as Ethernet MAC addresses, have the value AF_PACKET (on Linux) or AF_LINK (on AIX, FreeBSD, Haiku, illumos, macOS, NetBSD, OpenBSD and QNX) or are not returned at all (on GNU/Hurd and Solaris).

[...] For link-layer addresses, it can be interpreted as if it pointed to a struct sockaddr_ll (for AF_PACKET, see packet(7)) or a struct sockaddr_dl (for AF_LINK).

And the fact that sockaddr_ll seems to be absent from WinSock2.

One big caveat is that, since this won't be available on older versions of Npcap, it means for backward compatibility I would have to keep a workaround, or warn that MAC addresses will be unavailable unless updated to a more recent version.

A more naive solution would be to make a Npcap exclusive function to return the MAC address (and length) of a device, or return a NULL pointer if no MAC address are available (I.E. loopback).

Also please let me know if I've missed anything from documentation about being able to retrieve MAC addresses via Npcap.

Lingua principale
C
Stelle
3.6k
Fork
601
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nmap/npcap

Tutte le issue di nmap/npcap

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.