1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:28:11 +00:00

Kernel/Net: Get the correct interface type in SIOCGIFHWADDR ioctl

When calling ioctl on a socket with SIOCGIFHWADDR, return the correct
physical interface type. This value was previously hardcoded to
ARPHRD_ETHER (Ethernet), and now can also return ARPHRD_LOOPBACK for the
loopback adapter.
This commit is contained in:
Arda Cinar 2023-01-13 11:46:31 +03:00 committed by Jelle Raaijmakers
parent 6f9b84a64a
commit 037744e62a
5 changed files with 19 additions and 1 deletions

View file

@ -740,7 +740,16 @@ ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspac
case SIOCGIFHWADDR: {
auto mac_address = adapter->mac_address();
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; // FIXME: Query the underlying network interface for it's type
switch (adapter->adapter_type()) {
case NetworkAdapter::Type::Loopback:
ifr.ifr_hwaddr.sa_family = ARPHRD_LOOPBACK;
break;
case NetworkAdapter::Type::Ethernet:
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
break;
default:
VERIFY_NOT_REACHED();
}
mac_address.copy_to(Bytes { ifr.ifr_hwaddr.sa_data, sizeof(ifr.ifr_hwaddr.sa_data) });
return copy_to_user(user_ifr, &ifr);
}