36 lines
747 B
C++
36 lines
747 B
C++
#ifndef NETLINKHANDLER_H
|
|
#define NETLINKHANDLER_H
|
|
|
|
#include <QObject>
|
|
#include <QSocketNotifier>
|
|
#include <QByteArray>
|
|
#include "log.h"
|
|
|
|
class NetlinkHandler : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit NetlinkHandler(QObject *parent = nullptr);
|
|
~NetlinkHandler();
|
|
|
|
bool init(int protocol = 16); // 默认为 NETLINK_USERSOCK
|
|
bool sendMessage(const QByteArray &msg);
|
|
int socketFd() const { return m_sock; }
|
|
|
|
signals:
|
|
void messageReceived(const QByteArray &msg);
|
|
void errorOccurred(const QString &err);
|
|
|
|
private slots:
|
|
void onSocketReadyRead();
|
|
|
|
private:
|
|
int m_sock = -1;
|
|
QSocketNotifier *m_notifier = nullptr;
|
|
|
|
bool createSocket(int protocol);
|
|
void closeSocket();
|
|
};
|
|
|
|
#endif // NETLINKHANDLER_H
|