How to get MAC address from C
Posted: Sat Jun 04, 2016 10:02 pm
How can I get the MAC address on AmigaOS 4 from C?
Support Forum
https://forum.hyperion-entertainment.com/
https://forum.hyperion-entertainment.com/viewtopic.php?f=26&t=3460
Code: Select all
..
if ( ISocket->QueryInterfaceTags( Label_p, /* it can' t be longer than 15 chars */
IFQ_Address, &AddressBuffer,
/* IFQ_DestinationAddress, &DestinationAddressBuffer, */
IFQ_NetMask, &NetMaskBuffer,
IFQ_PrimaryDNSAddress, &PrimaryDNSAddressBuffer,
IFQ_SecondaryDNSAddress, &SecondaryDNSAddressBuffer,
IFQ_AddressBindType, &AddressBindType,
/* --- */
IFQ_HardwareType, &HardwareType,
IFQ_HardwareAddressSize, &HardwareAddressSize,
IFQ_HardwareAddress, HardwareAddressText,
IFQ_BPS, &BPS,
IFQ_State, &State,
/* --- */
IFQ_GetBytesIn, &GetBytesIn,
IFQ_GetBytesOut, &GetBytesOut,
TAG_DONE ) != 0 )
{
..
Code: Select all
IFQ_HardwareAddress (UBYTE *) - Retrieve the hardware address
associated with this interface; a maximum of 16 bytes
will be copied.
Code: Select all
UBYTE buf[17];
ULONG size;
ISocket->QueryInterfaceTags( interface,
IFQ_HardwareAddressSize, &size,
IFQ_HardwareAddress, buf,
TAG_DONE );
Code: Select all
UBYTE buf[128];
ULONG size;
ISocket->QueryInterfaceTags( interface,
IFQ_HardwareAddressSize, &size,
IFQ_HardwareAddress, buf,
TAG_DONE );
Code: Select all
IFQ_HardwareAddress (UBYTE *) - Retrieve the hardware address
associated with this interface; a maximum of 16 bytes
will be copied.
Yeah, that does indeed sound like a bug, then. Good to see Tony filed it already.softwarefailure wrote:Size is always set to 48, i.e. 6 bytes, which is right for a MAC address but as I've said, it seems to copy more than 17 bytes to the destination buffer because passing a buffer of 17 bytes causes a crash.
Right, that may be a (documentation?) bug too. I see it is noted in the bug report as well.The reason why I chose a 17 byte buffer was that the documentation states:
Code: Select all
IFQ_HardwareAddress (UBYTE *) - Retrieve the hardware address associated with this interface; a maximum of 16 bytes will be copied.
I just checked the code and found that QueryInterfaceTags() copies as many bytes as there are bits in the address. Hence, for an Ethernet MAC address 48 bytes are copied, the first six of which will contain valid data and the remaining 42 being junk that only serves to overwrite data that should not be harmed.nbache wrote:Yeah, that does indeed sound like a bug, then. Good to see Tony filed it already.softwarefailure wrote:Size is always set to 48, i.e. 6 bytes, which is right for a MAC address but as I've said, it seems to copy more than 17 bytes to the destination buffer because passing a buffer of 17 bytes causes a crash.
Oops .. he-he ... bytes, bits, what is difference ...Olaf Barthel wrote:I just checked the code and found that QueryInterfaceTags() copies as many bytes as there are bits in the address.
The difference between bits and bytes is not quite as pronounced in the network driver which fills in the data structure whose contents are what comes out as the address. The data structure member which contains the size of the address is called AddrFieldSize, which does not say anything about the unit of the length. The address field contains data which always was a multiple of 8 bits to begin with, which makes it the more puzzling why AddrFieldSize states the length in bits rather than bytes.nbache wrote:Oops .. he-he ... bytes, bits, what is difference ...Olaf Barthel wrote:I just checked the code and found that QueryInterfaceTags() copies as many bytes as there are bits in the address.
Best regards,
Niels