FreeBSD/usr.bin/systat/netstat.c
/*
 * Pretty print an Internet address (net address + port).
 * If the nflag was specified, use numbers instead of names.
 */
Pretty print an Internet address (net address + port).
If the nflag was specified, use numbers instead of names.
Pretty print an Internet address ( net address + port ) . If the nflag was specified use numbers instead of names .
static void
inetprint(struct sockaddr *sa, const char *proto)
{
	struct servent *sp = 0;
	char line[80], *cp;
	int port;
	switch (sa->sa_family) {
	case AF_INET:
		port = ((struct sockaddr_in *)sa)->sin_port;
		break;
#ifdef INET6
	case AF_INET6:
		port = ((struct sockaddr_in6 *)sa)->sin6_port;
		break;
#endif
	default:
		port = 0;
		break;
	}
	snprintf(line, sizeof(line), "%.*s.", 16, inetname(sa));
	cp = strchr(line, '\0');
	if (!nflag && port)
		sp = getservbyport(port, proto);
	if (sp || port == 0)
		snprintf(cp, sizeof(line) - (cp - line), "%.8s",
		    sp ? sp->s_name : "*");
	else
		snprintf(cp, sizeof(line) - (cp - line), "%d",
		    ntohs((u_short)port));
	cp = strchr(line, '\0');
	while (cp - line < 22)
		*cp++ = ' ';
	line[22] = '\0';
	waddstr(wnd, line);
}
static void inetprint ( struct sockaddr * sa , const char * proto ) { struct servent * sp = 0 ; char line [ 80 ] , * cp ; int port ; switch ( sa -> sa_family ) { case AF_INET : port = ( ( struct sockaddr_in * ) sa ) -> sin_port ; break ; #ifdef INET6 case AF_INET6 : port = ( ( struct sockaddr_in6 * ) sa ) -> sin6_port ; break ; #endif default : port = 0 ; break ; } snprintf ( line , sizeof ( line ) , " " , 16 , inetname ( sa ) ) ; cp = strchr ( line , ' \0 ' ) ; if ( ! nflag && port ) sp = getservbyport ( port , proto ) ; if ( sp || port == 0 ) snprintf ( cp , sizeof ( line ) - ( cp - line ) , " " , sp ? sp -> s_name : " " ) ; else snprintf ( cp , sizeof ( line ) - ( cp - line ) , " " , ntohs ( ( u_short ) port ) ) ; cp = strchr ( line , ' \0 ' ) ; while ( cp - line < 22 ) * cp ++ = ' ' ; line [ 22 ] = ' \0 ' ; waddstr ( wnd , line ) ; }
Pretty print an Internet address (net address + port).
Pretty print an Internet address ( net address + port ) .
/* pad to full column to clear any garbage */