traffic-selector: Print ICMP[v6] message type and code in a more readable way
authorTobias Brunner <tobias@strongswan.org>
Mon, 14 Oct 2013 14:53:42 +0000 (16:53 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 17 Oct 2013 14:57:39 +0000 (16:57 +0200)
src/libstrongswan/selectors/traffic_selector.c

index 6ee961e..b9d9b65 100644 (file)
@@ -194,6 +194,22 @@ static bool is_any(private_traffic_selector_t *this)
 }
 
 /**
+ * Print ICMP/ICMPv6 type and code
+ */
+static int print_icmp(printf_hook_data_t *data, u_int16_t port)
+{
+       u_int8_t type, code;
+
+       type = traffic_selector_icmp_type(port);
+       code = traffic_selector_icmp_code(port);
+       if (code)
+       {
+               return print_in_hook(data, "%d(%d)", type, code);
+       }
+       return print_in_hook(data, "%d", type);
+}
+
+/**
  * Described in header.
  */
 int traffic_selector_printf_hook(printf_hook_data_t *data,
@@ -302,20 +318,35 @@ int traffic_selector_printf_hook(printf_hook_data_t *data,
                {
                        struct servent *serv;
 
-                       serv = getservbyport(htons(this->from_port), serv_proto);
-                       if (serv)
+                       if (this->protocol == IPPROTO_ICMP ||
+                               this->protocol == IPPROTO_ICMPV6)
                        {
-                               written += print_in_hook(data, "%s", serv->s_name);
+                               written += print_icmp(data, this->from_port);
                        }
                        else
                        {
-                               written += print_in_hook(data, "%d", this->from_port);
+                               serv = getservbyport(htons(this->from_port), serv_proto);
+                               if (serv)
+                               {
+                                       written += print_in_hook(data, "%s", serv->s_name);
+                               }
+                               else
+                               {
+                                       written += print_in_hook(data, "%d", this->from_port);
+                               }
                        }
                }
                else if (is_opaque(this))
                {
                        written += print_in_hook(data, "OPAQUE");
                }
+               else if (this->protocol == IPPROTO_ICMP ||
+                                this->protocol == IPPROTO_ICMPV6)
+               {
+                       written += print_icmp(data, this->from_port);
+                       written += print_in_hook(data, "-");
+                       written += print_icmp(data, this->to_port);
+               }
                else
                {
                        written += print_in_hook(data, "%d-%d",