diff options
author | Anders Broman <anders.broman@ericsson.com> | 2007-10-27 14:44:29 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2007-10-27 14:44:29 +0000 |
commit | 1143ab41b155688a6eea2b3e2544a9ff527a2c6e (patch) | |
tree | 079baf0c01f0ade19877c264cdaba6a5ef68704d /epan/ipproto.c | |
parent | 79e035e3f3ba14472970d3d485bbe962c85bd24b (diff) |
Apply yet another set of the optimization patches:
- Use a fast path for the most common use of tvb_get_xxx functions:
offset is >= 0 and tvb->real_data is set (this one is always true).
- match_strval() is a linear search, put the most common protocols
TCP/UDP/RDP first.
- fix gtk1 g_strlcat declaration Use g_strlcat
svn path=/trunk/; revision=23285
Diffstat (limited to 'epan/ipproto.c')
-rw-r--r-- | epan/ipproto.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/epan/ipproto.c b/epan/ipproto.c index 9edaa0c8e3..9ddae2f462 100644 --- a/epan/ipproto.c +++ b/epan/ipproto.c @@ -36,11 +36,16 @@ #include <epan/packet.h> #include <epan/addr_resolv.h> #include <epan/dissectors/packet-ip.h> +#include <epan/strutil.h> static const value_string ipproto_val[] = { #if 0 { IP_PROTO_IP, "IPv4" }, #endif + { IP_PROTO_TCP, "TCP" }, + { IP_PROTO_UDP, "UDP" }, + { IP_PROTO_RDP, "Reliable Data" }, + { IP_PROTO_HOPOPTS, "IPv6 hop-by-hop option" }, { IP_PROTO_ICMP, "ICMP" }, { IP_PROTO_IGMP, "IGMP" }, @@ -50,7 +55,6 @@ static const value_string ipproto_val[] = { { IP_PROTO_IPV4, "IPv4" }, #endif { IP_PROTO_STREAM, "Stream" }, - { IP_PROTO_TCP, "TCP" }, { IP_PROTO_CBT, "CBT" }, { IP_PROTO_EGP, "EGP" }, { IP_PROTO_IGP, "IGRP" }, @@ -61,7 +65,6 @@ static const value_string ipproto_val[] = { { IP_PROTO_EMCON, "EMCON" }, { IP_PROTO_XNET, "XNET" }, { IP_PROTO_CHAOS, "CHAOS" }, - { IP_PROTO_UDP, "UDP" }, { IP_PROTO_MUX, "Multiplex" }, { IP_PROTO_DCNMEAS, "DCN Measurement" }, { IP_PROTO_HMP, "Host Monitoring" }, @@ -71,7 +74,6 @@ static const value_string ipproto_val[] = { { IP_PROTO_TRUNK2, "Trunk-2" }, { IP_PROTO_LEAF1, "Leaf-1" }, { IP_PROTO_LEAF2, "Leaf-2" }, - { IP_PROTO_RDP, "Reliable Data" }, { IP_PROTO_IRT, "IRT" }, { IP_PROTO_TP, "ISO TP4" }, { IP_PROTO_BULK, "Bulk Data" }, @@ -186,14 +188,12 @@ static const value_string ipproto_val[] = { }; const char *ipprotostr(int proto) { - static char buf[128]; const char *s; -#ifdef HAVE_GETPROTOBYNUMBER - struct protoent *pe; -#endif if ((s = match_strval(proto, ipproto_val)) != NULL) - goto ok; + return s; + + s = "Unknown"; #ifdef HAVE_GETPROTOBYNUMBER /* @@ -201,17 +201,15 @@ const char *ipprotostr(int proto) { * protocol names? */ if (g_resolv_flags != 0) { + static char buf[128]; + struct protoent *pe; + pe = getprotobynumber(proto); if (pe) { - s = pe->p_name; - goto ok; + g_strlcpy(buf, pe->p_name, sizeof(buf)); + s = buf; } } #endif - - s = "Unknown"; - -ok: - g_snprintf(buf, sizeof(buf), "%s", s); - return buf; + return s; } |