Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Netlink socket
Qt 6.11 is out! See what's new in the release blog

Netlink socket

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 3 Posters 6.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    f.vanalmetelevic.com
    wrote on last edited by
    #1

    Hi,

    I'm currently doing some experiments with a netlink socket to read a 1-wire iButton key. This works well when using native socket functions. However, it would be nice to have signal/slot functionality. Therefore, I would like to 'wrap' my native socket in a Qt object. Because it is a netlink socket, I think I have to use QAbstractSocket for that. First, I open a native socket and do a bind. When successful, I instantiate a QAbstractSocket :
    @ s = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);

    if (s == -1)
    {
    qDebug ("Socket problem");
    return;
    }

    l_local.nl_family = AF_NETLINK;
    l_local.nl_groups = 23;
    l_local.nl_pid = getpid();

    if (bind(s, (struct sockaddr *)&l_local, sizeof(struct sockaddr_nl)) == -1)
    {
    qDebug ("Bind problem");
    ::close(s);
    }

    QAbstractSocket *as = new QAbstractSocket(QAbstractSocket::UnknownSocketType, this);
    if (!as->setSocketDescriptor(s, QAbstractSocket::ConnectedState))
    {
    qDebug ("Failed to assign native socket to QAbstractSocket");
    }

    connect (as, SIGNAL(readyRead()), this, SLOT(axisDataAvailable()));@

    When I apply the key, the slot is never called. I also tested to read data from the QAbstractSocket, but with no success.
    Do I miss something ? Can I do it like this or are there better approaches to do this ?

    Filip

    1 Reply Last reply
    0
    • F Offline
      F Offline
      f.vanalmetelevic.com
      wrote on last edited by
      #2

      Problem solved.
      With QTcpSocket instead of QAbstractSocket, it looks like it's working fine.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yogesh
        wrote on last edited by
        #3

        Hi Filip, it would be great if you can post a small working program shows netlink+Qt working.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          f.vanalmetelevic.com
          wrote on last edited by
          #4

          As I'm very busy on my job (you know...deadlines...), I just post a snippet of my code :

          @
          int m_sock;
          struct sockaddr_nl l_local;
          QTcpSocket m_mySocket;
          /
          open netlink socket */
          m_sock = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);

          if (m_sock == -1)
          {
              qDebug ("Socket problem");
              return;
          }
          
          l_local.nl_family = AF_NETLINK;
          l_local.nl_groups = 23;
          l_local.nl_pid    = getpid();
          
          if (bind(m_sock, (struct sockaddr *)&l_local, sizeof(struct sockaddr_nl)) == -1)
          {
              qDebug ("Bind problem");
              close(m_sock);
              m_sock = 0;
              return;
          }
          
          m_mySocket = new QTcpSocket();
          if (!m_mySocket->setSocketDescriptor(m_sock))
          {
              qDebug ("Failed to assign native socket to QTcpSocket");
              close(m_sock);
              m_sock = 0;
              return;
          }
          
          connect (m_mySocket, SIGNAL(readyRead()), this, SLOT(netlinkDataAvailable()));@
          

          Hope this will help you...
          (Implemented this already some time ago, unfortunately not remembering all the details anymore right now.)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mohsen
            wrote on last edited by
            #5

            please add "[SOLVED]" to your thread title.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved