PcapPlusPlus  21.05
pcpp::LinuxNicInformationSocket Class Reference

#include <LinuxNicInformationSocket.h>

Public Types

typedef int LinuxSocket
 
typedef unsigned long IoctlType
 

Public Member Functions

 LinuxNicInformationSocket ()
 
 ~LinuxNicInformationSocket ()
 
bool makeRequest (const char *nicName, const IoctlType ioctlType, ifreq *request)
 Makes request to socket. Firstly tries to open socket if it is not opened. Then makes an ioctl(2) request to handled socket with provided request structure. See: netdevice(7) for description of possible values of ioctlType and content of request. More...
 

Detailed Description

Simple wrapper over Linux socket for making the information requests about NICs or making some changes in NICs setup. All possible requests are described in netdevice(7). The instance of this class handels underlying socket during its lifetime and takes an appropriate actions to close socket on destruction. The user must call LinuxNicInformationSocket::makeRequest method with known ioctl type and properly filled ifreq structure for this ioctl type. Filling of ifr_name may be omitted as it will be done automatically from provided NIC name.

Note
Usage of this class requires the inclusion of <sys/ioctl.h> and <net/if.h> Linux headers

Member Typedef Documentation

◆ IoctlType

Simple type rename for convenience

◆ LinuxSocket

Simple type rename for convenience

Constructor & Destructor Documentation

◆ LinuxNicInformationSocket()

pcpp::LinuxNicInformationSocket::LinuxNicInformationSocket ( )

Tries to open handled socket on construction. If fails prints the debug message

◆ ~LinuxNicInformationSocket()

pcpp::LinuxNicInformationSocket::~LinuxNicInformationSocket ( )

Closes handled socket on destruction. If no socket was opened prints the debug message

Member Function Documentation

◆ makeRequest()

bool pcpp::LinuxNicInformationSocket::makeRequest ( const char *  nicName,
const IoctlType  ioctlType,
ifreq *  request 
)

Makes request to socket. Firstly tries to open socket if it is not opened. Then makes an ioctl(2) request to handled socket with provided request structure. See: netdevice(7) for description of possible values of ioctlType and content of request.

Note
User have no need to fill ifr_name field of request. It will be filled automatically from provided nicName argument.
Parameters
[in]nicNameName of internet controller as displayed by Linux
[in]ioctlTypeValue of ioctl to make
[in,out]requestPointer to ifreq structure that contains some information or will be used for obtaining the information (depends on ioctlType)
Returns
false if request was not made or socket can't be opened otherwise true
Warning
For some types of requests to succeed You need to be a root or have the CAP_NET_ADMIN capability.