From 310238937c8c14190818c505e4cb14a453bbdda7 Mon Sep 17 00:00:00 2001 From: Julian Harnath Date: Tue, 15 Mar 2016 21:40:29 +0100 Subject: [PATCH] Network Kit: add BNetworkDevice::Control * Allows to do an arbitrary ioctl on the network device * For ifreq and ieee80211req requests --- headers/os/net/NetworkDevice.h | 2 ++ src/kits/network/libnetapi/NetworkDevice.cpp | 36 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/headers/os/net/NetworkDevice.h b/headers/os/net/NetworkDevice.h index a99ae9ee82..a71d22c4b1 100644 --- a/headers/os/net/NetworkDevice.h +++ b/headers/os/net/NetworkDevice.h @@ -96,6 +96,8 @@ public: bool IsEthernet(); bool IsWireless(); + status_t Control(int option, void* request); + status_t Scan(bool wait = true, bool forceRescan = true); diff --git a/src/kits/network/libnetapi/NetworkDevice.cpp b/src/kits/network/libnetapi/NetworkDevice.cpp index 29fade4e40..73f67f003a 100644 --- a/src/kits/network/libnetapi/NetworkDevice.cpp +++ b/src/kits/network/libnetapi/NetworkDevice.cpp @@ -82,6 +82,24 @@ do_request(T& request, const char* name, int option) } +template<> status_t +do_request(ieee80211req& request, const char* name, int option) +{ + int socket = ::socket(AF_INET, SOCK_DGRAM, 0); + if (socket < 0) + return errno; + + FileDescriptorCloser closer(socket); + + strlcpy(((struct ieee80211req&)request).i_name, name, IFNAMSIZ); + + if (ioctl(socket, option, &request, sizeof(request)) < 0) + return errno; + + return B_OK; +} + + //! Read a 16 bit little endian value static uint16 read_le16(uint8*& data, int32& length) @@ -646,6 +664,24 @@ BNetworkDevice::IsWireless() } +status_t +BNetworkDevice::Control(int option, void* request) +{ + switch (IFM_TYPE(Media())) { + case IFM_ETHER: + return do_request(*reinterpret_cast(request), + &fName[0], option); + + case IFM_IEEE80211: + return do_request(*reinterpret_cast(request), + &fName[0], option); + + default: + return B_ERROR; + } +} + + status_t BNetworkDevice::Scan(bool wait, bool forceRescan) {