|
|
0a4baa |
diff -up net-tools-2.0/netstat.c.sctp net-tools-2.0/netstat.c
|
|
|
0a4baa |
--- net-tools-2.0/netstat.c.sctp 2013-09-23 15:14:59.524866201 +0200
|
|
|
0a4baa |
+++ net-tools-2.0/netstat.c 2013-09-23 15:24:20.259143969 +0200
|
|
|
0a4baa |
@@ -115,7 +115,7 @@
|
|
|
0a4baa |
#endif
|
|
|
0a4baa |
|
|
|
0a4baa |
/* prototypes for statistics.c */
|
|
|
0a4baa |
-int parsesnmp(int, int, int);
|
|
|
0a4baa |
+int parsesnmp(int, int, int, int);
|
|
|
0a4baa |
void inittab(void);
|
|
|
0a4baa |
int parsesnmp6(int, int, int);
|
|
|
0a4baa |
void inittab6(void);
|
|
|
0a4baa |
@@ -888,159 +888,269 @@ static int igmp_info(void)
|
|
|
0a4baa |
igmp_do_one, "igmp", "igmp6");
|
|
|
0a4baa |
}
|
|
|
0a4baa |
|
|
|
0a4baa |
-static int ip_parse_dots(uint32_t *addr, char const *src) {
|
|
|
0a4baa |
- unsigned a, b, c, d;
|
|
|
0a4baa |
- unsigned ret = 4-sscanf(src, "%u.%u.%u.%u", &a, &b, &c, &d);
|
|
|
0a4baa |
- *addr = htonl((a << 24)|(b << 16)|(c << 8)|d);
|
|
|
0a4baa |
- return ret;
|
|
|
0a4baa |
-}
|
|
|
0a4baa |
-
|
|
|
0a4baa |
-static void print_ip_service(struct sockaddr_in *addr, char const *protname,
|
|
|
0a4baa |
- char *buf, unsigned size) {
|
|
|
0a4baa |
- struct aftype *ap;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- if(size == 0) return;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* print host */
|
|
|
0a4baa |
- if((ap = get_afntype(addr->sin_family)) == NULL) {
|
|
|
0a4baa |
- fprintf(stderr, _("netstat: unsupported address family %d !\n"),
|
|
|
0a4baa |
- addr->sin_family);
|
|
|
0a4baa |
- return;
|
|
|
0a4baa |
- }
|
|
|
0a4baa |
- safe_strncpy(buf, ap->sprint((struct sockaddr*)addr, flag_not), size);
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* print service */
|
|
|
0a4baa |
- if(flag_all || (flag_lst && !addr->sin_port) || (!flag_lst && addr->sin_port)) {
|
|
|
0a4baa |
- char bfs[32];
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- snprintf(bfs, sizeof(bfs), "%s",
|
|
|
0a4baa |
- get_sname(addr->sin_port, (char*)protname, flag_not & FLAG_NUM_PORT));
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* check if we must cut on host and/or service name */
|
|
|
0a4baa |
- {
|
|
|
0a4baa |
- unsigned const bufl = strlen(buf);
|
|
|
0a4baa |
- unsigned const bfsl = strlen(bfs);
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- if(bufl+bfsl+2 > size) {
|
|
|
0a4baa |
- unsigned const half = (size-2)>>1;
|
|
|
0a4baa |
- if(bufl > half) {
|
|
|
0a4baa |
- if(bfsl > half) {
|
|
|
0a4baa |
- buf[size-2-half] = '\0';
|
|
|
0a4baa |
- bfs[half+1] = '\0';
|
|
|
0a4baa |
- }
|
|
|
0a4baa |
- else buf[size-2-bfsl] = '\0';
|
|
|
0a4baa |
- }
|
|
|
0a4baa |
- else bfs[size-2-bufl] = '\0';
|
|
|
0a4baa |
- }
|
|
|
0a4baa |
+static const char *sctp_socket_state_str(int state)
|
|
|
0a4baa |
+{
|
|
|
0a4baa |
+ if(state>=0 && state<=10)
|
|
|
0a4baa |
+ return tcp_state[state];
|
|
|
0a4baa |
+ else {
|
|
|
0a4baa |
+ static char state_str_buf[64];
|
|
|
0a4baa |
+ sprintf(state_str_buf,"UNKNOWN(%d)",state);
|
|
|
0a4baa |
+ return state_str_buf;
|
|
|
0a4baa |
}
|
|
|
0a4baa |
- strcat(buf, ":");
|
|
|
0a4baa |
- strcat(buf, bfs);
|
|
|
0a4baa |
- }
|
|
|
0a4baa |
}
|
|
|
0a4baa |
|
|
|
0a4baa |
-/* process single SCTP endpoint */
|
|
|
0a4baa |
-static void sctp_do_ept(int lnr, char const *line, const char *prot)
|
|
|
0a4baa |
+static struct aftype *process_sctp_addr_str(const char *addr_str, struct sockaddr *sa)
|
|
|
0a4baa |
{
|
|
|
0a4baa |
- struct sockaddr_in laddr, raddr;
|
|
|
0a4baa |
- unsigned uid, inode;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- char l_addr[23], r_addr[23];
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* fill sockaddr_in structures */
|
|
|
0a4baa |
- {
|
|
|
0a4baa |
- unsigned lport;
|
|
|
0a4baa |
- unsigned ate;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- if(lnr == 0) return;
|
|
|
0a4baa |
- if(sscanf(line, "%*X %*X %*u %*u %*u %u %u %u %n",
|
|
|
0a4baa |
- &lport, &uid, &inode, &ate) < 3) goto err;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* decode IP address */
|
|
|
0a4baa |
- if(ip_parse_dots(&laddr.sin_addr.s_addr, line+ate)) goto err;
|
|
|
0a4baa |
- raddr.sin_addr.s_addr = htonl(0);
|
|
|
0a4baa |
- laddr.sin_family = raddr.sin_family = AF_INET;
|
|
|
0a4baa |
- laddr.sin_port = htons(lport);
|
|
|
0a4baa |
- raddr.sin_port = htons(0);
|
|
|
0a4baa |
- }
|
|
|
0a4baa |
+ if (strchr(addr_str,':')) {
|
|
|
0a4baa |
+#if HAVE_AFINET6
|
|
|
0a4baa |
+ extern struct aftype inet6_aftype;
|
|
|
0a4baa |
+ /* Demangle what the kernel gives us */
|
|
|
0a4baa |
+ struct in6_addr in6;
|
|
|
0a4baa |
+ char addr6_str[INET6_ADDRSTRLEN];
|
|
|
0a4baa |
+ unsigned u0,u1,u2,u3,u4,u5,u6,u7;
|
|
|
0a4baa |
+ sscanf(addr_str, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X",
|
|
|
0a4baa |
+ &u0, &u1, &u2, &u3, &u4, &u5, &u6, &u7;;
|
|
|
0a4baa |
+ in6.s6_addr16[0] = htons(u0);
|
|
|
0a4baa |
+ in6.s6_addr16[1] = htons(u1);
|
|
|
0a4baa |
+ in6.s6_addr16[2] = htons(u2);
|
|
|
0a4baa |
+ in6.s6_addr16[3] = htons(u3);
|
|
|
0a4baa |
+ in6.s6_addr16[4] = htons(u4);
|
|
|
0a4baa |
+ in6.s6_addr16[5] = htons(u5);
|
|
|
0a4baa |
+ in6.s6_addr16[6] = htons(u6);
|
|
|
0a4baa |
+ in6.s6_addr16[7] = htons(u7);
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ inet_ntop(AF_INET6, &in6, addr6_str, sizeof(addr6_str));
|
|
|
0a4baa |
+ inet6_aftype.input(1, addr6_str, sa);
|
|
|
0a4baa |
+ sa->sa_family = AF_INET6;
|
|
|
0a4baa |
+#endif
|
|
|
0a4baa |
+ } else {
|
|
|
0a4baa |
+ ((struct sockaddr_in*)sa)->sin_addr.s_addr = inet_addr(addr_str);
|
|
|
0a4baa |
+ sa->sa_family = AF_INET;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ return get_afntype(sa->sa_family);
|
|
|
0a4baa |
+}
|
|
|
0a4baa |
|
|
|
0a4baa |
- /* print IP:service to l_addr and r_addr */
|
|
|
0a4baa |
- print_ip_service(&laddr, prot, l_addr, sizeof(l_addr));
|
|
|
0a4baa |
- print_ip_service(&raddr, prot, r_addr, sizeof(r_addr));
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* Print line */
|
|
|
0a4baa |
- printf("%-4s %6d %6d %-*s %-*s %-11s",
|
|
|
0a4baa |
- prot, 0, 0,
|
|
|
0a4baa |
- (int)netmax(23,strlen(l_addr)), l_addr,
|
|
|
0a4baa |
- (int)netmax(23,strlen(r_addr)), r_addr,
|
|
|
0a4baa |
- _(tcp_state[TCP_LISTEN]));
|
|
|
0a4baa |
- finish_this_one(uid, inode, "");
|
|
|
0a4baa |
- return;
|
|
|
0a4baa |
- err:
|
|
|
0a4baa |
- fprintf(stderr, "SCTP error in line: %d\n", lnr);
|
|
|
0a4baa |
-}
|
|
|
0a4baa |
-
|
|
|
0a4baa |
-/* process single SCTP association */
|
|
|
0a4baa |
-static void sctp_do_assoc(int lnr, char const *line, const char *prot)
|
|
|
0a4baa |
-{
|
|
|
0a4baa |
- struct sockaddr_in laddr, raddr;
|
|
|
0a4baa |
- unsigned long rxq, txq;
|
|
|
0a4baa |
- unsigned uid, inode;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- char l_addr[23], r_addr[23];
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* fill sockaddr_in structures */
|
|
|
0a4baa |
- {
|
|
|
0a4baa |
- unsigned lport, rport;
|
|
|
0a4baa |
- unsigned ate;
|
|
|
0a4baa |
- char const *addr;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- if(lnr == 0) return;
|
|
|
0a4baa |
- if(sscanf(line, "%*X %*X %*u %*u %*u %*u %*u %lu %lu %u %u %u %u %n",
|
|
|
0a4baa |
- &txq, &rxq, &uid, &inode, &lport, &rport, &ate) < 6) goto err;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* decode IP addresses */
|
|
|
0a4baa |
- addr = strchr(line+ate, '*');
|
|
|
0a4baa |
- if(addr == 0) goto err;
|
|
|
0a4baa |
- if(ip_parse_dots(&laddr.sin_addr.s_addr, ++addr)) goto err;
|
|
|
0a4baa |
- addr = strchr(addr, '*');
|
|
|
0a4baa |
- if(addr == 0) goto err;
|
|
|
0a4baa |
- if(ip_parse_dots(&raddr.sin_addr.s_addr, ++addr)) goto err;
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* complete sockaddr_in structures */
|
|
|
0a4baa |
- laddr.sin_family = raddr.sin_family = AF_INET;
|
|
|
0a4baa |
- laddr.sin_port = htons(lport);
|
|
|
0a4baa |
- raddr.sin_port = htons(rport);
|
|
|
0a4baa |
- }
|
|
|
0a4baa |
+static void sctp_eps_do_one(int lnr, char *line, const char *proto)
|
|
|
0a4baa |
+{
|
|
|
0a4baa |
+ char buffer[1024];
|
|
|
0a4baa |
+ int state, port;
|
|
|
0a4baa |
+ int uid;
|
|
|
0a4baa |
+ unsigned long inode;
|
|
|
0a4baa |
+ struct aftype *ap;
|
|
|
0a4baa |
+#if HAVE_AFINET6
|
|
|
0a4baa |
+ struct sockaddr_in6 localaddr;
|
|
|
0a4baa |
+#else
|
|
|
0a4baa |
+ struct sockaddr_in localaddr;
|
|
|
0a4baa |
+#endif
|
|
|
0a4baa |
+ const char *sst_str;
|
|
|
0a4baa |
+ const char *lport_str;
|
|
|
0a4baa |
+ const char *uid_str;
|
|
|
0a4baa |
+ const char *inode_str;
|
|
|
0a4baa |
+ char *laddrs_str;
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ if(lnr == 0) {
|
|
|
0a4baa |
+ /* ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS */
|
|
|
0a4baa |
+ return;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ strtok(line," \t\n"); /*skip endpt*/
|
|
|
0a4baa |
+ strtok(0," \t\n"); /*skip sock*/
|
|
|
0a4baa |
+ strtok(0," \t\n"); /*skp sty*/
|
|
|
0a4baa |
+ sst_str = strtok(0," \t\n");
|
|
|
0a4baa |
+ strtok(0," \t\n"); /*skip hash bucket*/
|
|
|
0a4baa |
+ lport_str=strtok(0," \t\n");
|
|
|
0a4baa |
+ uid_str = strtok(0," \t\n");
|
|
|
0a4baa |
+ inode_str = strtok(0," \t\n");
|
|
|
0a4baa |
+ laddrs_str=strtok(0,"\t\n");
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ if (!sst_str || !lport_str || !uid_str || !inode_str) {
|
|
|
0a4baa |
+ fprintf(stderr, _("warning, got bogus sctp eps line.\n"));
|
|
|
0a4baa |
+ return;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ state = atoi(sst_str);
|
|
|
0a4baa |
+ port = atoi(lport_str);
|
|
|
0a4baa |
+ uid = atoi(uid_str);
|
|
|
0a4baa |
+ inode = strtoul(inode_str,0,0);
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ const char *this_local_addr;
|
|
|
0a4baa |
+ int first=1;
|
|
|
0a4baa |
+ char local_port[16];
|
|
|
0a4baa |
+ snprintf(local_port, sizeof(local_port), "%s",
|
|
|
0a4baa |
+ get_sname(htons(port), proto, flag_not & FLAG_NUM_PORT));
|
|
|
0a4baa |
+ for(this_local_addr=strtok(laddrs_str," \t\n");
|
|
|
0a4baa |
+ this_local_addr;
|
|
|
0a4baa |
+ this_local_addr=strtok(0," \t\n"))
|
|
|
0a4baa |
+ {
|
|
|
0a4baa |
+ char local_addr[64];
|
|
|
0a4baa |
+ ap = process_sctp_addr_str(this_local_addr, (struct sockaddr*)&localaddr);
|
|
|
0a4baa |
+ if(ap)
|
|
|
0a4baa |
+ safe_strncpy(local_addr,
|
|
|
0a4baa |
+ ap->sprint((struct sockaddr *) &localaddr, flag_not),
|
|
|
0a4baa |
+ sizeof(local_addr));
|
|
|
0a4baa |
+ else
|
|
|
0a4baa |
+ sprintf(local_addr,_("unsupported address family %d"), ((struct sockaddr*)&localaddr)->sa_family);
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ if(!first) printf("\n");
|
|
|
0a4baa |
+ if(first)
|
|
|
0a4baa |
+ printf("sctp ");
|
|
|
0a4baa |
+ else
|
|
|
0a4baa |
+ printf(" ");
|
|
|
0a4baa |
+ sprintf(buffer,"%s:%s", local_addr, local_port);
|
|
|
0a4baa |
+ printf("%-47s", buffer);
|
|
|
0a4baa |
+ printf(" %-11s", first?sctp_socket_state_str(state):"");
|
|
|
0a4baa |
+ first = 0;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ finish_this_one(uid,inode,"");
|
|
|
0a4baa |
+}
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+static void sctp_assoc_do_one(int lnr, char *line, const char *proto)
|
|
|
0a4baa |
+{
|
|
|
0a4baa |
+ char buffer[1024];
|
|
|
0a4baa |
+ int state, lport,rport;
|
|
|
0a4baa |
+ int uid;
|
|
|
0a4baa |
+ unsigned rxqueue,txqueue;
|
|
|
0a4baa |
+ unsigned long inode;
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ struct aftype *ap;
|
|
|
0a4baa |
+#if HAVE_AFINET6
|
|
|
0a4baa |
+ struct sockaddr_in6 localaddr,remoteaddr;
|
|
|
0a4baa |
+#else
|
|
|
0a4baa |
+ struct sockaddr_in localaddr,remoteaddr;
|
|
|
0a4baa |
+#endif
|
|
|
0a4baa |
+ const char *sst_str;
|
|
|
0a4baa |
+ const char *txqueue_str;
|
|
|
0a4baa |
+ const char *rxqueue_str;
|
|
|
0a4baa |
+ const char *lport_str,*rport_str;
|
|
|
0a4baa |
+ const char *uid_str;
|
|
|
0a4baa |
+ const char *inode_str;
|
|
|
0a4baa |
+ char *laddrs_str;
|
|
|
0a4baa |
+ char *raddrs_str;
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ if(lnr == 0) {
|
|
|
0a4baa |
+ /* ASSOC SOCK STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT RPORT LADDRS <-> RADDRS */
|
|
|
0a4baa |
+ return;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ strtok(line," \t\n"); /*skip assoc*/
|
|
|
0a4baa |
+ strtok(0," \t\n"); /*skip sock*/
|
|
|
0a4baa |
+ strtok(0," \t\n"); /*skp sty*/
|
|
|
0a4baa |
+ sst_str = strtok(0," \t\n");
|
|
|
0a4baa |
+ strtok(0," \t\n");
|
|
|
0a4baa |
+ strtok(0," \t\n"); /*skip hash bucket*/
|
|
|
0a4baa |
+ strtok(0," \t\n"); /*skip hash assoc-id*/
|
|
|
0a4baa |
+ txqueue_str = strtok(0," \t\n");
|
|
|
0a4baa |
+ rxqueue_str = strtok(0," \t\n");
|
|
|
0a4baa |
+ uid_str = strtok(0," \t\n");
|
|
|
0a4baa |
+ inode_str = strtok(0," \t\n");
|
|
|
0a4baa |
+ lport_str=strtok(0," \t\n");
|
|
|
0a4baa |
+ rport_str=strtok(0," \t\n");
|
|
|
0a4baa |
+ laddrs_str = strtok(0,"<->\t\n");
|
|
|
0a4baa |
+ raddrs_str = strtok(0,"<->\t\n");
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ if (!sst_str || !txqueue_str || !rxqueue_str || !uid_str ||
|
|
|
0a4baa |
+ !inode_str || !lport_str || !rport_str) {
|
|
|
0a4baa |
+ fprintf(stderr, _("warning, got bogus sctp assoc line.\n"));
|
|
|
0a4baa |
+ return;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ state = atoi(sst_str);
|
|
|
0a4baa |
+ txqueue = atoi(txqueue_str);
|
|
|
0a4baa |
+ rxqueue = atoi(rxqueue_str);
|
|
|
0a4baa |
+ uid = atoi(uid_str);
|
|
|
0a4baa |
+ inode = strtoul(inode_str,0,0);
|
|
|
0a4baa |
+ lport = atoi(lport_str);
|
|
|
0a4baa |
+ rport = atoi(rport_str);
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ /*print all addresses*/
|
|
|
0a4baa |
+ const char *this_local_addr;
|
|
|
0a4baa |
+ const char *this_remote_addr;
|
|
|
0a4baa |
+ char *ss1,*ss2;
|
|
|
0a4baa |
+ int first=1;
|
|
|
0a4baa |
+ char local_port[16];
|
|
|
0a4baa |
+ char remote_port[16];
|
|
|
0a4baa |
+ snprintf(local_port, sizeof(local_port), "%s",
|
|
|
0a4baa |
+ get_sname(htons(lport), proto,
|
|
|
0a4baa |
+ flag_not & FLAG_NUM_PORT));
|
|
|
0a4baa |
+ snprintf(remote_port, sizeof(remote_port), "%s",
|
|
|
0a4baa |
+ get_sname(htons(rport), proto,
|
|
|
0a4baa |
+ flag_not & FLAG_NUM_PORT));
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ this_local_addr=strtok_r(laddrs_str," \t\n",&ss1;;
|
|
|
0a4baa |
+ this_remote_addr=strtok_r(raddrs_str," \t\n",&ss2;;
|
|
|
0a4baa |
+ while(this_local_addr || this_remote_addr) {
|
|
|
0a4baa |
+ char local_addr[64];
|
|
|
0a4baa |
+ char remote_addr[64];
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ if(this_local_addr) {
|
|
|
0a4baa |
+ if (this_local_addr[0] == '*') {
|
|
|
0a4baa |
+ /* skip * */
|
|
|
0a4baa |
+ this_local_addr++;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ ap = process_sctp_addr_str(this_local_addr, (struct sockaddr*)&localaddr);
|
|
|
0a4baa |
+ if(ap)
|
|
|
0a4baa |
+ safe_strncpy(local_addr,
|
|
|
0a4baa |
+ ap->sprint((struct sockaddr *) &localaddr, flag_not), sizeof(local_addr));
|
|
|
0a4baa |
+ else
|
|
|
0a4baa |
+ sprintf(local_addr,_("unsupported address family %d"), ((struct sockaddr*)&localaddr)->sa_family);
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ if(this_remote_addr) {
|
|
|
0a4baa |
+ if (this_remote_addr[0] == '*') {
|
|
|
0a4baa |
+ /* skip * */
|
|
|
0a4baa |
+ this_remote_addr++;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ ap = process_sctp_addr_str(this_remote_addr, (struct sockaddr*)&remoteaddr);
|
|
|
0a4baa |
+ if(ap)
|
|
|
0a4baa |
+ safe_strncpy(remote_addr,
|
|
|
0a4baa |
+ ap->sprint((struct sockaddr *) &remoteaddr, flag_not), sizeof(remote_addr));
|
|
|
0a4baa |
+ else
|
|
|
0a4baa |
+ sprintf(remote_addr,_("unsupported address family %d"), ((struct sockaddr*)&remoteaddr)->sa_family);
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
|
|
|
0a4baa |
- /* print IP:service to l_addr and r_addr */
|
|
|
0a4baa |
- print_ip_service(&laddr, prot, l_addr, sizeof(l_addr));
|
|
|
0a4baa |
- print_ip_service(&raddr, prot, r_addr, sizeof(r_addr));
|
|
|
0a4baa |
-
|
|
|
0a4baa |
- /* Print line */
|
|
|
0a4baa |
- printf("%-4s %6ld %6ld %-*s %-*s %-11s",
|
|
|
0a4baa |
- prot, rxq, txq,
|
|
|
0a4baa |
- (int)netmax(23,strlen(l_addr)), l_addr,
|
|
|
0a4baa |
- (int)netmax(23,strlen(r_addr)), r_addr,
|
|
|
0a4baa |
- _(tcp_state[TCP_ESTABLISHED]));
|
|
|
0a4baa |
- finish_this_one(uid, inode, "");
|
|
|
0a4baa |
- return;
|
|
|
0a4baa |
- err:
|
|
|
0a4baa |
- fprintf(stderr, "SCTP error in line: %d\n", lnr);
|
|
|
0a4baa |
+ if(!first) printf("\n");
|
|
|
0a4baa |
+ if(first)
|
|
|
0a4baa |
+ printf("sctp %6u %6u ", rxqueue, txqueue);
|
|
|
0a4baa |
+ else
|
|
|
0a4baa |
+ printf(" ");
|
|
|
0a4baa |
+ if(this_local_addr) {
|
|
|
0a4baa |
+ if(first)
|
|
|
0a4baa |
+ sprintf(buffer,"%s:%s", local_addr, local_port);
|
|
|
0a4baa |
+ else
|
|
|
0a4baa |
+ sprintf(buffer,"%s", local_addr);
|
|
|
0a4baa |
+ printf("%-23s", buffer);
|
|
|
0a4baa |
+ } else
|
|
|
0a4baa |
+ printf("%-23s", "");
|
|
|
0a4baa |
+ printf(" ");
|
|
|
0a4baa |
+ if(this_remote_addr) {
|
|
|
0a4baa |
+ if(first)
|
|
|
0a4baa |
+ sprintf(buffer,"%s:%s", remote_addr, remote_port);
|
|
|
0a4baa |
+ else
|
|
|
0a4baa |
+ sprintf(buffer,"%s", remote_addr);
|
|
|
0a4baa |
+ printf("%-23s", buffer);
|
|
|
0a4baa |
+ } else
|
|
|
0a4baa |
+ printf("%-23s", "");
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ printf(" %-11s", first?sctp_socket_state_str(state):"");
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ first = 0;
|
|
|
0a4baa |
+ this_local_addr=strtok_r(0," \t\n",&ss1;;
|
|
|
0a4baa |
+ this_remote_addr=strtok_r(0," \t\n",&ss2;;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ finish_this_one(uid,inode,"");
|
|
|
0a4baa |
}
|
|
|
0a4baa |
|
|
|
0a4baa |
-static int sctp_info_epts(void) {
|
|
|
0a4baa |
+static int sctp_info_eps(void)
|
|
|
0a4baa |
+{
|
|
|
0a4baa |
INFO_GUTS6(_PATH_PROCNET_SCTPEPTS, _PATH_PROCNET_SCTP6EPTS, "AF INET (sctp)",
|
|
|
0a4baa |
- sctp_do_ept, "sctp", "sctp6");
|
|
|
0a4baa |
+ sctp_eps_do_one, "sctp", "sctp6");
|
|
|
0a4baa |
}
|
|
|
0a4baa |
|
|
|
0a4baa |
static int sctp_info_assocs(void) {
|
|
|
0a4baa |
INFO_GUTS6(_PATH_PROCNET_SCTPASSOCS, _PATH_PROCNET_SCTP6ASSOCS, "AF INET (sctp)",
|
|
|
0a4baa |
- sctp_do_assoc, "sctp", "sctp6");
|
|
|
0a4baa |
+ sctp_assoc_do_one, "sctp", "sctp6");
|
|
|
0a4baa |
}
|
|
|
0a4baa |
|
|
|
0a4baa |
static int sctp_info(void) {
|
|
|
0a4baa |
int res;
|
|
|
0a4baa |
- res = sctp_info_epts();
|
|
|
0a4baa |
+ res = sctp_info_eps();
|
|
|
0a4baa |
if(res) return res;
|
|
|
0a4baa |
return sctp_info_assocs();
|
|
|
0a4baa |
}
|
|
|
0a4baa |
@@ -2234,7 +2344,7 @@ int main
|
|
|
0a4baa |
if (!strcmp(afname, "inet")) {
|
|
|
0a4baa |
#if HAVE_AFINET
|
|
|
0a4baa |
inittab();
|
|
|
0a4baa |
- i = parsesnmp(flag_raw, flag_tcp, flag_udp);
|
|
|
0a4baa |
+ i = parsesnmp(flag_raw, flag_tcp, flag_udp, flag_sctp);
|
|
|
0a4baa |
#else
|
|
|
0a4baa |
ENOSUPP("netstat", "AF INET");
|
|
|
0a4baa |
#endif
|
|
|
0a4baa |
diff -up net-tools-2.0/statistics.c.sctp net-tools-2.0/statistics.c
|
|
|
0a4baa |
--- net-tools-2.0/statistics.c.sctp 2013-09-23 15:14:59.501866518 +0200
|
|
|
0a4baa |
+++ net-tools-2.0/statistics.c 2013-09-23 15:14:59.534866063 +0200
|
|
|
0a4baa |
@@ -21,7 +21,7 @@
|
|
|
0a4baa |
#define UFWARN(x)
|
|
|
0a4baa |
#endif
|
|
|
0a4baa |
|
|
|
0a4baa |
-int print_static,f_raw,f_tcp,f_udp,f_unknown = 1;
|
|
|
0a4baa |
+int print_static,f_raw,f_tcp,f_udp,f_sctp,f_unknown = 1;
|
|
|
0a4baa |
|
|
|
0a4baa |
enum State {
|
|
|
0a4baa |
number = 0, opt_number, i_forward, i_inp_icmp, i_outp_icmp, i_rto_alg,
|
|
|
0a4baa |
@@ -299,6 +299,27 @@ struct entry Tcpexttab[] =
|
|
|
0a4baa |
{ "TCPRenoRecoveryFail", N_("%llu classic Reno fast retransmits failed"), opt_number },
|
|
|
0a4baa |
};
|
|
|
0a4baa |
|
|
|
0a4baa |
+struct entry Sctptab[] =
|
|
|
0a4baa |
+{
|
|
|
0a4baa |
+ {"SctpCurrEstab", N_("%llu Current Associations"), number},
|
|
|
0a4baa |
+ {"SctpActiveEstabs", N_("%llu Active Associations"), number},
|
|
|
0a4baa |
+ {"SctpPassiveEstabs", N_("%llu Passive Associations"), number},
|
|
|
0a4baa |
+ {"SctpAborteds", N_("%llu Number of Aborteds "), number},
|
|
|
0a4baa |
+ {"SctpShutdowns", N_("%llu Number of Graceful Terminations"), number},
|
|
|
0a4baa |
+ {"SctpOutOfBlues", N_("%llu Number of Out of Blue packets"), number},
|
|
|
0a4baa |
+ {"SctpChecksumErrors", N_("%llu Number of Packets with invalid Checksum"), number},
|
|
|
0a4baa |
+ {"SctpOutCtrlChunks", N_("%llu Number of control chunks sent"), number},
|
|
|
0a4baa |
+ {"SctpOutOrderChunks", N_("%llu Number of ordered chunks sent"), number},
|
|
|
0a4baa |
+ {"SctpOutUnorderChunks", N_("%llu Number of Unordered chunks sent"), number},
|
|
|
0a4baa |
+ {"SctpInCtrlChunks", N_("%llu Number of control chunks received"), number},
|
|
|
0a4baa |
+ {"SctpInOrderChunks", N_("%llu Number of ordered chunks received"), number},
|
|
|
0a4baa |
+ {"SctpInUnorderChunks", N_("%llu Number of Unordered chunks received"), number},
|
|
|
0a4baa |
+ {"SctpFragUsrMsgs", N_("%llu Number of messages fragmented"), number},
|
|
|
0a4baa |
+ {"SctpReasmUsrMsgs", N_("%llu Number of messages reassembled "), number},
|
|
|
0a4baa |
+ {"SctpOutSCTPPacks", N_("%llu Number of SCTP packets sent"), number},
|
|
|
0a4baa |
+ {"SctpInSCTPPacks", N_("%llu Number of SCTP packets received"), number},
|
|
|
0a4baa |
+};
|
|
|
0a4baa |
+
|
|
|
0a4baa |
struct tabtab {
|
|
|
0a4baa |
char *title;
|
|
|
0a4baa |
struct entry *tab;
|
|
|
0a4baa |
@@ -312,6 +333,7 @@ struct tabtab snmptabs[] =
|
|
|
0a4baa |
{"Icmp", Icmptab, sizeof(Icmptab), &f_raw},
|
|
|
0a4baa |
{"Tcp", Tcptab, sizeof(Tcptab), &f_tcp},
|
|
|
0a4baa |
{"Udp", Udptab, sizeof(Udptab), &f_udp},
|
|
|
0a4baa |
+ {"Sctp", Sctptab, sizeof(Sctptab), &f_sctp},
|
|
|
0a4baa |
{"TcpExt", Tcpexttab, sizeof(Tcpexttab), &f_tcp},
|
|
|
0a4baa |
{NULL}
|
|
|
0a4baa |
};
|
|
|
0a4baa |
@@ -502,11 +524,38 @@ void process6_fd(FILE *f)
|
|
|
0a4baa |
|
|
|
0a4baa |
}
|
|
|
0a4baa |
|
|
|
0a4baa |
-int parsesnmp(int flag_raw, int flag_tcp, int flag_udp)
|
|
|
0a4baa |
+/* Process a file with name-value lines (like /proc/net/sctp/snmp) */
|
|
|
0a4baa |
+void process_fd2(FILE *f, const char *filename)
|
|
|
0a4baa |
+{
|
|
|
0a4baa |
+ char buf1[1024];
|
|
|
0a4baa |
+ char *sp;
|
|
|
0a4baa |
+ struct tabtab *tab;
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ tab = newtable(snmptabs, "Sctp");
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ while (fgets(buf1, sizeof buf1, f)) {
|
|
|
0a4baa |
+ sp = buf1 + strcspn(buf1, " \t\n");
|
|
|
0a4baa |
+ if (!sp) {
|
|
|
0a4baa |
+ fprintf(stderr,_("error parsing %s\n"), filename);
|
|
|
0a4baa |
+ return;
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ *sp = '\0';
|
|
|
0a4baa |
+ sp++;
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ sp += strspn(sp, " \t\n");
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ if (*sp != '\0' && *(tab->flag))
|
|
|
0a4baa |
+ printval(tab, buf1, strtoul(sp, 0, 10));
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ return;
|
|
|
0a4baa |
+}
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+int parsesnmp(int flag_raw, int flag_tcp, int flag_udp, int flag_sctp)
|
|
|
0a4baa |
+
|
|
|
0a4baa |
{
|
|
|
0a4baa |
FILE *f;
|
|
|
0a4baa |
|
|
|
0a4baa |
- f_raw = flag_raw; f_tcp = flag_tcp; f_udp = flag_udp;
|
|
|
0a4baa |
+ f_raw = flag_raw; f_tcp = flag_tcp; f_udp = flag_udp; f_sctp = flag_sctp;
|
|
|
0a4baa |
|
|
|
0a4baa |
f = proc_fopen("/proc/net/snmp");
|
|
|
0a4baa |
if (!f) {
|
|
|
0a4baa |
@@ -539,6 +588,17 @@ int parsesnmp(int flag_raw, int flag_tcp
|
|
|
0a4baa |
|
|
|
0a4baa |
fclose(f);
|
|
|
0a4baa |
}
|
|
|
0a4baa |
+
|
|
|
0a4baa |
+ f = proc_fopen("/proc/net/sctp/snmp");
|
|
|
0a4baa |
+ if (f) {
|
|
|
0a4baa |
+ process_fd2(f,"/proc/net/sctp/snmp");
|
|
|
0a4baa |
+ if (ferror(f)) {
|
|
|
0a4baa |
+ perror("/proc/net/sctp/snmp");
|
|
|
0a4baa |
+ fclose(f);
|
|
|
0a4baa |
+ return(1);
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+ }
|
|
|
0a4baa |
+
|
|
|
0a4baa |
return(0);
|
|
|
0a4baa |
}
|
|
|
0a4baa |
|