*** trunk/mac2eui64.c 2015/09/29 08:26:40 3
--- trunk/mac2eui64.c 2015/09/29 08:31:02 4
***************
*** 4,13 ****
Conversion from the IEEE 802 MAC format to the IEEE EUI-64 format.
Displays values suitable for use as a 64 bit interface ID in A6 RRs.
Also displayed are labels suitable for use with PTR RRs in the
! two defined reverse zones ip6.arpa (A6) and ip6.int (AAAA).
! Copyright (C) 2003 Trond Endrestøl <trond@ramstind.gtf.ol.no>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
--- 4,15 ----
Conversion from the IEEE 802 MAC format to the IEEE EUI-64 format.
Displays values suitable for use as a 64 bit interface ID in A6 RRs.
Also displayed are labels suitable for use with PTR RRs in the
! reverse zone ip6.arpa.
! Updated in 2015 to conform to ISO C 2011.
+ Copyright (C) 2003 Trond Endrestøl <Trond.Endrestol@ximalas.info>
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
***************
*** 29,53 ****
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
- void Usage(const char * const argv0, int ReturnValue);
- void Version(const char * const argv0);
- void TransformMAC(const char * const argv0, const char * const argvi);
-
int c;
! size_t i;
opterr = 0;
while ((c = getopt(argc, argv, "hv")) != -1) {
switch (c) {
case 'h':
Usage(argv[0], EXIT_SUCCESS);
! break;
case 'v':
Version(argv[0]);
! break;
case '?':
fprintf(stderr, "%s: invalid option -%c\n", argv[0], optopt);
--- 31,55 ----
#include <stdlib.h>
#include <unistd.h>
+ void Usage(const char * const argv0, int ReturnValue) __attribute__((noreturn));
+ void Version(const char * const argv0) __attribute__((noreturn));
+ void TransformMAC(const char * const argv0, const char * const argvi);
+
int main(int argc, char **argv)
{
int c;
! ssize_t i;
opterr = 0;
while ((c = getopt(argc, argv, "hv")) != -1) {
switch (c) {
case 'h':
Usage(argv[0], EXIT_SUCCESS);
! //break;
case 'v':
Version(argv[0]);
! //break;
case '?':
fprintf(stderr, "%s: invalid option -%c\n", argv[0], optopt);
***************
*** 56,62 ****
default:
fprintf(stderr, "%s: something is dead wrong with getopt() or with this program\n", argv[0]);
return EXIT_FAILURE;
! break;
}
}
--- 58,64 ----
default:
fprintf(stderr, "%s: something is dead wrong with getopt() or with this program\n", argv[0]);
return EXIT_FAILURE;
! //break;
}
}
***************
*** 102,111 ****
"Conversion from the IEEE 802 MAC format to the IEEE EUI-64 format.\n"
"Displays values suitable for use as a 64 bit interface ID in A6 RRs.\n"
"Also displayed are labels suitable for use with PTR RRs in the\n"
! "two defined reverse zones ip6.arpa (A6) and ip6.int (AAAA).\n\n"
! "Copyright (C) 2003 Trond Endrestøl <trond@ramstind.gtf.ol.no>\n\n"
"This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
--- 104,115 ----
"Conversion from the IEEE 802 MAC format to the IEEE EUI-64 format.\n"
"Displays values suitable for use as a 64 bit interface ID in A6 RRs.\n"
"Also displayed are labels suitable for use with PTR RRs in the\n"
! "reverse zone ip6.arpa.\n\n"
! "Updated in 2015 to conform to ISO C 2011.\n\n"
+ "Copyright (C) 2003 Trond Endrestøl <Trond.Endrestol@ximalas.info>\n\n"
+
"This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
***************
*** 124,141 ****
exit(EXIT_SUCCESS);
} /* Version */
! void TransformMAC(const char * const argv0, const char * const argvi)
! {
! int ConstructMAC(const char *argvi, unsigned char *MAC);
! void ConstructEUI64(const unsigned char * const MAC, unsigned char * const EUI64);
! void InvertUniversalLocalBit(unsigned char * const EUI64);
! void PrintMAC(const unsigned char * const MAC);
! void PrintEUI64(const unsigned char * const EUI64);
! void PrintEUI64_InterfaceID(const unsigned char * const EUI64);
! void PrintEUI64_IP6_INT(const unsigned char * const EUI64);
! void PrintEUI64_IP6_ARPA(const unsigned char * const EUI64);
unsigned char MAC[6], EUI64[8];
if (ConstructMAC(argvi, MAC)) {
--- 128,145 ----
exit(EXIT_SUCCESS);
} /* Version */
! int ConstructMAC(const char *argvi, unsigned char *MAC);
! void ConstructEUI64(const unsigned char * const MAC, unsigned char * const EUI64);
! void InvertUniversalLocalBit(unsigned char * const EUI64);
! void PrintMAC(const unsigned char * const MAC);
! void PrintEUI64(const unsigned char * const EUI64);
! void PrintEUI64_InterfaceID(const unsigned char * const EUI64);
! void PrintEUI64_IP6_ARPA(const unsigned char * const EUI64);
! //void PrintEUI64_IP6_INT(const unsigned char * const EUI64);
+ void TransformMAC(const char * const argv0, const char * const argvi)
+ {
unsigned char MAC[6], EUI64[8];
if (ConstructMAC(argvi, MAC)) {
***************
*** 154,161 ****
InvertUniversalLocalBit(EUI64);
PrintEUI64_InterfaceID(EUI64);
- PrintEUI64_IP6_INT(EUI64);
PrintEUI64_IP6_ARPA(EUI64);
} /* TransformMAC() */
int ConstructMAC(const char *argvi, unsigned char * MAC)
--- 158,165 ----
InvertUniversalLocalBit(EUI64);
PrintEUI64_InterfaceID(EUI64);
PrintEUI64_IP6_ARPA(EUI64);
+ //PrintEUI64_IP6_INT(EUI64);
} /* TransformMAC() */
int ConstructMAC(const char *argvi, unsigned char * MAC)
***************
*** 169,182 ****
while (*argvi) {
if (isxdigit(*argvi)) {
NumDigits++;
! MSNybble = *argvi++;
if (!isxdigit(*argvi)) {
break;
}
NumDigits++;
! LSNybble = *argvi;
MAC[i++] = ConstructHexByte(MSNybble, LSNybble);
}
--- 173,186 ----
while (*argvi) {
if (isxdigit(*argvi)) {
NumDigits++;
! MSNybble = (unsigned char)*argvi++;
if (!isxdigit(*argvi)) {
break;
}
NumDigits++;
! LSNybble = (unsigned char)*argvi;
MAC[i++] = ConstructHexByte(MSNybble, LSNybble);
}
***************
*** 190,201 ****
return ReturnValue;
} /* ConstructMAC() */
unsigned char ConstructHexByte(unsigned char MSNybble, unsigned char LSNybble)
{
unsigned char Byte;
! MSNybble = toupper(MSNybble);
! LSNybble = toupper(LSNybble);
if (MSNybble >= 'A') {
MSNybble = 0x0A + MSNybble - 'A';
--- 194,207 ----
return ReturnValue;
} /* ConstructMAC() */
+ unsigned char ConstructHexByte(unsigned char MSNybble, unsigned char LSNybble);
+
unsigned char ConstructHexByte(unsigned char MSNybble, unsigned char LSNybble)
{
unsigned char Byte;
! MSNybble = (unsigned char)toupper(MSNybble);
! LSNybble = (unsigned char)toupper(LSNybble);
if (MSNybble >= 'A') {
MSNybble = 0x0A + MSNybble - 'A';
***************
*** 211,217 ****
LSNybble -= '0';
}
! Byte = (MSNybble << 4) | LSNybble;
return Byte;
} /* ConstructHexByte() */
--- 217,223 ----
LSNybble -= '0';
}
! Byte = (unsigned char)((MSNybble << 4) | LSNybble);
return Byte;
} /* ConstructHexByte() */
***************
*** 256,264 ****
EUI64[4], EUI64[5], EUI64[6], EUI64[7]);
} /* PrintEUI64_InterfaceID() */
! void PrintEUI64_IP6_INT(const unsigned char * const EUI64)
{
! printf("ip6.int/64:\t%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x\n",
EUI64[7] & 0x0F, EUI64[7] >> 4,
EUI64[6] & 0x0F, EUI64[6] >> 4,
EUI64[5] & 0x0F, EUI64[5] >> 4,
--- 262,274 ----
EUI64[4], EUI64[5], EUI64[6], EUI64[7]);
} /* PrintEUI64_InterfaceID() */
! void PrintEUI64_IP6_ARPA(const unsigned char * const EUI64)
{
! // printf("ip6.arpa:\t\\[x%02X%02X%02X%02X%02X%02X%02X%02X/64]\n",
! // EUI64[0], EUI64[1], EUI64[2], EUI64[3],
! // EUI64[4], EUI64[5], EUI64[6], EUI64[7]);
!
! printf("ip6.arpa/64:\t%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x\n",
EUI64[7] & 0x0F, EUI64[7] >> 4,
EUI64[6] & 0x0F, EUI64[6] >> 4,
EUI64[5] & 0x0F, EUI64[5] >> 4,
***************
*** 267,279 ****
EUI64[2] & 0x0F, EUI64[2] >> 4,
EUI64[1] & 0x0F, EUI64[1] >> 4,
EUI64[0] & 0x0F, EUI64[0] >> 4);
- } /* PrintEUI64_IP6_INT() */
-
- void PrintEUI64_IP6_ARPA(const unsigned char * const EUI64)
- {
- printf("ip6.arpa:\t\\[x%02X%02X%02X%02X%02X%02X%02X%02X/64]\n",
- EUI64[0], EUI64[1], EUI64[2], EUI64[3],
- EUI64[4], EUI64[5], EUI64[6], EUI64[7]);
} /* PrintEUI64_IP6_ARPA() */
/* mac2eui64.c */
--- 277,295 ----
EUI64[2] & 0x0F, EUI64[2] >> 4,
EUI64[1] & 0x0F, EUI64[1] >> 4,
EUI64[0] & 0x0F, EUI64[0] >> 4);
} /* PrintEUI64_IP6_ARPA() */
+
+ //void PrintEUI64_IP6_INT(const unsigned char * const EUI64)
+ //{
+ // printf("ip6.int/64:\t%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x\n",
+ // EUI64[7] & 0x0F, EUI64[7] >> 4,
+ // EUI64[6] & 0x0F, EUI64[6] >> 4,
+ // EUI64[5] & 0x0F, EUI64[5] >> 4,
+ // EUI64[4] & 0x0F, EUI64[4] >> 4,
+ // EUI64[3] & 0x0F, EUI64[3] >> 4,
+ // EUI64[2] & 0x0F, EUI64[2] >> 4,
+ // EUI64[1] & 0x0F, EUI64[1] >> 4,
+ // EUI64[0] & 0x0F, EUI64[0] >> 4);
+ //} /* PrintEUI64_IP6_INT() */
/* mac2eui64.c */
|