How to convert Mac string to a Byte address in C. Could you tell me how to convert the mac string to binary bytes. – user1727270 Oct 11 '12 at 0:41.
8 Apr 2009CPOL
The code snippet converts MAC Address String Format into Bytes
Introduction
inet_addr
and inet_ntoa
are already available for IP address processing. Here, I put the same functionalities for MAC address.This code snippet converts MAC address string into bytes array and bytes array into MAC address' string.
Background
I searched the internet but I could not find such a function so I publish it here for every one.
Using the Code
The code is self explanatory.
History
- 8th April, 2009: Initial post
Bluetooth Device Address (or BD_ADDR) is a unique 48-bit identifier assigned to each Bluetooth device by the manufacturer.
Bluetooth Address is usually displayed as 6 bytes written in hexadecimal and separated by colons (example - 00:11:22:33:FF:EE).
The upper half of a Bluetooth Address (most-significant 24 bits) is so called Organizationally Unique Identifier (OUI). It can be used to determine the manufacturer of a device (Bluetooth MAC Address Lookup form). OUI prefixes are assigned by the Institute of Electrical and Electronics Engineers (IEEE).
Additionaly to identification, Bluetooth Device Address is used to determine the frequency hopping pattern in radio communication between Bluetooth devices.
Bluetooth Address Structure
Bluetooth Address consists of three parts: NAP, UAP and LAP.
NAP
Non-significant Address Part (2 bytes). Contains first 16 bits of the OUI. The NAP value is used in Frequency Hopping Synchronization frames.
UAP
Upper Address Part (1 byte). Contains remaining 8 bits of the OUI. The UAP value is used for seeding in various Bluetooth specification algorithms.
LAP
Lower Address Part (3 bytes). This portion of Bluetooth Address is allocated by the vendor of device. The LAP value uniquely identifies a Bluetooth device as part of the Access Code in every transmitted frame.
The LAP and the UAP make the significant address part (SAP) of the Bluetooth Address.