#ifndef NETLINKHANDLER_H #define NETLINKHANDLER_H #include #include #include #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