2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
13 #include <sys/ioctl.h>
15 #define DEFAULT_TTY_SIZE 80
24 #define __magenta "35"
27 #define __on_black "40"
29 #define __on_green "42"
30 #define __on_yellow "43"
31 #define __on_blue "44"
32 #define __on_magenta "45"
33 #define __on_cyan "46"
34 #define __on_white "47"
36 #define colorize_start(fore) "\033[" __##fore "m"
37 #define colorize_start_full(fore, back) "\033[" __##fore ";" __on_##back "m"
38 #define colorize_end() "\033[" __reset "m"
39 #define colorize_str(fore, text) \
40 colorize_start(fore) text colorize_end()
41 #define colorize_full_str(fore, back, text) \
42 colorize_start_full(fore, back) text colorize_end()
44 static inline int get_tty_size(void)
47 struct ttysize ts
= {0};
48 int ret
= ioctl(0, TIOCGSIZE
, &ts
);
49 return (ret
== 0 ? ts
.ts_cols
: DEFAULT_TTY_SIZE
);
50 #elif defined(TIOCGWINSZ)
52 memset(&ts
, 0, sizeof(ts
));
53 int ret
= ioctl(0, TIOCGWINSZ
, &ts
);
54 return (ret
== 0 ? ts
.ws_col
: DEFAULT_TTY_SIZE
);
56 return DEFAULT_TTY_SIZE
;
57 #endif /* TIOCGSIZE */