Skip to content

Commit

Permalink
Handles inline MDNS names dissection
Browse files Browse the repository at this point in the history
  • Loading branch information
simonemainardi committed Jan 28, 2019
1 parent f369888 commit 88e63e0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
6 changes: 5 additions & 1 deletion include/Host.h
Expand Up @@ -36,7 +36,9 @@ class Host : public GenericHashEntry {

/* Host data: update Host::deleteHostData when adding new fields */
struct {
char *symbolic_name; /* write protected by mutex */
char * symbolic_name; /* write protected by mutex */
char * dhcp; /* Extracted from DHCP dissection */
char * mdns, *mdns_txt;
} names;

char *mdns_info;
Expand Down Expand Up @@ -262,6 +264,8 @@ class Host : public GenericHashEntry {
virtual void inlineSetOS(const char * const _os) {};
void inlineSetSSDPLocation(const char * const url);
void inlineSetMDNSInfo(char * const s);
void inlineSetMDNSName(const char * const n);
void inlineSetMDNSTXTName(const char * const n);
};

#endif /* _HOST_H_ */
9 changes: 7 additions & 2 deletions src/Flow.cpp
Expand Up @@ -3069,8 +3069,10 @@ void Flow::dissectMDNS(u_int8_t *payload, u_int16_t payload_len) {
c[0] = '\0';
}

if(cli_host)
if(cli_host) {
cli_host->setName(name); /* See (**) */
cli_host->inlineSetMDNSName(name);
}

if((rsp_type == 0x10 /* TXT */) && (data_len > 0)) {
char *txt = (char*)&payload[i+sizeof(rsp)], txt_buf[256];
Expand Down Expand Up @@ -3108,7 +3110,10 @@ void Flow::dissectMDNS(u_int8_t *payload, u_int16_t payload_len) {
}

if(strncmp(txt_buf, "nm=", 3) == 0) {
if(cli_host) cli_host->setName(&txt_buf[3]);
if(cli_host) {
cli_host->setName(&txt_buf[3]);
cli_host->inlineSetMDNSTXTName(&txt_buf[3]);
}
}

if(strncmp(txt_buf, "ssid=", 3) == 0) {
Expand Down
20 changes: 18 additions & 2 deletions src/Host.cpp
Expand Up @@ -1079,6 +1079,20 @@ void Host::inlineSetSSDPLocation(const char * const url) {

/* *************************************** */

void Host::inlineSetMDNSName(const char * const mdns_n) {
if(!names.mdns && mdns_n && (names.mdns = strdup(mdns_n)))
;
}

/* *************************************** */

void Host::inlineSetMDNSTXTName(const char * const mdns_n_txt) {
if(!names.mdns_txt && mdns_n_txt && (names.mdns_txt = strdup(mdns_n_txt)))
;
}

/* *************************************** */

char* Host::get_country(char *buf, u_int buf_len) {
char *continent = NULL, *country_name = NULL, *city = NULL;
float latitude = 0, longitude = 0;
Expand Down Expand Up @@ -1188,8 +1202,10 @@ void Host::checkDataReset() {
void Host::deleteHostData() {
if(m) m->lock(__FILE__, __LINE__);
// setName((char*)""); // TODO: handle setName reset
if(mdns_info) { free(mdns_info); mdns_info = NULL; }
if(ssdpLocation) { free(ssdpLocation); ssdpLocation = NULL; }
if(mdns_info) { free(mdns_info); mdns_info = NULL; }
if(ssdpLocation) { free(ssdpLocation); ssdpLocation = NULL; }
if(names.mdns) { free(names.mdns); names.mdns = NULL; }
if(names.mdns_txt) { free(names.mdns_txt); names.mdns_txt = NULL; }
if(m) m->unlock(__FILE__, __LINE__);
host_label_set = false;
first_seen = last_seen;
Expand Down

0 comments on commit 88e63e0

Please sign in to comment.