diff options
author | lemur117 <lemur117@protonmail.com> | 2023-09-26 06:53:56 +0000 |
---|---|---|
committer | AndersBroman <a.broman58@gmail.com> | 2023-09-26 06:53:56 +0000 |
commit | 54b19db4ee67a0942af4b500e2c7733b2f838b51 (patch) | |
tree | 92e00fdca5cd7d606ca4f9cdbe595504c8b2c699 /wiretap/nettrace_3gpp_32_423.c | |
parent | f8d48d04d59da11d7de1c2b385421e0d11d7909f (diff) |
TS32.423: Fix dissector for various formats
Diffstat (limited to 'wiretap/nettrace_3gpp_32_423.c')
-rw-r--r-- | wiretap/nettrace_3gpp_32_423.c | 61 |
1 files changed, 19 insertions, 42 deletions
diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index 512f6f23d1..468ac42e2c 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -30,7 +30,7 @@ #include "wsutil/str_util.h" #include <wsutil/inet_addr.h> #include <wsutil/ws_assert.h> - +#include <glib.h> #include "nettrace_3gpp_32_423.h" @@ -119,18 +119,14 @@ void register_nettrace_3gpp_32_423(void); static char* nettrace_parse_address(char* curr_pos, char* next_pos, gboolean is_src_addr, exported_pdu_info_t *exported_pdu_info) { - guint port; + guint port=0; char transp_str[5]; - int scan_found; - char str[3]; - char* end_pos, *skip_pos; char ip_addr_str[WS_INET6_ADDRSTRLEN]; - int str_len; ws_in6_addr ip6_addr; guint32 ip4_addr; - gchar tempchar; + char *ptr; //for strtol function - /* curr_pos pointing to first char after address */ + /* curr_pos pointing to first char of address */ /* Excample from one trace, unsure if it's generic... * {address == 192.168.73.1, port == 5062, transport == Udp} @@ -138,38 +134,24 @@ nettrace_parse_address(char* curr_pos, char* next_pos, gboolean is_src_addr, exp * {address == 2001:1B70:8294:210A::90, port... * Address=198.142.204.199,Port=2123 */ - /* Skip whitespace and equalsigns) */ - for (skip_pos = curr_pos; skip_pos < next_pos && - ((tempchar = *skip_pos) == ' ' || - tempchar == '\t' || tempchar == '\r' || tempchar == '\n' || tempchar == '='); - skip_pos++); - curr_pos = skip_pos; + char **addressMatches = g_regex_split_simple("address\\s*=*\\s*\\[?((?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(?:[0-9a-f:]*))", curr_pos, G_REGEX_CASELESS | G_REGEX_FIRSTLINE, 0); + char **portMatches = g_regex_split_simple("port\\s*=*\\s*(\\d*)", curr_pos, G_REGEX_CASELESS | G_REGEX_FIRSTLINE, 0); + char **transportMatches = g_regex_split_simple("transport\\s*=*\\s*(\\w*)", curr_pos, G_REGEX_CASELESS | G_REGEX_FIRSTLINE, 0); - (void) g_strlcpy(str, curr_pos, 3); - /* If we find "" here we have no IP address */ - if (strcmp(str, "\"\"") == 0) { - return next_pos; - } - str[1] = 0; - if (strcmp(str, "[") == 0) { - /* Should we check for a digit here?*/ - end_pos = strstr(curr_pos, "]"); - }else { - /* Should we check for a digit here?*/ - end_pos = strstr(curr_pos, ","); + if (addressMatches[1] != NULL && addressMatches[2] != NULL) { + (void) g_strlcpy(ip_addr_str, addressMatches[1], strlen(addressMatches[1])+1); } - if (!end_pos) { - return next_pos; + if (portMatches[1] != NULL && portMatches[2] != NULL) { + port = (guint) strtol(portMatches[1], &ptr, 10); + //port = atoi(portMatches[1]); } - - str_len = (int)(end_pos - curr_pos)+1; - if (str_len > WS_INET6_ADDRSTRLEN) { - return next_pos; + if (transportMatches[1] != NULL && transportMatches[2] != NULL) { + (void) g_strlcpy(transp_str, transportMatches[1], strlen(transportMatches[1])+1); } - (void) g_strlcpy(ip_addr_str, curr_pos, str_len); - curr_pos = end_pos; + + if (ws_inet_pton6(ip_addr_str, &ip6_addr)) { if (is_src_addr) { exported_pdu_info->presence_flags |= EXP_PDU_TAG_IP6_SRC_BIT; @@ -191,9 +173,7 @@ nettrace_parse_address(char* curr_pos, char* next_pos, gboolean is_src_addr, exp } } - curr_pos++; - scan_found = sscanf(curr_pos, ", %*s %*s %5u, %*s %*s %4s", &port, transp_str); - if (scan_found == 2) { + if (port > 0) { /* Only add port_type once */ if (exported_pdu_info->ptype == EXP_PDU_PT_NONE) { if (g_ascii_strncasecmp(transp_str, "udp", 3) == 0) { @@ -345,9 +325,8 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re curr_pos += CLEN(c_s_initiator); next_pos = STRNSTR(curr_pos, c_e_initiator); /* Find address */ - curr_pos = STRNSTR(curr_pos, c_address); + curr_pos = STRNSTR(curr_pos, c_address) - 1; if (curr_pos != NULL) { - curr_pos += CLEN(c_address); nettrace_parse_address(curr_pos, next_pos, TRUE/* SRC */, &exported_pdu_info); } } @@ -359,12 +338,10 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re /* Check if we have the tag or if we passed the end of the current message */ if (curr_pos != NULL) { curr_pos += CLEN(c_s_target); - curr_pos = curr_pos + 7; next_pos = STRNSTR(curr_pos, c_e_target); /* Find address */ - curr_pos = STRNSTR(curr_pos, c_address); + curr_pos = STRNSTR(curr_pos, c_address) - 1; if (curr_pos != NULL) { - curr_pos += CLEN(c_address); /* curr_pos set below */ nettrace_parse_address(curr_pos, next_pos, FALSE/* DST */, &exported_pdu_info); } |