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:
Code:
#include <QDialog>
#include <QUdpSocket>
namespace Ui {
class Discovery;
}
{
Q_OBJECT
public:
explicit Discovery
(QWidget *parent
= 0);
~Discovery();
private:
Ui::Discovery *ui;
public slots:
void processPendingDatagrams(void);
};
Code:
#include "discovery.h"
#include "ui_discovery.h"
#include <QUdpSocket>
Discovery
::Discovery(QWidget *parent
) : ui(new Ui::Discovery),
sock(this)
{
ui->setupUi(this);
connect(&sock, SIGNAL(readyRead ()), this, SLOT (processPendingDatagrams ()));
static const char datagramma[] = {00, 01, 00, 0xF6 };
dg.append(datagramma, sizeof(datagramma));
sock.bind();
sock.
writeDatagram(dg,
QHostAddress("255.255.255.255"), 0x77FE
);
}
Discovery::~Discovery()
{
delete ui;
}
void Discovery::processPendingDatagrams(void)
{
char data[64];
quint16 port;
sock.readDatagram(data, sizeof(data), &host, &port);
qDebug("read from %s", host.toString().toAscii().constData());
}
Doing this I can recover IP address
Now I must recover the MAC address.
How can I retrieve MAC address from packet received?
thanks
Re: MAC address of UDP packet's sender
You can't. The UDP packet does not contain the MAC address associated with its transmission unless the sender deliberately includes it in the UDP data. If you are also writing the sender then this is a trivial exercise.
Re: MAC address of UDP packet's sender
Also please, just for the sake of us all, apply a network mask to the broadcast address before you start emitting such datagrams. One badly configured router and your packet leaks out of your LAN segment.
Re: MAC address of UDP packet's sender
@mastupristi: i'm getting mac addresses with arp sender/receiver... Look around for that..