common.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (c) 2002 Damien Miller. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  14. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef _SFD_COMMON_H
  25. #define _SFD_COMMON_H
  26. #include "config.h"
  27. #define _BSD_SOURCE /* Needed for BSD-style struct ip,tcp,udp on Linux */
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30. #include <sys/ioctl.h>
  31. #include <sys/poll.h>
  32. #include <sys/socket.h>
  33. #include <sys/time.h>
  34. #include <sys/un.h>
  35. #include <netinet/in.h>
  36. #include <netinet/in_systm.h>
  37. #include <netinet/ip.h>
  38. #include <netinet/ip6.h>
  39. #include <netinet/ip_icmp.h>
  40. #include <netinet/tcp.h>
  41. #include <netinet/udp.h>
  42. #include <arpa/inet.h>
  43. #include <unistd.h>
  44. #include <stdlib.h>
  45. #include <errno.h>
  46. #include <fcntl.h>
  47. #include <grp.h>
  48. #include <netdb.h>
  49. #include <limits.h>
  50. #include <pwd.h>
  51. #include <signal.h>
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <syslog.h>
  55. #include <time.h>
  56. #if defined(HAVE_NET_BPF_H)
  57. #include <net/bpf.h>
  58. #elif defined(HAVE_PCAP_BPF_H)
  59. #include <pcap-bpf.h>
  60. #endif
  61. #if defined(HAVE_INTTYPES_H)
  62. #include <inttypes.h>
  63. #endif
  64. /* The name of the program */
  65. #define PROGNAME "softflowd"
  66. /* The name of the program */
  67. #define PROGVER "0.9.8"
  68. /* Default pidfile */
  69. #define DEFAULT_PIDFILE "/var/run/" PROGNAME ".pid"
  70. /* Default control socket */
  71. #define DEFAULT_CTLSOCK "/var/run/" PROGNAME ".ctl"
  72. #define RCSID(msg) \
  73. static /**/const char *const flowd_rcsid[] = \
  74. { (const char *)flowd_rcsid, "\100(#)" msg } \
  75. #ifndef IP_OFFMASK
  76. # define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
  77. #endif
  78. #ifndef IPV6_VERSION
  79. #define IPV6_VERSION 0x60
  80. #endif
  81. #ifndef IPV6_VERSION_MASK
  82. #define IPV6_VERSION_MASK 0xf0
  83. #endif
  84. #ifndef IPV6_FLOWINFO_MASK
  85. #define IPV6_FLOWINFO_MASK ntohl(0x0fffffff)
  86. #endif
  87. #ifndef IPV6_FLOWLABEL_MASK
  88. #define IPV6_FLOWLABEL_MASK ntohl(0x000fffff)
  89. #endif
  90. #ifndef _PATH_DEVNULL
  91. # define _PATH_DEVNULL "/dev/null"
  92. #endif
  93. #ifndef MIN
  94. # define MIN(a,b) (((a)<(b))?(a):(b))
  95. #endif
  96. #ifndef MAX
  97. # define MAX(a,b) (((a)>(b))?(a):(b))
  98. #endif
  99. #ifndef offsetof
  100. # define offsetof(type, member) ((size_t) &((type *)0)->member)
  101. #endif
  102. #if defined(__GNUC__)
  103. # ifndef __dead
  104. # define __dead __attribute__((__noreturn__))
  105. # endif
  106. # ifndef __packed
  107. # define __packed __attribute__((__packed__))
  108. # endif
  109. #endif
  110. #if !defined(HAVE_INT8_T) && defined(OUR_CFG_INT8_T)
  111. typedef OUR_CFG_INT8_T int8_t;
  112. #endif
  113. #if !defined(HAVE_INT16_T) && defined(OUR_CFG_INT16_T)
  114. typedef OUR_CFG_INT16_T int16_t;
  115. #endif
  116. #if !defined(HAVE_INT32_T) && defined(OUR_CFG_INT32_T)
  117. typedef OUR_CFG_INT32_T int32_t;
  118. #endif
  119. #if !defined(HAVE_INT64_T) && defined(OUR_CFG_INT64_T)
  120. typedef OUR_CFG_INT64_T int64_t;
  121. #endif
  122. #if !defined(HAVE_U_INT8_T) && defined(OUR_CFG_U_INT8_T)
  123. typedef OUR_CFG_U_INT8_T u_int8_t;
  124. #endif
  125. #if !defined(HAVE_U_INT16_T) && defined(OUR_CFG_U_INT16_T)
  126. typedef OUR_CFG_U_INT16_T u_int16_t;
  127. #endif
  128. #if !defined(HAVE_U_INT32_T) && defined(OUR_CFG_U_INT32_T)
  129. typedef OUR_CFG_U_INT32_T u_int32_t;
  130. #endif
  131. #if !defined(HAVE_U_INT64_T) && defined(OUR_CFG_U_INT64_T)
  132. typedef OUR_CFG_U_INT64_T u_int64_t;
  133. #endif
  134. #ifndef HAVE_STRLCPY
  135. size_t strlcpy(char *dst, const char *src, size_t siz);
  136. #endif
  137. #ifndef HAVE_STRLCAT
  138. size_t strlcat(char *dst, const char *src, size_t siz);
  139. #endif
  140. #ifndef HAVE_CLOSEFROM
  141. void closefrom(int lowfd);
  142. #endif
  143. #ifndef HAVE_STRUCT_IP6_EXT
  144. struct ip6_ext {
  145. u_int8_t ip6e_nxt;
  146. u_int8_t ip6e_len;
  147. } __packed;
  148. #endif
  149. #endif /* _SFD_COMMON_H */