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"
40 #define colorize_str(fore, text) \
41 colorize_start(fore) text colorize_end()
42 #define colorize_full_str(fore, back, text) \
43 colorize_start_full(fore, back) text colorize_end()
45 static inline int get_tty_size(void)
48 struct ttysize ts
= {0};
49 int ret
= ioctl(0, TIOCGSIZE
, &ts
);
50 return (ret
== 0 ? ts
.ts_cols
: DEFAULT_TTY_SIZE
);
51 #elif defined(TIOCGWINSZ)
52 struct winsize ts
= {0};
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 */
60 static inline void set_tty_invisible(struct termios
*orig
)
64 setvbuf(stdout
, NULL
, _IONBF
,0);
67 memcpy(&now
, orig
, sizeof(*orig
));
68 now
.c_lflag
&= ~(ISIG
| ICANON
| ECHO
);
71 tcsetattr(0, TCSANOW
, &now
);
74 static inline void set_tty_visible(struct termios
*orig
)
76 tcsetattr(0, TCSANOW
, orig
);