NetBIOS decoding changes

This commit is contained in:
Luca Deri
2021-06-16 19:57:20 +02:00
parent be808c30f3
commit 2eba77e3b0
2 changed files with 13 additions and 8 deletions
-2
View File
@@ -131,8 +131,6 @@ extern "C" {
extern u_int8_t ndpi_is_proto(ndpi_protocol proto, u_int16_t p);
extern u_int16_t ndpi_get_lower_proto(ndpi_protocol p);
/* NDPI_PROTOCOL_NETBIOS */
int ndpi_netbios_name_interpret(char *in, size_t inlen, char *out, u_int out_len);
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct *ndpi_struct,
+13 -6
View File
@@ -37,11 +37,19 @@ struct netbios_header {
/* ****************************************************************** */
static int is_printable_char(unsigned char c) {
return(((c >= 0x20) && (c <= 0x7e)) ? 1 : 0);
}
/* ****************************************************************** */
/* The function below has been inherited by tcpdump */
int ndpi_netbios_name_interpret(char *in, size_t in_len, char *out, u_int out_len) {
int ndpi_netbios_name_interpret(u_char *in, size_t in_len, u_char *out, u_int out_len) {
u_int ret = 0, len, idx = in_len, out_idx = 0;
len = (*in++)/2, in_len--;
len = in[0] / 2;
in++, in_len--;
out_len--;
out[out_idx] = 0;
@@ -57,7 +65,7 @@ int ndpi_netbios_name_interpret(char *in, size_t in_len, char *out, u_int out_le
out[out_idx] = ((in[0] - 'A') << 4) + (in[1] - 'A');
in += 2, idx -= 2;
if(isprint(out[out_idx]))
if(is_printable_char(out[out_idx]))
out_idx++, ret++;
}
@@ -70,7 +78,6 @@ int ndpi_netbios_name_interpret(char *in, size_t in_len, char *out, u_int out_le
out[out_idx] = 0;
out_idx--;
}
}
return(ret);
@@ -81,11 +88,11 @@ int ndpi_netbios_name_interpret(char *in, size_t in_len, char *out, u_int out_le
static void ndpi_int_netbios_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t sub_protocol) {
char name[64];
unsigned char name[64];
u_int off = flow->packet.payload[12] == 0x20 ? 12 : 14;
if((off < flow->packet.payload_packet_len)
&& ndpi_netbios_name_interpret((char*)&flow->packet.payload[off],
&& ndpi_netbios_name_interpret((unsigned char*)&flow->packet.payload[off],
flow->packet.payload_packet_len - off, name, sizeof(name)) > 0) {
snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name);