A Packet Reading Loop

// loop forever, reading packets.
while (1) {
    int msg_type;

    rc = ipq_read(h, buf, BUFSIZE, 0);
    if (rc < 0) {
        ipq_perror("ipq_read:");
        ipq_destroy_handle(h);
        exit(1);
    }

    msg_type = ipq_message_type(buf);
    switch (msg_type) {
        case NLMSG_ERROR:
            fprintf(stderr, "ipq_read got error %d",
                    ipq_get_msgerr(buf));
            break;
        case IPQM_PACKET:
            {
                ipq_packet_msg_t* msg = ipq_get_packet(buf);
                rc = ipq_set_verdict(h, msg->packet_id, NF_ACCEPT, 0, NULL);
            }
            break;
        default:
            fprintf(stderr, "unknown ipq msg type %d\n", msg_type);
    }
}
Originally written by Valid HTML 4.01!guy keren