This code try to print the timestamp of packet using
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
If this is UDP packet.
Is there any way that
CMSG_DATA(cmsg) will return NULL?
If you look at the definition of CMSG_DATA you see
#define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
This adds an offset to
Unless you manage to feed a
cmsg into that macro that evaluates to
NULL after adding that offset, the result can never be come
Answered By – Gerhardh