488 | | |
489 | | myGlobals.numVendorLookupRead++; |
490 | | if( (strstr(tmpLine, "(base") == NULL) && |
491 | | (strstr(tmpLine, "(special") == NULL) ) { |
492 | | continue; |
493 | | } |
494 | | tmpMAC = strtok_r(tmpLine, " \t", &strtokState); |
495 | | if(tmpMAC == NULL) continue; |
496 | | tmpTag1 = strtok_r(NULL, " \t", &strtokState); |
497 | | if(tmpTag1 == NULL) continue; |
498 | | if((strcmp(tmpTag1, "(base") == 0) || (strcmp(tmpTag1, "(special") == 0)) { |
499 | | tmpTag2 = strtok_r(NULL, " \t", &strtokState); |
500 | | if(tmpTag2 == NULL) continue; |
501 | | tmpVendor = strtok_r(NULL, "\n", &strtokState); |
502 | | if(tmpVendor == NULL) continue; |
503 | | /* Skip leading blanks and tabs*/ |
504 | | while ( (tmpVendor[0] == ' ') || (tmpVendor[0] == '\t') ) tmpVendor++; |
505 | | memset(&macInfoEntry, 0, sizeof(macInfoEntry)); |
506 | | if(strcmp(tmpTag1, "(special") == 0) { |
507 | | macInfoEntry.isSpecial = 's'; |
508 | | } else { |
509 | | macInfoEntry.isSpecial = 'r'; |
510 | | } |
511 | | memcpy(&(macInfoEntry.vendorName[0]), |
512 | | tmpVendor, |
513 | | min(strlen(tmpVendor)+1, sizeof(macInfoEntry.vendorName)-1)); |
514 | | data_data.dptr = (void*)(&macInfoEntry); |
515 | | data_data.dsize = sizeof(macInfoEntry); |
516 | | tmpMACkey[0]='\0'; |
517 | | strncat(tmpMACkey, tmpMAC, 2); |
518 | | strncat(tmpMACkey, ":", (sizeof(tmpMACkey) - strlen(tmpMACkey) - 1)); |
519 | | strncat(tmpMACkey, tmpMAC+2, 2); |
520 | | strncat(tmpMACkey, ":", (sizeof(tmpMACkey) - strlen(tmpMACkey) - 1)); |
521 | | strncat(tmpMACkey, tmpMAC+4, 2); |
522 | | if(strcmp(tmpTag2, "48)") == 0) { |
523 | | /* special 48 - full tag */ |
524 | | strncat(tmpMACkey, ":", (sizeof(tmpMACkey) - strlen(tmpMACkey) - 1)); |
525 | | strncat(tmpMACkey, tmpMAC+6, 2); |
526 | | strncat(tmpMACkey, ":", (sizeof(tmpMACkey) - strlen(tmpMACkey) - 1)); |
527 | | strncat(tmpMACkey, tmpMAC+8, 2); |
528 | | strncat(tmpMACkey, ":", (sizeof(tmpMACkey) - strlen(tmpMACkey) - 1)); |
529 | | strncat(tmpMACkey, tmpMAC+10, 2); |
530 | | } |
531 | | key_data.dptr = tmpMACkey; |
532 | | key_data.dsize = strlen(tmpMACkey)+1; |
533 | | if(gdbm_store(myGlobals.macPrefixFile, key_data, data_data, GDBM_REPLACE) != 0) { |
534 | | traceEvent(CONST_TRACE_WARNING, |
535 | | "VENDOR: unable to add record '%s': {%d, %s} - skipped", |
536 | | tmpMACkey, macInfoEntry.isSpecial, macInfoEntry.vendorName); |
537 | | } else { |
538 | | numLoaded++; |
539 | | myGlobals.numVendorLookupAdded++; |
540 | | if(macInfoEntry.isSpecial == 's') |
541 | | myGlobals.numVendorLookupAddedSpecial++; |
| 488 | int len; |
| 489 | |
| 490 | myGlobals.numVendorLookupRead++; |
| 491 | if( (strstr(tmpLine, "(base") == NULL) && |
| 492 | (strstr(tmpLine, "(special") == NULL) ) { |
| 493 | continue; |
| 494 | } |
| 495 | tmpMAC = strtok_r(tmpLine, " \t", &strtokState); |
| 496 | if(tmpMAC == NULL) continue; |
| 497 | tmpTag1 = strtok_r(NULL, " \t", &strtokState); |
| 498 | if(tmpTag1 == NULL) continue; |
| 499 | if((strcmp(tmpTag1, "(base") == 0) || (strcmp(tmpTag1, "(special") == 0)) { |
| 500 | tmpTag2 = strtok_r(NULL, " \t", &strtokState); |
| 501 | if(tmpTag2 == NULL) continue; |
| 502 | tmpVendor = strtok_r(NULL, "\n", &strtokState); |
| 503 | if(tmpVendor == NULL) continue; |
| 504 | /* Skip leading blanks and tabs*/ |
| 505 | while ( (tmpVendor[0] == ' ') || (tmpVendor[0] == '\t') ) tmpVendor++; |
| 506 | memset(&macInfoEntry, 0, sizeof(macInfoEntry)); |
| 507 | if(strcmp(tmpTag1, "(special") == 0) { |
| 508 | macInfoEntry.isSpecial = 's'; |
| 509 | } else { |
| 510 | macInfoEntry.isSpecial = 'r'; |
| 511 | } |
| 512 | |
| 513 | if(strlen(tmpVendor) >= (MAX_LEN_VENDOR_NAME-1)) |
| 514 | tmpVendor[MAX_LEN_VENDOR_NAME-1] = '\0'; |
| 515 | strcmp(macInfoEntry.vendorName, tmpVendor); |
| 516 | data_data.dptr = (void*)(&macInfoEntry); |
| 517 | data_data.dsize = sizeof(macInfoEntry); |
| 518 | memset(tmpMACkey, 0, sizeof(tmpMACkey)); |
| 519 | strncat(tmpMACkey, tmpMAC, 2); len = 2; tmpMACkey[len] = '\0'; |
| 520 | strcat(tmpMACkey, ":"); len++; tmpMACkey[len] = '\0'; |
| 521 | strncat(tmpMACkey, &tmpMAC[2], 2); len += 2; tmpMACkey[len] = '\0'; |
| 522 | strcat(tmpMACkey, ":"); len++; tmpMACkey[len] = '\0'; |
| 523 | strncat(tmpMACkey, &tmpMAC[4], 2); len += 2; tmpMACkey[len] = '\0'; |
| 524 | if(strcmp(tmpTag2, "48)") == 0) { |
| 525 | /* special 48 - full tag */ |
| 526 | strcat(tmpMACkey, ":"); len++; tmpMACkey[len] = '\0'; |
| 527 | strncat(tmpMACkey, &tmpMAC[6], 2); len +=2; tmpMACkey[len] = '\0'; |
| 528 | strcat(tmpMACkey, ":"); len++; tmpMACkey[len] = '\0'; |
| 529 | strncat(tmpMACkey, &tmpMAC[8], 2); len +=2; tmpMACkey[len] = '\0'; |
| 530 | strcat(tmpMACkey, ":");len++; tmpMACkey[len] = '\0'; |
| 531 | strncat(tmpMACkey, &tmpMAC[10], 2); len +=2; tmpMACkey[len] = '\0'; |
| 532 | } |
| 533 | key_data.dptr = tmpMACkey; |
| 534 | key_data.dsize = strlen(tmpMACkey)+1; |
| 535 | if(gdbm_store(myGlobals.macPrefixFile, key_data, data_data, GDBM_REPLACE) != 0) { |
| 536 | traceEvent(CONST_TRACE_WARNING, |
| 537 | "VENDOR: unable to add record '%s': {%d, %s} - skipped", |
| 538 | tmpMACkey, macInfoEntry.isSpecial, macInfoEntry.vendorName); |
| 539 | } else { |
| 540 | numLoaded++; |
| 541 | myGlobals.numVendorLookupAdded++; |
| 542 | if(macInfoEntry.isSpecial == 's') |
| 543 | myGlobals.numVendorLookupAddedSpecial++; |