This repository has been archived on 2025-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
upper_netlink/netlinkhandler.h
2025-06-07 23:36:39 +08:00

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