Skip to content

Instantly share code, notes, and snippets.

Created January 9, 2019 05:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Trouble accessing C struct's fields
const c = @cImport ({
fn callback(queue: ?*c.nfq_q_handle, msg: ?[*]c.nfgenmsg, data: ?*c.nfq_data, arbitrary: ?*c_void) c_int {
const packet_header = try c.nfq_get_msg_packet_hdr(data) orelse return 0;
const packet_id = c.ntohl(packet_header.*.packet_id);
var payload: [*]u8 = undefined;
const payload_len = c.nfq_get_payload(data, @ptrCast(?[*]?[*]u8, &payload));
const payload_slice: []u8 = payload[0..@intCast(usize, payload_len)];
var test_packet: Packet = undefined;
_ = packets.parse_ip_packet(&test_packet, payload_slice);
// Attempting to access `id` field of nfq_q_handle struct here
if (queue.?.id == OUTPUT_QUEUE_ID) {
warn("OUT ");
} else {
warn("IN ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment