]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/capture/ipq_linux/libipq.h
Better logging for ipq_cap.
[stg.git] / projects / stargazer / plugins / capture / ipq_linux / libipq.h
1 /*
2  * libipq.h
3  *
4  * IPQ library for userspace.
5  *
6  * Author: James Morris <jmorris@intercode.com.au>
7  *
8  * Copyright (c) 2000-2001 Netfilter Core Team
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  */
21  
22 #ifndef _LIBIPQ_H
23 #define _LIBIPQ_H
24
25 #include <errno.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <sys/uio.h>
31 #include <asm/types.h>
32 #include <linux/netlink.h>
33
34 #ifdef KERNEL_64_USERSPACE_32
35 #include "ip_queue_64.h"
36 typedef u_int64_t ipq_id_t;
37 #else
38 #include <linux/netfilter_ipv4/ip_queue.h>
39 #endif
40 typedef unsigned long ipq_id_t;
41 #endif
42
43 #ifdef DEBUG_LIBIPQ
44 #include <stdio.h>
45 #define LDEBUG(x...) fprintf(stderr, ## x)
46 #else
47 #define LDEBUG(x...)
48 #endif  /* DEBUG_LIBIPQ */
49
50 /* FIXME: glibc sucks */
51 #ifndef MSG_TRUNC
52 #define MSG_TRUNC 0x20
53 #endif
54
55 struct ipq_handle
56 {
57         int fd;
58         u_int8_t blocking;
59         struct sockaddr_nl local;
60         struct sockaddr_nl peer;
61 };
62
63 struct ipq_handle *ipq_create_handle(u_int32_t flags, u_int32_t protocol);
64
65 int ipq_destroy_handle(struct ipq_handle *h);
66
67 ssize_t ipq_read(const struct ipq_handle *h,
68                 unsigned char *buf, size_t len, int timeout);
69
70 int ipq_set_mode(const struct ipq_handle *h, u_int8_t mode, size_t len);
71
72 ipq_packet_msg_t *ipq_get_packet(const unsigned char *buf);
73
74 int ipq_message_type(const unsigned char *buf);
75
76 int ipq_get_msgerr(const unsigned char *buf);
77
78 int ipq_set_verdict(const struct ipq_handle *h,
79                     ipq_id_t id,
80                     unsigned int verdict,
81                     size_t data_len,
82                     unsigned char *buf);
83
84 int ipq_ctl(const struct ipq_handle *h, int request, ...);
85
86 char *ipq_errstr(void);
87 //void ipq_perror(const char *s);
88
89 #endif  /* _LIBIPQ_H */
90