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