Skip to content

Commit

Permalink
source code files uncrustified
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Koeppe committed Oct 21, 2017
1 parent 36b4a6a commit 7ca2fc5
Show file tree
Hide file tree
Showing 333 changed files with 25,876 additions and 27,252 deletions.
170 changes: 85 additions & 85 deletions include/ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
#include <stdlib.h>

#ifdef OS_WINDOWS
#include <windows.h>
#include <windows.h>
#endif

#if defined OS_DARWIN || defined OS_BSD
#define PCAP_DONT_INCLUDE_PCAP_BPF_H 1
#include <net/bpf.h>
#define PCAP_DONT_INCLUDE_PCAP_BPF_H 1
#include <net/bpf.h>
#endif

#ifndef PATH_MAX
#define PATH_MAX 1024
#define PATH_MAX 1024
#endif

#if !defined (__USE_GNU) /* for memmem(), strsignal(), etc etc... */
#define __USE_GNU
#if !defined(__USE_GNU) /* for memmem(), strsignal(), etc etc... */
#define __USE_GNU
#endif
#ifdef OS_SOLARIS
#define _REENTRANT /* for strtok_r() */
#define _REENTRANT /* for strtok_r() */
#endif
#include <string.h>
#if defined (__USE_GNU)
#undef __USE_GNU
#if defined(__USE_GNU)
#undef __USE_GNU
#endif
#include <strings.h>
#include <unistd.h>
Expand All @@ -42,13 +42,13 @@
* used in plugins and functions in plugins must be declared as 'importable'
*/
#if defined(OS_WINDOWS)
#if defined(BUILDING_PLUGIN)
#define EC_API_EXTERN __declspec(dllimport)
#else
#define EC_API_EXTERN __declspec(dllexport)
#endif
#if defined(BUILDING_PLUGIN)
#define EC_API_EXTERN __declspec(dllimport)
#else
#define EC_API_EXTERN extern
#define EC_API_EXTERN __declspec(dllexport)
#endif
#else
#define EC_API_EXTERN extern
#endif

/* these are often needed... */
Expand All @@ -60,131 +60,133 @@
#include <ec_strings.h>

#ifdef OS_MINGW
#include <ec_os_mingw.h>
#include <ec_os_mingw.h>
#endif


/* wrappers for safe memory allocation */

#define SAFE_CALLOC(x, n, s) do { \
x = calloc(n, s); \
ON_ERROR(x, NULL, "virtual memory exhausted"); \
} while(0)

#define SAFE_MALLOC(x, s) do { \
x = malloc(s); \
ON_ERROR(x, NULL, "virtual memory exhausted"); \
} while (0)
#define SAFE_CALLOC(x, n, s) \
do { \
x = calloc(n, s); \
ON_ERROR(x, NULL, "virtual memory exhausted"); \
} while (0)

#define SAFE_REALLOC(x, s) do { \
x = realloc(x, s); \
ON_ERROR(x, NULL, "virtual memory exhausted"); \
} while(0)
#define SAFE_MALLOC(x, s) \
do { \
x = malloc(s); \
ON_ERROR(x, NULL, "virtual memory exhausted"); \
} while (0)

#define SAFE_STRDUP(x, s) do{ \
x = strdup(s); \
ON_ERROR(x, NULL, "virtual memory exhausted"); \
}while(0)
#define SAFE_REALLOC(x, s) \
do { \
x = realloc(x, s); \
ON_ERROR(x, NULL, "virtual memory exhausted"); \
} while (0)

#define SAFE_FREE(x) do{ if(x) { free(x); x = NULL; } }while(0)
#define SAFE_STRDUP(x, s) \
do { \
x = strdup(s); \
ON_ERROR(x, NULL, "virtual memory exhausted"); \
} while (0)

#define SAFE_FREE(x) do { if (x) { free(x); x = NULL; } } while (0)

/* convert to string */
#define EC_STRINGIFY(in) #in
#define EC_TOSTRING(in) EC_STRINGIFY(in)

// No need to have a priority in the constructor at this moment
/*
#if __GNUC_PREREQ(4,3)
#define __init __attribute__ ((constructor(101)))
#else
*/
#if __GNUC_PREREQ(4,3)
#define __init __attribute__ ((constructor(101)))
#else
*/
#define __init __attribute__ ((constructor))
//#endif
// #endif

#ifndef __set_errno
#define __set_errno(e) (errno = (e))
#endif

#define LOOP for(;;)
#define LOOP for (;;)

#define EXECUTE(x, ...) do{ if(x != NULL) x( __VA_ARGS__ ); }while(0)
#define EXECUTE(x, ...) do { if (x != NULL) x(__VA_ARGS__); } while (0)

/* couple of useful macros */
#ifndef offsetof
#define offsetof(type, member) ((size_t) &((type*)0)->member)
#define offsetof(type, member) ((size_t)&((type *)0)->member)
#endif
#ifndef containerof
#define containerof(ptr, type, member) ((type*)((char*)ptr - offsetof(type,member)))
#define containerof(ptr, type, member) ((type *)((char *)ptr - offsetof(type, member)))
#endif

/* min and max */

#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif

/* timeunit conversions */
#define SEC2NANO(x) x * 1000000000
#define MILLI2NANO(x) x * 1000000
#define MICRO2NANO(x) x * 1000
#define SEC2MICRO(x) x * 1000000
#define MILLI2MICRO(x) x * 1000
#define MILLI2SEC(x) x / 1000
#define MICRO2SEC(x) x / 1000000
#define MILLI2NANO(x) x * 1000000
#define MICRO2NANO(x) x * 1000
#define SEC2MICRO(x) x * 1000000
#define MILLI2MICRO(x) x * 1000
#define MILLI2SEC(x) x / 1000
#define MICRO2SEC(x) x / 1000000
#define NANO2SEC(x) x / 1000000000

/* file operations */
/* file operations */
#ifndef OS_WINDOWS
#define O_BINARY 0
#define O_BINARY 0
#endif

/* bit operations */

#define BIT_SET(r,b) ( r[b>>3] |= 1<<(b&7) )
#define BIT_RESET(r,b) ( r[b>>3] &= ~ 1<<(b&7) )
#define BIT_TEST(r,b) ( r[b>>3] & 1<<(b&7) )
#define BIT_NOT(r,b) ( r[b>>3] ^= 1<<(b&7) )
#define BIT_SET(r, b) (r[b >> 3] |= 1 << (b & 7))
#define BIT_RESET(r, b) (r[b >> 3] &= ~1 << (b & 7))
#define BIT_TEST(r, b) (r[b >> 3] & 1 << (b & 7))
#define BIT_NOT(r, b) (r[b >> 3] ^= 1 << (b & 7))

/* Save and restore relative offsets for pointers into a buffer */
#define SAVE_OFFSET(o,b) o=(u_int8 *)((int)o-(int)b)
#define RESTORE_OFFSET(o,b) o=(u_int8 *)((int)o+(int)b)
#define SAVE_OFFSET(o, b) o = (u_int8 *)((int)o - (int)b)
#define RESTORE_OFFSET(o, b) o = (u_int8 *)((int)o + (int)b)

/* ANSI colors */
#ifndef OS_WINDOWS
#define EC_COLOR_END "\033[0m"
#define EC_COLOR_BOLD "\033[1m"

#define EC_COLOR_RED "\033[31m"EC_COLOR_BOLD
#define EC_COLOR_YELLOW "\033[33m"EC_COLOR_BOLD
#define EC_COLOR_GREEN "\033[32m"EC_COLOR_BOLD
#define EC_COLOR_BLUE "\033[34m"EC_COLOR_BOLD
#define EC_COLOR_CYAN "\033[36m"EC_COLOR_BOLD
#define EC_COLOR_END "\033[0m"
#define EC_COLOR_BOLD "\033[1m"

#define EC_COLOR_RED "\033[31m"EC_COLOR_BOLD
#define EC_COLOR_YELLOW "\033[33m"EC_COLOR_BOLD
#define EC_COLOR_GREEN "\033[32m"EC_COLOR_BOLD
#define EC_COLOR_BLUE "\033[34m"EC_COLOR_BOLD
#define EC_COLOR_CYAN "\033[36m"EC_COLOR_BOLD
#else
/* Windows console doesn't grok ANSI */
#define EC_COLOR_END
#define EC_COLOR_BOLD
/* Windows console doesn't grok ANSI */
#define EC_COLOR_END
#define EC_COLOR_BOLD

#define EC_COLOR_RED
#define EC_COLOR_YELLOW
#define EC_COLOR_GREEN
#define EC_COLOR_BLUE
#define EC_COLOR_CYAN
#define EC_COLOR_RED
#define EC_COLOR_YELLOW
#define EC_COLOR_GREEN
#define EC_COLOR_BLUE
#define EC_COLOR_CYAN
#endif

/* magic numbers */

#ifndef RANDMAGIC
#define EC_MAGIC_8 0xec
#define EC_MAGIC_16 0xe77e
#define EC_MAGIC_32 0xe77ee77e
#define EC_MAGIC_8 0xec
#define EC_MAGIC_16 0xe77e
#define EC_MAGIC_32 0xe77ee77e
#else
#define EC_MAGIC_8 ((RANDMAGIC & 0x0ff0) >> 4)
#define EC_MAGIC_16 (RANDMAGIC & 0xffff)
#define EC_MAGIC_32 (((RANDMAGIC & 0xff) << 8)|((RANDMAGIC & 0xff00) >> 8)|(RANDMAGIC & 0xffff0000))
#define EC_MAGIC_8 ((RANDMAGIC & 0x0ff0) >> 4)
#define EC_MAGIC_16 (RANDMAGIC & 0xffff)
#define EC_MAGIC_32 (((RANDMAGIC & 0xff) << 8) | ((RANDMAGIC & 0xff00) >> 8) | (RANDMAGIC & 0xffff0000))
#endif

/* exported by ec_main */
Expand All @@ -193,10 +195,8 @@ EC_API_EXTERN void clean_exit(int errcode);
/* exported by ec_mem */
EC_API_EXTERN void safe_free_mem(char **param, int *param_length, char *command);


#endif /* EC_H */
#endif /* EC_H */

/* EOF */

// vim:ts=3:expandtab

1 change: 0 additions & 1 deletion include/ec_capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ EC_API_EXTERN void add_aligner(int dlt, int (*aligner)(void));
/* EOF */

// vim:ts=3:expandtab

1 change: 0 additions & 1 deletion include/ec_checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ EC_API_EXTERN u_int16 checksum_shouldbe(u_int16 sum, u_int16 computed_sum);
/* EOF */

// vim:ts=3:expandtab

2 changes: 0 additions & 2 deletions include/ec_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct conf_section {
struct conf_entry *entries;
};


/* exported functions */

EC_API_EXTERN void load_conf(void);
Expand All @@ -22,4 +21,3 @@ EC_API_EXTERN void conf_dissectors(void);
/* EOF */

// vim:ts=3:expandtab

2 changes: 0 additions & 2 deletions include/ec_connbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ EC_API_EXTERN int connbuf_add(struct conn_buf *cb, struct packet_object *po);
EC_API_EXTERN void connbuf_wipe(struct conn_buf *cb);
EC_API_EXTERN int connbuf_print(struct conn_buf *cb, void (*)(u_char *, size_t, struct ip_addr *));


#endif

/* EOF */

// vim:ts=3:expandtab

18 changes: 8 additions & 10 deletions include/ec_conntrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* conntrack hook definition */
struct ct_hook_list {
void (*func)(struct packet_object *po);
SLIST_ENTRY (ct_hook_list) next;
SLIST_ENTRY(ct_hook_list) next;
};

/* conntrack object */
Expand All @@ -19,11 +19,11 @@ struct conn_object {
/* mac addresses */
u_int8 L2_addr1[MEDIA_ADDR_LEN];
u_int8 L2_addr2[MEDIA_ADDR_LEN];

/* ip addresses */
struct ip_addr L3_addr1;
struct ip_addr L3_addr2;

/* port numbers */
u_int16 L4_addr1;
u_int16 L4_addr2;
Expand All @@ -36,7 +36,7 @@ struct conn_object {
u_int32 xferred; /* XXX: remove it some day */
u_int32 tx; /* from 1 to 2 */
u_int32 rx; /* from 2 to 1 */

/* connection status */
int status;

Expand All @@ -51,12 +51,11 @@ struct conn_object {
};

struct conn_tail {
struct conn_object *co;
struct conn_object *co;
struct conn_hash_search *cs;
TAILQ_ENTRY(conn_tail) next;
};


enum {
CONN_IDLE = 0,
CONN_OPENING = 1,
Expand All @@ -74,13 +73,13 @@ enum {
};

/* exported functions */
EC_API_EXTERN void * conntrack_print(int mode, void *list, char **desc, size_t len);
EC_API_EXTERN void * conntrack_get(int mode, void *list, struct conn_object **conn);
EC_API_EXTERN void *conntrack_print(int mode, void *list, char **desc, size_t len);
EC_API_EXTERN void *conntrack_get(int mode, void *list, struct conn_object **conn);
EC_API_EXTERN int conntrack_protostr(struct conn_object *conn, char *pstr, int len);
EC_API_EXTERN int conntrack_flagstr(struct conn_object *conn, char *pstr, int len);
EC_API_EXTERN int conntrack_statusstr(struct conn_object *conn, char *pstr, int len);
EC_API_EXTERN int conntrack_countrystr(struct conn_object *conn, char *pstr, int len);
EC_API_EXTERN EC_THREAD_FUNC(conntrack_timeouter);
EC_API_EXTERN EC_THREAD_FUNC(conntrack_timeouter);
EC_API_EXTERN void conntrack_purge(void);

EC_API_EXTERN int conntrack_hook_packet_add(struct packet_object *po, void (*func)(struct packet_object *po));
Expand All @@ -93,4 +92,3 @@ EC_API_EXTERN int conntrack_hook_conn_del(struct conn_object *co, void (*func)(s
/* EOF */

// vim:ts=3:expandtab

Loading

0 comments on commit 7ca2fc5

Please sign in to comment.