How to get device maC address?

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Dmitry_K
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Nov 04, 2021 3:33 pm

How to get device maC address?

Post by Dmitry_K »

Hello.

I use for exchange wxDatagramSocket.

wxIPV4address BroadCastAddress;
BroadCastAddress.Hostname(_("XXXXXXXXXXX"));
BroadCastAddress.AnyAddress();
BroadCastAddress.Service(48660);

// Create the socket
M_UDP_socket = new wxDatagramSocket(BroadCastAddress, wxSOCKET_WAITALL_WRITE);

wxIPV4address raddr;
raddr.Hostname("192.168.1.5");
raddr.Service(5001);

....
.....
.....

my_size = M_UDP_socket->SendTo(raddr, &My_data_buf, sizeof(My_data_buf)).LastCount();

Send data is successful and receiver is successful is recive data. The is no problem.

The question is, when I receive data back from the sender, how can I see the MAC address of the device that answered me?

Regards, Dmitry.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to get device maC address?

Post by ONEEYEMAN »

Hi,
Which protocol you are using - TCP or UDP?

You will need to parse the packet header and see the information you need. Unless you have control over the sender...

Thank you.
User avatar
T-Rex
Moderator
Moderator
Posts: 1248
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: How to get device maC address?

Post by T-Rex »

wxDatagramSocket is a derived class from wxSocketBase.
wxSocketBase has a SetNotify() method that enables the subscription for the relevant events
When you get the incoming data, your event handler should be triggered.
In the event handler you will get the wxSocketEvent.
The wxSocketEvent object has a GetSocket() method that returns the relevant wxSocketBase pointer.
wxSocketBase has a GetLocal() and GetPeer() method. I assume that GetPeer() should return the address that has sent the message.
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to get device maC address?

Post by doublemax »

T-Rex wrote: Tue Feb 08, 2022 3:11 pm GetPeer() should return the address that has sent the message.
OP is looking for the MAC address not IP.

Maybe try Wireshark and check if the information is available at all.
( I have no experience with Wireshark and can't help with its use)
Use the source, Luke!
Post Reply