summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdw <>2013-11-19 11:11:10 +0000
committerpdw <>2013-11-19 11:11:10 +0000
commit940bdcca64895827058d616699bf2e8f48526021 (patch)
treeaaec94d3ae29316849ac4f4f934415291ecda9a8
parentaf3ed6ff48f5cb6a13f78027ed83fe5ed1618126 (diff)
downloadiftop-940bdcca64895827058d616699bf2e8f48526021.zip
Put IPv6 address in square brackets if showing port number.
-rw-r--r--ui.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/ui.c b/ui.c
index 032d557..86c3e51 100644
--- a/ui.c
+++ b/ui.c
@@ -563,7 +563,7 @@ void analyse_data() {
}
-void sprint_host(char * line, int af, struct in6_addr* addr, unsigned int port, unsigned int protocol, int L) {
+void sprint_host(char * line, int af, struct in6_addr* addr, unsigned int port, unsigned int protocol, int L, int unspecified_as_star) {
char hostname[HOSTNAME_LENGTH];
char service[HOSTNAME_LENGTH];
char* s_name;
@@ -575,7 +575,7 @@ void sprint_host(char * line, int af, struct in6_addr* addr, unsigned int port,
ip_service skey;
int left;
- if(IN6_IS_ADDR_UNSPECIFIED(addr)) {
+ if(IN6_IS_ADDR_UNSPECIFIED(addr) && unspecified_as_star) {
sprintf(hostname, " * ");
}
else {
@@ -599,9 +599,16 @@ void sprint_host(char * line, int af, struct in6_addr* addr, unsigned int port,
else {
service[0] = '\0';
}
-
-
- sprintf(line, "%-*s", L, hostname);
+
+ /* If we're showing IPv6 addresses with a port number, put them in square
+ * brackets. */
+ if(port == 0 || af == AF_INET || L < 2) {
+ sprintf(line, "%-*s", L, hostname);
+ }
+ else {
+ sprintf(line, "[%-.*s]", L-2, hostname);
+ left += 2;
+ }
if(left > (L - strlen(service))) {
left = L - strlen(service);
if(left < 0) {
@@ -669,11 +676,11 @@ void ui_print() {
sprint_host(host1, screen_line->ap.af,
&(screen_line->ap.src6),
screen_line->ap.src_port,
- screen_line->ap.protocol, L);
+ screen_line->ap.protocol, L, options.aggregate_src);
sprint_host(host2, screen_line->ap.af,
&(screen_line->ap.dst6),
screen_line->ap.dst_port,
- screen_line->ap.protocol, L);
+ screen_line->ap.protocol, L, options.aggregate_dest);
if(!screen_filter_match(host1) && !screen_filter_match(host2)) {
continue;