Skip to content

Commit 7a13c07

Browse files
committed
netdissect: expand comments for some macros.
Note that ND_BYTES_BETWEEN() returns 0 if the second pointer is past the first pointer. Note that ND_BYTES_AVAILABLE_AFTER() returns 0 if the pointer is before the *beginning* of the packet data.
1 parent 181b64b commit 7a13c07

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

netdissect.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,20 @@ if (!ND_TTEST_LEN(p, l)) goto trunc; \
402402
#define ND_TCHECK_SIZE(p) ND_TCHECK_LEN(p, sizeof(*(p)))
403403

404404
/*
405-
* Number of bytes between two pointers.
405+
* Number of bytes between two pointers, if p1 points to an address after
406+
* p2; zero otherwise.
407+
*
408+
* The result must fit in a u_int; the difference is never negative,
409+
* and must be able to handle the full size of an address space, so
410+
* the signed ptrdiff_t is not appropriate.
406411
*/
407412
#define ND_BYTES_BETWEEN(p1, p2) ((const u_char *)(p1) >= (const u_char *)(p2) ? 0 : ((u_int)(((const u_char *)(p2)) - (const u_char *)(p1))))
408413

409414
/*
410415
* Number of bytes remaining in the captured data, starting at the
411416
* byte pointed to by the argument.
417+
*
418+
* Returns 0 if the pointer is before the *beginning* of the packet.
412419
*/
413420
#define ND_BYTES_AVAILABLE_AFTER(p) ((const u_char *)(p) < ndo->ndo_packetp ? 0 : ND_BYTES_BETWEEN((p), ndo->ndo_snapend))
414421

0 commit comments

Comments
 (0)