Skip to content

Commit 37745f6

Browse files
committed
frag6: Refactor duplicate code
Update a test output accordingly.
1 parent 429c68e commit 37745f6

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

print-frag6.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,13 @@ frag6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2)
4040
dp = (const struct ip6_frag *)bp;
4141
ip6 = (const struct ip6_hdr *)bp2;
4242

43-
if (ndo->ndo_vflag) {
44-
ND_PRINT("frag (0x%08x:%u|%zu)",
45-
GET_BE_U_4(dp->ip6f_ident),
46-
GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
47-
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
48-
(bp - bp2) - sizeof(struct ip6_frag));
49-
} else {
50-
ND_PRINT("frag (%u|%zu)",
51-
GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
52-
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
53-
(bp - bp2) - sizeof(struct ip6_frag));
54-
}
43+
ND_PRINT("frag (");
44+
if (ndo->ndo_vflag)
45+
ND_PRINT("0x%08x:", GET_BE_U_4(dp->ip6f_ident));
46+
ND_PRINT("%u|%zu)",
47+
GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
48+
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
49+
(bp - bp2) - sizeof(struct ip6_frag));
5550

5651
/* it is meaningless to decode non-first fragment */
5752
if ((GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK) != 0)

tests/ip6_frag_asan.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1 2038-01-01 00:00:00.000000 IP6 (class 0x51, flowlabel 0xb2100, hlim 16, next-header Fragment (44) payload length: 27136) 452:22:19:0:41a:e4ff:10ff:484d > 2243:80:1400:100:19:ffff:ffff:fffb: [|frag6]
1+
1 2038-01-01 00:00:00.000000 IP6 (class 0x51, flowlabel 0xb2100, hlim 16, next-header Fragment (44) payload length: 27136) 452:22:19:0:41a:e4ff:10ff:484d > 2243:80:1400:100:19:ffff:ffff:fffb: frag ( [|frag6]

0 commit comments

Comments
 (0)