Lines 58-63
Link Here
|
58 |
* |
58 |
* |
59 |
*990420 {1.38} Tuan Hoang removed a useless assignment from igmp_do_one() |
59 |
*990420 {1.38} Tuan Hoang removed a useless assignment from igmp_do_one() |
60 |
*20010404 {1.39} Arnaldo Carvalho de Melo - use setlocale |
60 |
*20010404 {1.39} Arnaldo Carvalho de Melo - use setlocale |
|
|
61 |
*20041011 {1.39} Kalin KOZHUHAROV <kalin@thinrope.net> |
62 |
* cleaned up code for printing by defining some macros |
63 |
* fixed truncating of IPv4 addresses mapped into IPv6 |
64 |
* FIXME: write a better printer for column output :-| |
65 |
* |
61 |
* |
66 |
* |
62 |
* This program is free software; you can redistribute it |
67 |
* This program is free software; you can redistribute it |
63 |
* and/or modify it under the terms of the GNU General |
68 |
* and/or modify it under the terms of the GNU General |
Lines 95-100
Link Here
|
95 |
#include "interface.h" |
100 |
#include "interface.h" |
96 |
#include "util.h" |
101 |
#include "util.h" |
97 |
|
102 |
|
|
|
103 |
/* Usually an IPv4 socket address can be represented as aaa.bbb.ccc.ddd:ppppp or |
104 |
15+1+5+'\0'=22 octets. However with IPv6 this becomes 45+1+5+'\0'=52 octets max |
105 |
if we keep the same number of ports (see /usr/include/netinet/in.h for |
106 |
INET_ADDRSTRLEN and INET6_ADDRSTRLEN ). */ |
107 |
|
108 |
/* For now let's try to keep the old behaviour of aligning (if possible) to 23rd |
109 |
column, but WITHOUT truncating the output (of longer addresses). |
110 |
But why 23 and not 22 ??? |
111 |
FIXME: Make a better macro for ALIGN_AT_LEN_FORMAT below */ |
112 |
#define ALIGN_AT_LEN 23 |
113 |
#define ALIGN_AT_LEN_FORMAT "%-23s" |
114 |
#define SPRINT_ADDRESS(addr) \ |
115 |
{char tmp_str[128]; \ |
116 |
if (strlen(addr) <= ALIGN_AT_LEN) { \ |
117 |
sprintf(tmp_str, ALIGN_AT_LEN_FORMAT,addr); \ |
118 |
safe_strncpy(addr,tmp_str,sizeof(addr)); \ |
119 |
}} |
120 |
|
121 |
/* Cut addresses at the length below to prevent possible (?) buffer overflows. |
122 |
52 is enough (<<128), but why is it needed at all? It was 22 in v1.39 */ |
123 |
#define CUT_AT_LEN 66 |
124 |
#define CUT_ADDR_AT_LEN(which) \ |
125 |
if ((strlen(which) + strlen(buffer)) > CUT_AT_LEN)\ |
126 |
which[CUT_AT_LEN - strlen(buffer)] = '\0'; |
127 |
|
98 |
#define PROGNAME_WIDTH 20 |
128 |
#define PROGNAME_WIDTH 20 |
99 |
|
129 |
|
100 |
#if !defined(s6_addr32) && defined(in6a_words) |
130 |
#if !defined(s6_addr32) && defined(in6a_words) |
Lines 772-788
Link Here
|
772 |
get_sname(htons(local_port), "tcp", |
802 |
get_sname(htons(local_port), "tcp", |
773 |
flag_not & FLAG_NUM_PORT)); |
803 |
flag_not & FLAG_NUM_PORT)); |
774 |
|
804 |
|
775 |
if ((strlen(local_addr) + strlen(buffer)) > 22) |
805 |
CUT_ADDR_AT_LEN(local_addr) |
776 |
local_addr[22 - strlen(buffer)] = '\0'; |
|
|
777 |
|
778 |
strcat(local_addr, ":"); |
806 |
strcat(local_addr, ":"); |
779 |
strcat(local_addr, buffer); |
807 |
strcat(local_addr, buffer); |
780 |
snprintf(buffer, sizeof(buffer), "%s", |
808 |
snprintf(buffer, sizeof(buffer), "%s", |
781 |
get_sname(htons(rem_port), "tcp", flag_not & FLAG_NUM_PORT)); |
809 |
get_sname(htons(rem_port), "tcp", flag_not & FLAG_NUM_PORT)); |
782 |
|
810 |
|
783 |
if ((strlen(rem_addr) + strlen(buffer)) > 22) |
811 |
CUT_ADDR_AT_LEN(rem_addr) |
784 |
rem_addr[22 - strlen(buffer)] = '\0'; |
|
|
785 |
|
786 |
strcat(rem_addr, ":"); |
812 |
strcat(rem_addr, ":"); |
787 |
strcat(rem_addr, buffer); |
813 |
strcat(rem_addr, buffer); |
788 |
timers[0] = '\0'; |
814 |
timers[0] = '\0'; |
Lines 813-819
Link Here
|
813 |
timer_run, (double) time_len / HZ, retr, timeout); |
839 |
timer_run, (double) time_len / HZ, retr, timeout); |
814 |
break; |
840 |
break; |
815 |
} |
841 |
} |
816 |
printf("tcp %6ld %6ld %-23s %-23s %-12s", |
842 |
SPRINT_ADDRESS(local_addr) |
|
|
843 |
SPRINT_ADDRESS(rem_addr) |
844 |
printf("tcp %6ld %6ld %s %s %-12s", |
817 |
rxq, txq, local_addr, rem_addr, _(tcp_state[state])); |
845 |
rxq, txq, local_addr, rem_addr, _(tcp_state[state])); |
818 |
|
846 |
|
819 |
finish_this_one(uid,inode,timers); |
847 |
finish_this_one(uid,inode,timers); |
Lines 922-929
Link Here
|
922 |
snprintf(buffer, sizeof(buffer), "%s", |
950 |
snprintf(buffer, sizeof(buffer), "%s", |
923 |
get_sname(htons(local_port), "udp", |
951 |
get_sname(htons(local_port), "udp", |
924 |
flag_not & FLAG_NUM_PORT)); |
952 |
flag_not & FLAG_NUM_PORT)); |
925 |
if ((strlen(local_addr) + strlen(buffer)) > 22) |
953 |
|
926 |
local_addr[22 - strlen(buffer)] = '\0'; |
954 |
CUT_ADDR_AT_LEN(local_addr) |
927 |
strcat(local_addr, ":"); |
955 |
strcat(local_addr, ":"); |
928 |
strcat(local_addr, buffer); |
956 |
strcat(local_addr, buffer); |
929 |
|
957 |
|
Lines 931-938
Link Here
|
931 |
get_sname(htons(rem_port), "udp", flag_not & FLAG_NUM_PORT)); |
959 |
get_sname(htons(rem_port), "udp", flag_not & FLAG_NUM_PORT)); |
932 |
safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, |
960 |
safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, |
933 |
flag_not), sizeof(rem_addr)); |
961 |
flag_not), sizeof(rem_addr)); |
934 |
if ((strlen(rem_addr) + strlen(buffer)) > 22) |
962 |
|
935 |
rem_addr[22 - strlen(buffer)] = '\0'; |
963 |
CUT_ADDR_AT_LEN(rem_addr) |
936 |
strcat(rem_addr, ":"); |
964 |
strcat(rem_addr, ":"); |
937 |
strcat(rem_addr, buffer); |
965 |
strcat(rem_addr, buffer); |
938 |
|
966 |
|
Lines 953-959
Link Here
|
953 |
retr, timeout); |
981 |
retr, timeout); |
954 |
break; |
982 |
break; |
955 |
} |
983 |
} |
956 |
printf("udp %6ld %6ld %-23s %-23s %-12s", |
984 |
SPRINT_ADDRESS(local_addr) |
|
|
985 |
SPRINT_ADDRESS(rem_addr) |
986 |
printf("udp %6ld %6ld %s %s %-12s", |
957 |
rxq, txq, local_addr, rem_addr, udp_state); |
987 |
rxq, txq, local_addr, rem_addr, udp_state); |
958 |
|
988 |
|
959 |
finish_this_one(uid,inode,timers); |
989 |
finish_this_one(uid,inode,timers); |
Lines 1041-1048
Link Here
|
1041 |
flag_not & FLAG_NUM_PORT)); |
1071 |
flag_not & FLAG_NUM_PORT)); |
1042 |
safe_strncpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, |
1072 |
safe_strncpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, |
1043 |
flag_not), sizeof(local_addr)); |
1073 |
flag_not), sizeof(local_addr)); |
1044 |
if ((strlen(local_addr) + strlen(buffer)) > 22) |
1074 |
|
1045 |
local_addr[22 - strlen(buffer)] = '\0'; |
1075 |
CUT_ADDR_AT_LEN(local_addr) |
1046 |
strcat(local_addr, ":"); |
1076 |
strcat(local_addr, ":"); |
1047 |
strcat(local_addr, buffer); |
1077 |
strcat(local_addr, buffer); |
1048 |
|
1078 |
|
Lines 1050-1057
Link Here
|
1050 |
get_sname(htons(rem_port), "raw", flag_not & FLAG_NUM_PORT)); |
1080 |
get_sname(htons(rem_port), "raw", flag_not & FLAG_NUM_PORT)); |
1051 |
safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, |
1081 |
safe_strncpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, |
1052 |
flag_not), sizeof(rem_addr)); |
1082 |
flag_not), sizeof(rem_addr)); |
1053 |
if ((strlen(rem_addr) + strlen(buffer)) > 22) |
1083 |
|
1054 |
rem_addr[22 - strlen(buffer)] = '\0'; |
1084 |
CUT_ADDR_AT_LEN(rem_addr) |
1055 |
strcat(rem_addr, ":"); |
1085 |
strcat(rem_addr, ":"); |
1056 |
strcat(rem_addr, buffer); |
1086 |
strcat(rem_addr, buffer); |
1057 |
|
1087 |
|
Lines 1074-1080
Link Here
|
1074 |
retr, timeout); |
1104 |
retr, timeout); |
1075 |
break; |
1105 |
break; |
1076 |
} |
1106 |
} |
1077 |
printf("raw %6ld %6ld %-23s %-23s %-12d", |
1107 |
SPRINT_ADDRESS(local_addr) |
|
|
1108 |
SPRINT_ADDRESS(rem_addr) |
1109 |
printf("raw %6ld %6ld %s %s %-12d", |
1078 |
rxq, txq, local_addr, rem_addr, state); |
1110 |
rxq, txq, local_addr, rem_addr, state); |
1079 |
|
1111 |
|
1080 |
finish_this_one(uid,inode,timers); |
1112 |
finish_this_one(uid,inode,timers); |