libipq.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifndef _LIBIPQ_H
  22. #define _LIBIPQ_H
  23. #include <errno.h>
  24. #include <unistd.h>
  25. #include <fcntl.h>
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28. #include <sys/uio.h>
  29. #include <asm/types.h>
  30. #include <linux/netlink.h>
  31. #include <linux/netfilter_ipv4/ip_queue.h>
  32. typedef unsigned long ipq_id_t;
  33. #ifdef DEBUG_LIBIPQ
  34. #include <stdio.h>
  35. #define LDEBUG(x...) fprintf(stderr, ## x)
  36. #else
  37. #define LDEBUG(x...)
  38. #endif /* DEBUG_LIBIPQ */
  39. /* FIXME: glibc sucks */
  40. #ifndef MSG_TRUNC
  41. #define MSG_TRUNC 0x20
  42. #endif
  43. struct ipq_handle
  44. {
  45. int fd;
  46. u_int8_t blocking;
  47. struct sockaddr_nl local;
  48. struct sockaddr_nl peer;
  49. };
  50. struct ipq_handle *ipq_create_handle(u_int32_t flags, u_int32_t protocol);
  51. int ipq_destroy_handle(struct ipq_handle *h);
  52. ssize_t ipq_read(const struct ipq_handle *h,
  53. unsigned char *buf, size_t len, int timeout);
  54. int ipq_set_mode(const struct ipq_handle *h, u_int8_t mode, size_t len);
  55. ipq_packet_msg_t *ipq_get_packet(const unsigned char *buf);
  56. int ipq_message_type(const unsigned char *buf);
  57. int ipq_get_msgerr(const unsigned char *buf);
  58. int ipq_set_verdict(const struct ipq_handle *h,
  59. ipq_id_t id,
  60. unsigned int verdict,
  61. size_t data_len,
  62. unsigned char *buf);
  63. int ipq_ctl(const struct ipq_handle *h, int request, ...);
  64. char *ipq_errstr(void);
  65. void ipq_perror(const char *s);
  66. #endif /* _LIBIPQ_H */