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:
DL6ER 2019-01-07 18:46:57 +01:00
parent 486e497d8a
commit 427f8ad8e1
No known key found for this signature in database
GPG Key ID: FB60471F0575164A
5 changed files with 18 additions and 18 deletions

2
FTL.h
View File

@ -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

View File

@ -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

View File

@ -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)
{

View File

@ -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

View File

@ -138,3 +138,4 @@ bool check_capabilities(void);
// networktable.c
bool create_network_table(void);
void parse_arp_cache(void);
void updateMACVendorRecords(void);