Ethereal-dev: [Ethereal-dev] Patch: local dns support for NSIP - please check in
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: "Susanne Edlund (LI/EAB)" <susanne.edlund@xxxxxxxxxxxx>
Date: Wed, 12 Jan 2005 14:28:21 +0100
I have added support for a "local dns" for nsip via a text file, in which each line consists of an ip address and its translation. The translation is shown in the src and dst columns. If no translation is available the IP address is shown. To do: implement this as a generic function, available to all dissectors. --- packet-nsip.c Tue Dec 14 20:53:30 2004 +++ packet-nsip_sus.c Tue Jan 11 07:29:28 2005 @@ -52,20 +52,14 @@ #define NSIP_SEP ", " /* Separator string */ #define NSIP_LITTLE_ENDIAN 0 - - -#define ERICSSON_DESCR_LEN 50 -#define ERICSSON_RIP_TYPE 223 /* Ip address of format x.x.223.x */ -#define ERICSSON_LIP_TYPE 80 /* Ip address of format x.x.80.x */ -static int hf_nsip_ericsson_rip = -1; -static int hf_nsip_ericsson_lip = -1; -static int hf_nsip_ericsson_rp = -1; - static int nsip_udp_port1 = NSIP_UDP_PORT1; static int nsip_udp_port2 = NSIP_UDP_PORT2; static int global_nsip_udp_port1 = NSIP_UDP_PORT1; static int global_nsip_udp_port2 = NSIP_UDP_PORT2; -static gboolean ericsson_decode = FALSE; +#define NSIP_DNS_NAME_MAX_LENGTH 50 +static gboolean use_nsip_dns = FALSE; +static gchar *nsip_dns_filepath; + void proto_reg_handoff_nsip(void); /* Initialize the protocol and registered fields */ @@ -270,79 +264,42 @@ "Not set" }; +static int +do_nsip_dns(address addr, char *filepath, char *dns_name) { + const int SUCCESS = 1; + const int FAILURE = 0; + char *ref_addr; + char ip_addr[16]; + FILE *fp; + int i; -static void -add_ericsson_internal_info(address addr, build_info_t *bi, char *descr) { - const guint8 MIN_RIP_ID = 3; - const guint8 MAX_RIP_ID = 16; - const guint8 MIN_LIP_ID = 10; - const guint8 MAX_LIP_ID = 13; - - int rp; - guint8 addr_type, addr_id; - guint8 dummy_len = 1; - gchar **ip_str_parts; + if (addr.type != AT_IPv4) return FAILURE; - if (addr.type != AT_IPv4) { - descr = NULL; - return; - } - ip_str_parts = g_strsplit((ip_to_str(addr.data)), ".", 4); - addr_type = (guint8)atol(ip_str_parts[2]); - addr_id = (guint8)atol(ip_str_parts[3]); - - g_strfreev(ip_str_parts); - - switch (addr_type) { - case ERICSSON_RIP_TYPE: - if ((addr_id >= MIN_RIP_ID) && (addr_id <= MAX_RIP_ID)) { - if (bi->nsip_tree) { - proto_tree_add_uint_hidden(bi->nsip_tree, hf_nsip_ericsson_rip, - bi->tvb, bi->offset, dummy_len, addr_id); - } - g_snprintf(descr, ERICSSON_DESCR_LEN, "RIP .%d", addr_id); - } - else { - g_snprintf(descr, ERICSSON_DESCR_LEN, "Unknown RIP (.%d)", addr_id); - } - break; - case ERICSSON_LIP_TYPE: - if ((addr_id >= MIN_LIP_ID) && (addr_id <= MAX_LIP_ID)) { - switch (addr_id) { - case 13: rp = 101; break; - case 12: rp = 100; break; - case 11: rp = 99; break; - case 10: rp = 98; break; - default: rp = -1; break; + fp = fopen(filepath, "r"); + if (!fp) { + perror(filepath); + return FAILURE; + } + ref_addr = ip_to_str(addr.data); + + while (!feof(fp)) { + i = fscanf(fp, "%s\t", ip_addr); + if ((!feof(fp)) && (i == 1)) { + fgets(dns_name, NSIP_DNS_NAME_MAX_LENGTH, fp); + if (g_strcasecmp(ref_addr, ip_addr) == 0) { + i = strlen(dns_name) - 1; + if (dns_name[i] == '\n') { + dns_name[i] = '\0'; } - if (bi->nsip_tree) { - proto_tree_add_uint_hidden(bi->nsip_tree, hf_nsip_ericsson_lip, - bi->tvb, bi->offset, dummy_len, addr_id); - if (rp != -1) { - proto_tree_add_uint_hidden(bi->nsip_tree, hf_nsip_ericsson_rp, - bi->tvb, bi->offset, dummy_len, - (guint8)rp); - } - } - if (rp != -1) { - g_snprintf(descr, ERICSSON_DESCR_LEN, "LIP .%d (RP%d)", addr_id, rp); + fclose(fp); + return SUCCESS; } - else { - g_snprintf(descr, ERICSSON_DESCR_LEN, "LIP .%d (Unknown RP)", - addr_id); - } } - else { - g_snprintf(descr, ERICSSON_DESCR_LEN, "Unknown LIP (.%d)", addr_id); - } - break; - default: - g_snprintf(descr, ERICSSON_DESCR_LEN, "Not a RIP or LIP (.%d.%d)", - addr_type, addr_id); } + fclose(fp); + return FAILURE; } - static void get_value_length(nsip_ie_t *ie, build_info_t *bi) { /* length indicator in bit 8, 0 => two bytes, 1 => one byte */ @@ -1041,8 +998,8 @@ build_info_t bi = { tvb, 0, pinfo, NULL, tree }; proto_item *ti; proto_tree *nsip_tree; - char ericsson_src[ERICSSON_DESCR_LEN]; - char ericsson_dst[ERICSSON_DESCR_LEN]; + char dns_src[NSIP_DNS_NAME_MAX_LENGTH]; + char dns_dst[NSIP_DNS_NAME_MAX_LENGTH]; pinfo->current_proto = "NSIP"; @@ -1073,23 +1030,25 @@ } decode_pdu(pdu_type, &bi); - if (ericsson_decode){ - add_ericsson_internal_info(bi.pinfo->src, &bi, ericsson_src); - if (ericsson_src != NULL) { - pinfo->src.type = AT_NONE; - if (check_col(pinfo->cinfo, COL_DEF_SRC)) { - col_set_str(pinfo->cinfo, COL_DEF_SRC, ericsson_src); - } - } - add_ericsson_internal_info(bi.pinfo->dst, &bi, ericsson_dst); - if (ericsson_dst != NULL) { - pinfo->dst.type = AT_NONE; - if (check_col(pinfo->cinfo, COL_DEF_DST)) { - col_set_str(pinfo->cinfo, COL_DEF_DST, ericsson_dst); - } - } - }/* ericsson_decode */ + if (use_nsip_dns){ + if (do_nsip_dns(bi.pinfo->src, + nsip_dns_filepath, + dns_src)) { + pinfo->src.type = AT_NONE; + if (check_col(pinfo->cinfo, COL_DEF_SRC)) { + col_set_str(pinfo->cinfo, COL_DEF_SRC, dns_src); + } + } + if (do_nsip_dns(bi.pinfo->dst, + nsip_dns_filepath, + dns_dst)) { + pinfo->dst.type = AT_NONE; + if (check_col(pinfo->cinfo, COL_DEF_DST)) { + col_set_str(pinfo->cinfo, COL_DEF_DST, dns_dst); + } + } + } } void @@ -1206,21 +1165,6 @@ FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL } }, - { &hf_nsip_ericsson_rip, - { "Ericsson RIP", "nsip.ericsson.rip", - FT_UINT8, BASE_DEC, NULL, 0x0, - "", HFILL } - }, - { &hf_nsip_ericsson_lip, - { "Ericsson LIP", "nsip.ericsson.lip", - FT_UINT8, BASE_DEC, NULL, 0x0, - "", HFILL } - }, - { &hf_nsip_ericsson_rp, - { "Ericsson RP", "nsip.ericsson.rp", - FT_UINT8, BASE_DEC, NULL, 0x0, - "", HFILL } - }, }; /* Setup protocol subtree array */ @@ -1252,9 +1196,14 @@ prefs_register_uint_preference(nsip_module, "udp.port2", "NSIP UDP Port 2", "Set the second UDP port", 10, &nsip_udp_port2); - prefs_register_bool_preference(nsip_module,"ericsson_decode", "Ericsson internal IP addr decode", - "Display Ericsson internal decode of IP address in SRC and DST Col", - &ericsson_decode); + prefs_register_bool_preference(nsip_module, "internal_dns", + "Fetch DNS info from a text file", + "Display special ip addresses in SRC and DST Col", + &use_nsip_dns); + prefs_register_string_preference(nsip_module, "internal_dns_file", + "Absolute path to file used for NSIP DNS", + "The file should be a tab delimited text file with one translation per line", + &nsip_dns_filepath); } void
- Prev by Date: [Ethereal-dev] Ethereal crash
- Next by Date: RE: [Ethereal-dev] Development problem
- Previous by thread: [Ethereal-dev] Development problem (fwd)
- Next by thread: [Ethereal-dev] Patch: L2TP version 3 support - please check in
- Index(es):