FreeBSD/sbin/ifconfig/ifieee80211.c
/*
 * Copy the ssid string contents into buf, truncating to fit.  If the
 * ssid is entirely printable then just copy intact.  Otherwise convert
 * to hexadecimal.  If the result is truncated then replace the last
 * three characters with "...".
 */
Copy the ssid string contents into buf, truncating to fit.  If the
ssid is entirely printable then just copy intact.  Otherwise convert
to hexadecimal.  If the result is truncated then replace the last
three characters with "...".
Copy the ssid string contents into buf truncating to fit . If the ssid is entirely printable then just copy intact . Otherwise convert to hexadecimal . If the result is truncated then replace the last three characters with " ... " .
static int
copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
{
	const u_int8_t *p; 
	size_t maxlen;
	u_int i;
	if (essid_len > bufsize)
		maxlen = bufsize;
	else
		maxlen = essid_len;
	for (i = 0, p = essid; i < maxlen; i++, p++) {
		if (*p < ' ' || *p > 0x7e)
			break;
	}
	if (i != maxlen) {		
		if (bufsize < 3)
			return 0;
		strlcpy(buf, "0x", bufsize);
		bufsize -= 2;
		p = essid;
		for (i = 0; i < maxlen && bufsize >= 2; i++) {
			sprintf(&buf[2+2*i], "%02x", p[i]);
			bufsize -= 2;
		}
		if (i != essid_len)
			memcpy(&buf[2+2*i-3], "...", 3);
	} else {			
		memcpy(buf, essid, maxlen);
		if (maxlen != essid_len)
			memcpy(&buf[maxlen-3], "...", 3);
	}
	return maxlen;
}
static int copy_essid ( char buf [ ] , size_t bufsize , const u_int8_t * essid , size_t essid_len ) { const u_int8_t * p ; size_t maxlen ; u_int i ; if ( essid_len > bufsize ) maxlen = bufsize ; else maxlen = essid_len ; for ( i = 0 , p = essid ; i < maxlen ; i ++ , p ++ ) { if ( * p < ' ' || * p > 0x7e ) break ; } if ( i != maxlen ) { if ( bufsize < 3 ) return 0 ; strlcpy ( buf , " " , bufsize ) ; bufsize -= 2 ; p = essid ; for ( i = 0 ; i < maxlen && bufsize >= 2 ; i ++ ) { sprintf ( & buf [ 2 + 2 * i ] , " " , p [ i ] ) ; bufsize -= 2 ; } if ( i != essid_len ) memcpy ( & buf [ 2 + 2 * i - 3 ] , " " , 3 ) ; } else { memcpy ( buf , essid , maxlen ) ; if ( maxlen != essid_len ) memcpy ( & buf [ maxlen - 3 ] , " " , 3 ) ; } return maxlen ; }
Copy the ssid string contents into buf, truncating to fit.
Copy the ssid string contents into buf truncating to fit .
/* determine printable or not */ /* not printable, print as hex */ /* printable, truncate as needed */