[netsniff-ng] [PATCH 4/5] screen: Add helpers to easy use color by name

2016-03-23 Thread Vadim Kochan
Added macros which allow easy specify color pair like:

INIT_COLOR(YELLOW, BLACK);
COLOR(YELLOW, BLACK);
COLOR_ON(YELLOW, BLACK);

by calculating pair id via generic formula. Added shorter
color names via new enum.

Signed-off-by: Vadim Kochan 
---
 screen.h | 17 +
 1 file changed, 17 insertions(+)

diff --git a/screen.h b/screen.h
index 7a647be..f5a15d4 100644
--- a/screen.h
+++ b/screen.h
@@ -3,6 +3,23 @@
 
 #include 
 
+enum colors {
+   BLACK   = COLOR_BLACK,
+   RED = COLOR_RED,
+   GREEN   = COLOR_GREEN,
+   YELLOW  = COLOR_YELLOW,
+   BLUE= COLOR_BLUE,
+   MAGENTA = COLOR_MAGENTA,
+   CYAN= COLOR_CYAN,
+   WHITE   = COLOR_WHITE,
+};
+
+#define COLOR_MASK(fg, bg) ((fg) + (bg) * (COLOR_WHITE + 1))
+#define COLOR(fg, bg) COLOR_PAIR(COLOR_MASK((fg), (bg)))
+#define INIT_COLOR(fg, bg) init_pair(COLOR_MASK((fg), (bg)), (fg), (bg))
+#define COLOR_ON(fg, bg) attron(COLOR(fg, bg))
+#define COLOR_OFF(fg, bg) attroff(COLOR(fg, bg))
+
 extern WINDOW *screen_init(bool israw);
 extern void screen_end(void);
 
-- 
2.6.3

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] [PATCH 0/5] flowtop: Layout change to 1-row view

2016-03-23 Thread Vadim Kochan
Changed flows list layout to look more a top-like output
with header and in 1 line. When -s option is specified
then layout changes to 2 lines view including with src peer
info and dst under it on next line.

Also shortified flow state names to allocate less space.

Removed presenter_get_port be cause ports are printed for both peers
separately.

The flow duration time is printed in very short form in one of the
units:
XXd - days
XXh - hours
XXm - minutes
XXs - seconds

the reason is that it is enough to have actually generic understanding
about flow time in the biggest time unit.

Vadim Kochan (5):
  geoip: Allow to get country 3-code
  flowtop: Change flows layout to 1-row view
  flowtop: Add display option to show src info
  screen: Add helpers to easy use color by name
  flowtop: Use new colors naming & helpers

 flowtop.c | 437 ++
 geoip.c   |  14 ++
 geoip.h   |   2 +
 screen.h  |  17 +++
 4 files changed, 244 insertions(+), 226 deletions(-)

-- 
2.6.3

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] [PATCH 2/5] flowtop: Change flows layout to 1-row view

2016-03-23 Thread Vadim Kochan
Changed flows list layout to look more a top-like output
with header and in 1 line. When -s option is specified
then layout changes to 2 lines view including with src peer
info and dst under it on next line.

Also shortified flow state names to allocate less space.

Removed presenter_get_port be cause ports are printed for both peers
separately.

The flow duration time is printed in very short form in one of the
units:
XXd - days
XXh - hours
XXm - minutes
XXs - seconds

the reason is that it is enough to have actually generic understanding
about flow time in the biggest time unit.

Signed-off-by: Vadim Kochan 
---
 flowtop.c | 405 ++
 1 file changed, 194 insertions(+), 211 deletions(-)

diff --git a/flowtop.c b/flowtop.c
index 4c15c06..8201321 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -62,6 +62,7 @@ struct flow_entry {
uint64_t pkts_dst, bytes_dst;
uint64_t timestamp_start, timestamp_stop;
char country_src[128], country_dst[128];
+   char country_code_src[4], country_code_dst[4];
char city_src[128], city_dst[128];
char rev_dns_src[256], rev_dns_dst[256];
char procname[256];
@@ -166,11 +167,6 @@ static const char *copyright = "Please report bugs to 


[netsniff-ng] [PATCH 1/5] geoip: Allow to get country 3-code

2016-03-23 Thread Vadim Kochan
Add func to get country code-3 name by IPv4/6 address

Signed-off-by: Vadim Kochan 
---
 geoip.c | 14 ++
 geoip.h |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/geoip.c b/geoip.c
index ee654a6..917b1a7 100644
--- a/geoip.c
+++ b/geoip.c
@@ -339,6 +339,20 @@ const char *geoip6_country_name(struct sockaddr_in6 *sa)
return GeoIP_country_name_by_ipnum_v6(gi6_country, sa->sin6_addr);
 }
 
+const char *geoip4_country_code3_name(struct sockaddr_in *sa)
+{
+   bug_on(gi4_country == NULL);
+
+   return GeoIP_country_code3_by_ipnum(gi4_country, 
ntohl(sa->sin_addr.s_addr));
+}
+
+const char *geoip6_country_code3_name(struct sockaddr_in6 *sa)
+{
+   bug_on(gi6_country == NULL);
+
+   return GeoIP_country_code3_by_ipnum_v6(gi6_country, sa->sin6_addr);
+}
+
 static int fdout, fderr;
 
 /* GeoIP people were too stupid to come to the idea that you could set
diff --git a/geoip.h b/geoip.h
index 66ed20b..0cbd619 100644
--- a/geoip.h
+++ b/geoip.h
@@ -17,6 +17,8 @@ extern const char *geoip4_region_name(struct sockaddr_in *sa);
 extern const char *geoip6_region_name(struct sockaddr_in6 *sa);
 extern const char *geoip4_country_name(struct sockaddr_in *sa);
 extern const char *geoip6_country_name(struct sockaddr_in6 *sa);
+extern const char *geoip4_country_code3_name(struct sockaddr_in *sa);
+extern const char *geoip6_country_code3_name(struct sockaddr_in6 *sa);
 extern float geoip4_longitude(struct sockaddr_in *sa);
 extern float geoip4_latitude(struct sockaddr_in *sa);
 extern float geoip6_longitude(struct sockaddr_in6 *sa);
-- 
2.6.3

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] [PATCH 5/5] flowtop: Use new colors naming & helpers

2016-03-23 Thread Vadim Kochan
Use new colors definitions via enum variables instead of
numbers which helps to undrerstand better which kind
of color is used.

Signed-off-by: Vadim Kochan 
---
 flowtop.c | 42 +-
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/flowtop.c b/flowtop.c
index a810919..aa90733 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -881,29 +881,29 @@ static char *time2str(uint64_t tstamp, char *str, size_t 
len)
 static void print_flow_peer_info(const struct flow_entry *n, int y, int x,
 enum flow_direction dir)
 {
-   int counters_color = COLOR_PAIR(3);
-   int country_color = COLOR_PAIR(4);
+   int counters_color = COLOR(YELLOW, BLACK);
+   int src_color = COLOR(RED, BLACK);
+   int dst_color = COLOR(BLUE, BLACK);
+   int country_color = COLOR(GREEN, BLACK);
int port_color = A_BOLD;
const char *str = NULL;
uint16_t port = 0;
char tmp[128];
 
if (show_src && dir == FLOW_DIR_SRC) {
-   counters_color = COLOR_PAIR(1);
-   country_color = COLOR_PAIR(1);
-   port_color |= COLOR_PAIR(1);
+   country_color = counters_color = src_color;
+   port_color |= src_color;
} else if (show_src && FLOW_DIR_DST) {
-   counters_color = COLOR_PAIR(2);
-   country_color = COLOR_PAIR(2);
-   port_color |= COLOR_PAIR(2);
+   country_color = counters_color = dst_color;
+   port_color |= dst_color;
}
 
mvprintw(y, x, "");
 
/* Reverse DNS/IP */
-   attron(COLOR_PAIR(dir == FLOW_DIR_SRC ? 1 : 2));
+   attron(dir == FLOW_DIR_SRC ? src_color : dst_color);
printw(" %-*.*s", 50, 50, SELFLD(dir, rev_dns_src, rev_dns_dst));
-   attroff(COLOR_PAIR(dir == FLOW_DIR_SRC ? 1 : 2));
+   attroff(dir == FLOW_DIR_SRC ? src_color : dst_color);
 
/* Application port */
port = SELFLD(dir, port_src, port_dst);
@@ -955,15 +955,15 @@ static void draw_flow_entry(WINDOW *scr, const struct 
flow_entry *n, int line)
mvwprintw(scr, line, 0, "");
 
/* Application */
-   attron(COLOR_PAIR(3));
+   COLOR_ON(YELLOW, BLACK);
printw("%-*.*s", 10, 10, n->procname);
-   attroff(COLOR_PAIR(3));
+   COLOR_OFF(YELLOW, BLACK);
 
/* L4 protocol */
printw(" %-*.*s", 6, 6, l4proto2str[n->l4_proto]);
 
/* L4 protocol state */
-   attron(COLOR_PAIR(3));
+   COLOR_ON(YELLOW, BLACK);
switch (n->l4_proto) {
case IPPROTO_TCP:
str = tcp_state2str[n->tcp_state];
@@ -982,7 +982,7 @@ static void draw_flow_entry(WINDOW *scr, const struct 
flow_entry *n, int line)
break;
}
printw(" %-*.*s", 4, 4, str);
-   attroff(COLOR_PAIR(3));
+   COLOR_OFF(YELLOW, BLACK);
 
/* Time */
printw(" %*.*s", 4, 4, time2str(n->timestamp_start, tmp, sizeof(tmp)));
@@ -1054,7 +1054,7 @@ static inline bool presenter_flow_wrong_state(struct 
flow_entry *n)
 
 static void draw_flows_header(WINDOW *scr, int line)
 {
-   attron(COLOR_PAIR(5));
+   COLOR_ON(BLACK, GREEN);
 
mvwprintw(scr, line, 0, "%-*.*s", cols, cols, "");
mvwprintw(scr, line, 0, "");
@@ -1069,7 +1069,7 @@ static void draw_flows_header(WINDOW *scr, int line)
wprintw(scr, " %*.*s", 10, 10, "BYTES");
wprintw(scr, " %*.*s", 10, 10, "RATE");
 
-   attroff(COLOR_PAIR(5));
+   COLOR_OFF(BLACK, GREEN);
 }
 
 static void draw_flows(WINDOW *screen, struct flow_list *fl,
@@ -1249,11 +1249,11 @@ static void presenter(void)
screen = screen_init(false);
 
start_color();
-   init_pair(1, COLOR_RED, COLOR_BLACK);
-   init_pair(2, COLOR_BLUE, COLOR_BLACK);
-   init_pair(3, COLOR_YELLOW, COLOR_BLACK);
-   init_pair(4, COLOR_GREEN, COLOR_BLACK);
-   init_pair(5, COLOR_BLACK, COLOR_GREEN);
+   INIT_COLOR(RED, BLACK);
+   INIT_COLOR(BLUE, BLACK);
+   INIT_COLOR(YELLOW, BLACK);
+   INIT_COLOR(GREEN, BLACK);
+   INIT_COLOR(BLACK, GREEN);
 
rcu_register_thread();
while (!sigint) {
-- 
2.6.3

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[netsniff-ng] [PATCH 3/5] flowtop: Add display option to show src info

2016-03-23 Thread Vadim Kochan
Add 's' key option to toggle source peer info at runtime,
behaviour is the same like for '-s' command line option.

Signed-off-by: Vadim Kochan 
---
 flowtop.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/flowtop.c b/flowtop.c
index 8201321..a810919 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -784,10 +784,8 @@ static void flow_entry_get_extended(struct flow_entry *n)
if (n->flow_id == 0)
return;
 
-   if (show_src) {
-   flow_entry_get_extended_revdns(n, FLOW_DIR_SRC);
-   flow_entry_get_extended_geo(n, FLOW_DIR_SRC);
-   }
+   flow_entry_get_extended_revdns(n, FLOW_DIR_SRC);
+   flow_entry_get_extended_geo(n, FLOW_DIR_SRC);
 
flow_entry_get_extended_revdns(n, FLOW_DIR_DST);
flow_entry_get_extended_geo(n, FLOW_DIR_DST);
@@ -1181,12 +1179,13 @@ static void draw_help(WINDOW *screen)
 
mvaddnstr(row + 11, col + 3, "b Toggle rate units (bits/bytes)", 
-1);
mvaddnstr(row + 12, col + 3, "a Toggle display of active flows 
(rate > 0) only", -1);
+   mvaddnstr(row + 13, col + 3, "s Toggle show source peer info", -1);
 
-   mvaddnstr(row + 14, col + 3, "T Toggle display TCP flows", -1);
-   mvaddnstr(row + 15, col + 3, "U Toggle display UDP flows", -1);
-   mvaddnstr(row + 16, col + 3, "D Toggle display DCCP flows", -1);
-   mvaddnstr(row + 17, col + 3, "I Toggle display ICMP flows", -1);
-   mvaddnstr(row + 18, col + 3, "S Toggle display SCTP flows", -1);
+   mvaddnstr(row + 15, col + 3, "T Toggle display TCP flows", -1);
+   mvaddnstr(row + 16, col + 3, "U Toggle display UDP flows", -1);
+   mvaddnstr(row + 17, col + 3, "D Toggle display DCCP flows", -1);
+   mvaddnstr(row + 18, col + 3, "I Toggle display ICMP flows", -1);
+   mvaddnstr(row + 19, col + 3, "S Toggle display SCTP flows", -1);
 }
 
 static void draw_header(WINDOW *screen)
@@ -1292,6 +1291,9 @@ static void presenter(void)
case 'a':
show_active_only = !show_active_only;
break;
+   case 's':
+   show_src = !show_src;
+   break;
case '?':
show_help = !show_help;
wclear(screen);
-- 
2.6.3

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.