message: Show the fragmentation numbers in message stringification
authorMartin Willi <martin@revosec.ch>
Fri, 17 Apr 2015 12:19:05 +0000 (14:19 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 1 Jun 2015 07:42:10 +0000 (09:42 +0200)
src/libcharon/encoding/message.c

index e51c946..1ee2cf8 100644 (file)
@@ -1411,6 +1411,42 @@ static char* get_string(private_message_t *this, char *buf, int len)
                                len -= written;
                        }
                }
+               if (payload->get_type(payload) == PLV1_FRAGMENT)
+               {
+                       fragment_payload_t *frag;
+
+                       frag = (fragment_payload_t*)payload;
+                       if (frag->is_last(frag))
+                       {
+                               written = snprintf(pos, len, "(%u/%u)",
+                                                       frag->get_number(frag), frag->get_number(frag));
+                       }
+                       else
+                       {
+                               written = snprintf(pos, len, "(%u)", frag->get_number(frag));
+                       }
+                       if (written >= len || written < 0)
+                       {
+                               return buf;
+                       }
+                       pos += written;
+                       len -= written;
+               }
+               if (payload->get_type(payload) == PLV2_FRAGMENT)
+               {
+                       encrypted_fragment_payload_t *frag;
+
+                       frag = (encrypted_fragment_payload_t*)payload;
+                       written = snprintf(pos, len, "(%u/%u)",
+                                                          frag->get_fragment_number(frag),
+                                                          frag->get_total_fragments(frag));
+                       if (written >= len || written < 0)
+                       {
+                               return buf;
+                       }
+                       pos += written;
+                       len -= written;
+               }
        }
        enumerator->destroy(enumerator);