Further review comments. Always allocate vendor so we can always free this pointer. Add a callback for the update subroutine.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
486e497d8a
commit
427f8ad8e1
2
FTL.h
2
FTL.h
|
@ -222,7 +222,7 @@ typedef struct {
|
|||
// Used to check memory integrity in various structs
|
||||
#define MAGICBYTE 0x57
|
||||
|
||||
// Some magic database constants constants
|
||||
// Some magic database constants
|
||||
#define DB_FAILED -2
|
||||
#define DB_NODATA -1
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ for line in manuf:
|
|||
line = line.strip()
|
||||
|
||||
# Skip comments and empty lines
|
||||
if line[:1] == "#" or line == "":
|
||||
if line[1] == "#" or line == "":
|
||||
continue
|
||||
|
||||
# Remove quotation marks as these might interfere with later INSERT / UPDATE commands
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#define ARPCACHE "/proc/net/arp"
|
||||
|
||||
// Private prototypes
|
||||
char* getMACVendor(const char* hwaddr);
|
||||
static char* getMACVendor(const char* hwaddr);
|
||||
|
||||
bool create_network_table(void)
|
||||
{
|
||||
|
@ -194,7 +194,7 @@ void parse_arp_cache(void)
|
|||
dbclose();
|
||||
}
|
||||
|
||||
char* getMACVendor(const char* hwaddr)
|
||||
static char* getMACVendor(const char* hwaddr)
|
||||
{
|
||||
struct stat st;
|
||||
if(stat(FTLfiles.macvendordb, &st) != 0)
|
||||
|
@ -246,16 +246,16 @@ char* getMACVendor(const char* hwaddr)
|
|||
{
|
||||
vendor = strdup((char*)sqlite3_column_text(stmt, 0));
|
||||
}
|
||||
else if(rc == SQLITE_DONE)
|
||||
else
|
||||
{
|
||||
// Not found
|
||||
vendor = "";
|
||||
vendor = strdup("");
|
||||
}
|
||||
else
|
||||
|
||||
if(rc != SQLITE_DONE && rc != SQLITE_ROW)
|
||||
{
|
||||
// Error
|
||||
logg("getMACVendor(%s) - SQL error step (%i): %s", hwaddr, rc, sqlite3_errmsg(macdb));
|
||||
vendor = "";
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
@ -306,10 +306,7 @@ void updateMACVendorRecords()
|
|||
if(asprintf(&querystr, "UPDATE network SET macVendor = \"%s\" WHERE id = %i", vendor, id) < 1)
|
||||
{
|
||||
logg("updateMACVendorRecords() - Allocation error 2");
|
||||
|
||||
if(strlen(vendor) > 0)
|
||||
free(vendor);
|
||||
|
||||
free(vendor);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -319,18 +316,14 @@ void updateMACVendorRecords()
|
|||
if( rc != SQLITE_OK ){
|
||||
logg("updateMACVendorRecords() - SQL exec error: %s (%i): %s", querystr, rc, zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
|
||||
free(querystr);
|
||||
if(strlen(vendor) > 0)
|
||||
free(vendor);
|
||||
|
||||
free(vendor);
|
||||
break;
|
||||
}
|
||||
|
||||
// Free allocated memory
|
||||
free(querystr);
|
||||
if(strlen(vendor) > 0)
|
||||
free(vendor);
|
||||
free(vendor);
|
||||
}
|
||||
if(rc != SQLITE_DONE)
|
||||
{
|
||||
|
|
|
@ -168,6 +168,12 @@ void process_request(char *client_message, int *sock)
|
|||
read_regex_from_file();
|
||||
unlock_shm();
|
||||
}
|
||||
else if(command(client_message, ">update-mac-vendor"))
|
||||
{
|
||||
processed = true;
|
||||
logg("Received API request to update vendors in network table");
|
||||
updateMACVendorRecords();
|
||||
}
|
||||
|
||||
// Test only at the end if we want to quit or kill
|
||||
// so things can be processed before
|
||||
|
|
|
@ -138,3 +138,4 @@ bool check_capabilities(void);
|
|||
// networktable.c
|
||||
bool create_network_table(void);
|
||||
void parse_arp_cache(void);
|
||||
void updateMACVendorRecords(void);
|
||||
|
|
Loading…
Reference in New Issue