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

オープン
#858 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c
領域
networking

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C
スター
3.6k
フォーク
601
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nmap/npcap のほかの issue

nmap/npcap の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。