/[mac2eui64]/trunk/mac2eui64.c
ViewVC logotype

Diff of /trunk/mac2eui64.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5 by trond, 2015-09-29T09:12:20Z Revision 6 by trond, 2015-10-12T07:53:50Z
# Line 147  void TransformMAC(const char * const argv0, const char Line 147  void TransformMAC(const char * const argv0, const char
147      fprintf(stderr, "%s: invalid MAC address: %s\n", argv0, argvi);      fprintf(stderr, "%s: invalid MAC address: %s\n", argv0, argvi);
148      return;      return;
149      }      }
150    
151    ConstructEUI64(MAC, EUI64);    ConstructEUI64(MAC, EUI64);
152    ConstructModEUI64(EUI64, ModEUI64);    ConstructModEUI64(EUI64, ModEUI64);
153    
154    PrintMAC(MAC);    PrintMAC(MAC);
155    PrintEUI64(EUI64);    PrintEUI64(EUI64);
156    PrintModEUI64(ModEUI64);    PrintModEUI64(ModEUI64);
157    PrintEUI64_InterfaceID(ModEUI64);    PrintEUI64_InterfaceID(ModEUI64);
158    PrintEUI64_IP6_ARPA(ModEUI64);    PrintEUI64_IP6_ARPA(ModEUI64);
159    //PrintEUI64_IP6_INT(ModEUI64);    //PrintEUI64_IP6_INT(ModEUI64);
160  } /* TransformMAC() */  } /* TransformMAC() */
161    
162    unsigned char ConstructHexByte(unsigned char MSNybble, unsigned char LSNybble);
163    
164  int ConstructMAC(const char *argvi, unsigned char * MAC)  int ConstructMAC(const char *argvi, unsigned char * MAC)
165  {  {
   unsigned char ConstructHexByte(unsigned char MSNybble, unsigned char LSNybble);  
   
166    int ReturnValue = EXIT_SUCCESS, NumDigits = 0;    int ReturnValue = EXIT_SUCCESS, NumDigits = 0;
167    size_t i = 0;    size_t i = 0;
168    unsigned char MSNybble, LSNybble;    unsigned char MSNybble, LSNybble;
169    
170    while (*argvi) {    while (*argvi) {
171      if (isxdigit(*argvi)) {      if (isxdigit(*argvi)) {
172        NumDigits++;        NumDigits++;
173        MSNybble = (unsigned char)*argvi++;        MSNybble = (unsigned char)*argvi++;
174    
175        if (!isxdigit(*argvi)) {        if (!isxdigit(*argvi)) {
176          break;          break;
177          }          }
178    
179        NumDigits++;        NumDigits++;
180        LSNybble = (unsigned char)*argvi;        LSNybble = (unsigned char)*argvi;
181    
182        MAC[i++] = ConstructHexByte(MSNybble, LSNybble);        MAC[i++] = ConstructHexByte(MSNybble, LSNybble);
183        }        }
184    
185      argvi++;      argvi++;
186      }      }
187    
188    if (NumDigits != 12)    if (NumDigits != 12)
189      ReturnValue = EXIT_FAILURE;      ReturnValue = EXIT_FAILURE;
190    
191    return ReturnValue;    return ReturnValue;
192  } /* ConstructMAC() */  } /* ConstructMAC() */
   
 unsigned char ConstructHexByte(unsigned char MSNybble, unsigned char LSNybble);  
193    
194  unsigned char ConstructHexByte(unsigned char MSNybble, unsigned char LSNybble)  unsigned char ConstructHexByte(unsigned char MSNybble, unsigned char LSNybble)
195  {  {
196    unsigned char Byte;    unsigned char Byte;
197    
198    MSNybble = (unsigned char)toupper(MSNybble);    MSNybble = (unsigned char)toupper(MSNybble);
199    LSNybble = (unsigned char)toupper(LSNybble);    LSNybble = (unsigned char)toupper(LSNybble);
200    
201    if (MSNybble >= 'A') {    if (MSNybble >= 'A') {
202      MSNybble = 0x0A + MSNybble - 'A';      MSNybble = 0x0A + MSNybble - 'A';
203      }      }
204    else {    else {
205      MSNybble -= '0';      MSNybble -= '0';
206      }      }
207    


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

svn@ximalas.info
ViewVC Help
Powered by ViewVC 1.3.0-dev