diff --git a/gtests/net/packetdrill/packet_to_string.c b/gtests/net/packetdrill/packet_to_string.c
index fdc10dec753ccd7c55405c7240073d5a1afbb71c..cfd503dcea22dab32406e13ea88fcde3efb80fcf 100644
--- a/gtests/net/packetdrill/packet_to_string.c
+++ b/gtests/net/packetdrill/packet_to_string.c
@@ -45,7 +45,7 @@ static void endpoints_to_string(FILE *s, const struct packet *packet)
 static void packet_buffer_to_string(FILE *s, struct packet *packet)
 {
 	char *hex = NULL;
-	hex_dump(packet->buffer, packet->ip_bytes, &hex);
+	hex_dump(packet->buffer, packet_end(packet) - packet->buffer, &hex);
 	fputc('\n', s);
 	fprintf(s, "%s", hex);
 	free(hex);