Skip to content

Instantly share code, notes, and snippets.

@bitwits
Created January 9, 2019 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitwits/7ee01acf4c13db2e8afd788eddc23770 to your computer and use it in GitHub Desktop.
Save bitwits/7ee01acf4c13db2e8afd788eddc23770 to your computer and use it in GitHub Desktop.
Trouble accessing C struct's fields
const c = @cImport ({
@cInclude("libnetfilter_queue/libnetfilter_queue.h");
});
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