diff options
author | Luca Deri <deri@ntop.org> | 2021-06-16 19:57:20 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2021-06-16 19:57:20 +0200 |
commit | 2eba77e3b0724ee46685f3648ac6e714c23b9854 (patch) | |
tree | 98165b7a966aaa3bc13d6778cd2701bd6e248048 /src/lib/protocols/netbios.c | |
parent | be808c30f3f4582009df4c5efccd4f3bb0c6ef1d (diff) |
NetBIOS decoding changes
Diffstat (limited to 'src/lib/protocols/netbios.c')
-rw-r--r-- | src/lib/protocols/netbios.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/lib/protocols/netbios.c b/src/lib/protocols/netbios.c index 417cce88f..a214a174f 100644 --- a/src/lib/protocols/netbios.c +++ b/src/lib/protocols/netbios.c @@ -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); |