I am looking to append timeval fields into my custom packet header. Facing issues with type conversion.
My custom fields in the header
struct pkthdr {
uint64_t sec;
uint64_t usec;
}
Linux timeval struct
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
}
Initialization
struct pkthdr *hdr;
struct timeval *tm;
gettimeofday(&tm, 0);
hdr->sec = htonl(tm->tv_sec);
hdr->usec = htonl(tm->tv_usec);
Following lines cause segmentation error
hdr->sec = htonl(tm->tv_sec);
hdr->usec = htonl(tm->tv_usec);