| 1 |
/* |
/* |
| 2 |
mac2eui64.c |
mac2eui64.c |
| 3 |
|
|
| 4 |
Conversion from the IEEE 802 MAC format to the IEEE EUI-64 format. |
Conversion from the IEEE 802 MAC format to the (modified) IEEE EUI-64 format. |
| 5 |
Displays values suitable for use as a 64 bit interface ID in A6 RRs. |
Displays values suitable for use as a 64 bit interface ID in AAAA and A6 RRs. |
| 6 |
Also displayed are labels suitable for use with PTR RRs in the |
Also displays labels suitable for use with PTR RRs in the reverse zone |
| 7 |
reverse zone ip6.arpa. |
ip6.arpa. |
| 8 |
|
|
| 9 |
Updated in 2015 to conform to ISO C 2011. |
Updated in 2015 to conform to ISO C 2011. |
| 10 |
|
|
| 101 |
{ |
{ |
| 102 |
printf("%s version 1.0\n\n" |
printf("%s version 1.0\n\n" |
| 103 |
|
|
| 104 |
"Conversion from the IEEE 802 MAC format to the IEEE EUI-64 format.\n" |
"Conversion from the IEEE 802 MAC format to the (modified) IEEE EUI-64 format.\n" |
| 105 |
"Displays values suitable for use as a 64 bit interface ID in A6 RRs.\n" |
"Displays values suitable for use as a 64 bit interface ID in AAAA and A6 RRs.\n" |
| 106 |
"Also displayed are labels suitable for use with PTR RRs in the\n" |
"Also displays labels suitable for use with PTR RRs in the reverse zone\n" |
| 107 |
"reverse zone ip6.arpa.\n\n" |
"ip6.arpa.\n\n" |
| 108 |
|
|
| 109 |
"Updated in 2015 to conform to ISO C 2011.\n\n" |
"Updated in 2015 to conform to ISO C 2011.\n\n" |
| 110 |
|
|
| 130 |
|
|
| 131 |
int ConstructMAC(const char *argvi, unsigned char *MAC); |
int ConstructMAC(const char *argvi, unsigned char *MAC); |
| 132 |
void ConstructEUI64(const unsigned char * const MAC, unsigned char * const EUI64); |
void ConstructEUI64(const unsigned char * const MAC, unsigned char * const EUI64); |
| 133 |
void InvertUniversalLocalBit(unsigned char * const EUI64); |
void ConstructModEUI64(const unsigned char * const EUI64, unsigned char * const ModEUI64); |
| 134 |
|
|
| 135 |
void PrintMAC(const unsigned char * const MAC); |
void PrintMAC(const unsigned char * const MAC); |
| 136 |
void PrintEUI64(const unsigned char * const EUI64); |
void PrintEUI64(const unsigned char * const EUI64); |
| 137 |
|
void PrintModEUI64(const unsigned char * const EUI64); |
| 138 |
void PrintEUI64_InterfaceID(const unsigned char * const EUI64); |
void PrintEUI64_InterfaceID(const unsigned char * const EUI64); |
| 139 |
void PrintEUI64_IP6_ARPA(const unsigned char * const EUI64); |
void PrintEUI64_IP6_ARPA(const unsigned char * const EUI64); |
| 140 |
//void PrintEUI64_IP6_INT(const unsigned char * const EUI64); |
//void PrintEUI64_IP6_INT(const unsigned char * const EUI64); |
| 141 |
|
|
| 142 |
void TransformMAC(const char * const argv0, const char * const argvi) |
void TransformMAC(const char * const argv0, const char * const argvi) |
| 143 |
{ |
{ |
| 144 |
unsigned char MAC[6], EUI64[8]; |
unsigned char MAC[6], EUI64[8], ModEUI64[8]; |
| 145 |
|
|
| 146 |
if (ConstructMAC(argvi, MAC)) { |
if (ConstructMAC(argvi, MAC)) { |
| 147 |
fprintf(stderr, "%s: invalid MAC address: %s\n", argv0, argvi); |
fprintf(stderr, "%s: invalid MAC address: %s\n", argv0, argvi); |
| 149 |
} |
} |
| 150 |
|
|
| 151 |
ConstructEUI64(MAC, EUI64); |
ConstructEUI64(MAC, EUI64); |
| 152 |
|
ConstructModEUI64(EUI64, ModEUI64); |
| 153 |
|
|
| 154 |
PrintMAC(MAC); |
PrintMAC(MAC); |
| 155 |
PrintEUI64(EUI64); |
PrintEUI64(EUI64); |
| 156 |
|
PrintModEUI64(ModEUI64); |
| 157 |
/* Transform the EUI-64 address into |
PrintEUI64_InterfaceID(ModEUI64); |
| 158 |
the Modified EUI-64 address for use as |
PrintEUI64_IP6_ARPA(ModEUI64); |
| 159 |
the value for the interface ID */ |
//PrintEUI64_IP6_INT(ModEUI64); |
|
InvertUniversalLocalBit(EUI64); |
|
|
|
|
|
PrintEUI64_InterfaceID(EUI64); |
|
|
PrintEUI64_IP6_ARPA(EUI64); |
|
|
//PrintEUI64_IP6_INT(EUI64); |
|
| 160 |
} /* TransformMAC() */ |
} /* TransformMAC() */ |
| 161 |
|
|
| 162 |
int ConstructMAC(const char *argvi, unsigned char * MAC) |
int ConstructMAC(const char *argvi, unsigned char * MAC) |
| 225 |
EUI64[1] = MAC[1]; |
EUI64[1] = MAC[1]; |
| 226 |
EUI64[2] = MAC[2]; |
EUI64[2] = MAC[2]; |
| 227 |
EUI64[3] = 0xFF; |
EUI64[3] = 0xFF; |
| 228 |
EUI64[4] = 0xFE; |
EUI64[4] = 0xFF; |
| 229 |
EUI64[5] = MAC[3]; |
EUI64[5] = MAC[3]; |
| 230 |
EUI64[6] = MAC[4]; |
EUI64[6] = MAC[4]; |
| 231 |
EUI64[7] = MAC[5]; |
EUI64[7] = MAC[5]; |
| 232 |
} /* ConstructEUI64() */ |
} /* ConstructEUI64() */ |
| 233 |
|
|
| 234 |
|
void InvertUniversalLocalBit(unsigned char * const EUI64); |
| 235 |
|
|
| 236 |
|
void ConstructModEUI64(const unsigned char * const EUI64, unsigned char * const ModEUI64) |
| 237 |
|
{ |
| 238 |
|
ModEUI64[0] = EUI64[0]; |
| 239 |
|
ModEUI64[1] = EUI64[1]; |
| 240 |
|
ModEUI64[2] = EUI64[2]; |
| 241 |
|
ModEUI64[3] = EUI64[3]; |
| 242 |
|
ModEUI64[4] = 0xFE; |
| 243 |
|
ModEUI64[5] = EUI64[5]; |
| 244 |
|
ModEUI64[6] = EUI64[6]; |
| 245 |
|
ModEUI64[7] = EUI64[7]; |
| 246 |
|
|
| 247 |
|
InvertUniversalLocalBit(ModEUI64); |
| 248 |
|
} /* ConstructModEUI64() */ |
| 249 |
|
|
| 250 |
void InvertUniversalLocalBit(unsigned char * const EUI64) |
void InvertUniversalLocalBit(unsigned char * const EUI64) |
| 251 |
{ |
{ |
| 252 |
if (EUI64[0] & 0x02) |
if (EUI64[0] & 0x02) |
| 268 |
EUI64[4], EUI64[5], EUI64[6], EUI64[7]); |
EUI64[4], EUI64[5], EUI64[6], EUI64[7]); |
| 269 |
} /* PrintEUI64() */ |
} /* PrintEUI64() */ |
| 270 |
|
|
| 271 |
|
void PrintModEUI64(const unsigned char * const EUI64) |
| 272 |
|
{ |
| 273 |
|
printf("Mod. EUI-64:\t%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", |
| 274 |
|
EUI64[0], EUI64[1], EUI64[2], EUI64[3], |
| 275 |
|
EUI64[4], EUI64[5], EUI64[6], EUI64[7]); |
| 276 |
|
} /* PrintModEUI64() */ |
| 277 |
|
|
| 278 |
void PrintEUI64_InterfaceID(const unsigned char * const EUI64) |
void PrintEUI64_InterfaceID(const unsigned char * const EUI64) |
| 279 |
{ |
{ |
| 280 |
printf("Interface ID:\t::%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", |
printf("Interface ID:\t::%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", |