Skip to content

Instantly share code, notes, and snippets.

@olavmrk
Created June 29, 2014 18:46
Show Gist options
  • Save olavmrk/2e4a3675b05ea89a11a0 to your computer and use it in GitHub Desktop.
Save olavmrk/2e4a3675b05ea89a11a0 to your computer and use it in GitHub Desktop.
Check padding of ulog_packet_msg_t
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#define IFNAMSIZ 16
#define ULOG_PREFIX_LEN 32
#define ULOG_MAC_LEN 80
typedef struct ulog_packet_msg {
unsigned long mark;
long timestamp_sec;
long timestamp_usec;
unsigned int hook;
char indev_name[IFNAMSIZ];
char outdev_name[IFNAMSIZ];
size_t data_len;
char prefix[ULOG_PREFIX_LEN];
unsigned char mac_len;
unsigned char mac[ULOG_MAC_LEN];
unsigned char payload[0];
} ulog_packet_msg_t;
int main() {
printf("sizeof(ulog_packet_msg_t) == %zu\n",
sizeof(ulog_packet_msg_t));
printf("Extra padding at end: %zu\n",
sizeof(ulog_packet_msg_t) - offsetof(ulog_packet_msg_t, payload));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment