Standard c macros to indicate length of MAC address?

Go To StackoverFlow.com

1

Are there standard (or semi-standard, widely deployed) C macros for:

  1. The length of a MAC address formatted as 00:11:22:33:44:55, i.e. 17 bytes.
  2. The length of a raw MAC, i.e. 6 bytes.

I have seen these defined in proprietary header files at various times, but I see a lot of sample/tutorial code that otherwise uses "proper" macros and doesn't have anything for these -- the "6" is always hardcoded.

FWIW I'm on linux.

Obviously it's trivial to define my own, but I'd like to use a standard where possible.

2012-04-05 18:14
by bstpierre
Your question is ambiguous. Are you literally just looking for a macro defined to be 17 and another defined to be 6 - Perry 2012-04-05 18:17
@Perry: Yes, that's exactly what I'm looking for - bstpierre 2012-04-05 18:22
Or 18, if the macro happens to define the size of the buffer required, including the NUL terminator - bstpierre 2012-04-05 18:24


2

Some platforms define a "/usr/include/net/ethernet.h" which does something like:

#define ETHER_ADDR_LEN 6

And some platforms have similar defines in if_ether.h (located in various places, including netinet).

However, I'm unaware of anything that defines the length of a "string formatted" address, and I'm unaware of any standard that imposes these #defines, so they're likely not universally portable.

2012-04-05 18:29
by Perry
Ads