Results 1 to 4 of 4

Thread: MAC address of UDP packet's sender

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    75
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default MAC address of UDP packet's sender

    Hi,

    I have to write a program to "discover" (retrieving IP and MAC address) some network device. To this end I send difined UDP datagram to broadcast on a certain port. All device present on network will replies.
    I have the following class:
    Qt Code:
    1. #include <QDialog>
    2. #include <QUdpSocket>
    3.  
    4. namespace Ui {
    5. class Discovery;
    6. }
    7.  
    8. class Discovery : public QDialog
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. explicit Discovery(QWidget *parent = 0);
    14. ~Discovery();
    15.  
    16. private:
    17. Ui::Discovery *ui;
    18.  
    19. QUdpSocket sock;
    20.  
    21. public slots:
    22. void processPendingDatagrams(void);
    23. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "discovery.h"
    2. #include "ui_discovery.h"
    3.  
    4. #include <QUdpSocket>
    5.  
    6. Discovery::Discovery(QWidget *parent) :
    7. QDialog(parent),
    8. ui(new Ui::Discovery),
    9. sock(this)
    10. {
    11. ui->setupUi(this);
    12.  
    13. connect(&sock, SIGNAL(readyRead ()), this, SLOT (processPendingDatagrams ()));
    14.  
    15. static const char datagramma[] = {00, 01, 00, 0xF6 };
    16. dg.append(datagramma, sizeof(datagramma));
    17. sock.bind();
    18. sock.writeDatagram(dg,QHostAddress("255.255.255.255"), 0x77FE);
    19. }
    20.  
    21. Discovery::~Discovery()
    22. {
    23. delete ui;
    24. }
    25.  
    26. void Discovery::processPendingDatagrams(void)
    27. {
    28. char data[64];
    29. quint16 port;
    30.  
    31. sock.readDatagram(data, sizeof(data), &host, &port);
    32. qDebug("read from %s", host.toString().toAscii().constData());
    33. }
    To copy to clipboard, switch view to plain text mode 
    Doing this I can recover IP address
    Now I must recover the MAC address.

    How can I retrieve MAC address from packet received?

    thanks
    Last edited by mastupristi; 4th January 2011 at 14:55.

Similar Threads

  1. Packet handling advice with QTcpSocket?
    By zAAm in forum General Programming
    Replies: 1
    Last Post: 27th April 2010, 15:23
  2. Packet getting fragmented when sending over QTcpSocket
    By arturo182 in forum Qt Programming
    Replies: 14
    Last Post: 5th August 2009, 23:11
  3. tip on using QObject::sender()
    By drhex in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2008, 20:01
  4. how to send ICMP packet
    By eleanor in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2007, 14:23
  5. QtNetwork send ICMP Packet
    By SlowTree in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 20:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.