* 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 "...". */
| 3445 | * three characters with "...". |
| 3446 | */ |
| 3447 | static int |
| 3448 | copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len) |
| 3449 | { |
| 3450 | const u_int8_t *p; |
| 3451 | size_t maxlen; |
| 3452 | u_int i; |
| 3453 | |
| 3454 | if (essid_len > bufsize) |
| 3455 | maxlen = bufsize; |
| 3456 | else |
| 3457 | maxlen = essid_len; |
| 3458 | /* determine printable or not */ |
| 3459 | for (i = 0, p = essid; i < maxlen; i++, p++) { |
| 3460 | if (*p < ' ' || *p > 0x7e) |
| 3461 | break; |
| 3462 | } |
| 3463 | if (i != maxlen) { /* not printable, print as hex */ |
| 3464 | if (bufsize < 3) |
| 3465 | return 0; |
| 3466 | strlcpy(buf, "0x", bufsize); |
| 3467 | bufsize -= 2; |
| 3468 | p = essid; |
| 3469 | for (i = 0; i < maxlen && bufsize >= 2; i++) { |
| 3470 | sprintf(&buf[2+2*i], "%02x", p[i]); |
| 3471 | bufsize -= 2; |
| 3472 | } |
| 3473 | if (i != essid_len) |
| 3474 | memcpy(&buf[2+2*i-3], "...", 3); |
| 3475 | } else { /* printable, truncate as needed */ |
| 3476 | memcpy(buf, essid, maxlen); |
| 3477 | if (maxlen != essid_len) |
| 3478 | memcpy(&buf[maxlen-3], "...", 3); |
| 3479 | } |
| 3480 | return maxlen; |
| 3481 | } |
| 3482 | |
| 3483 | static void |
| 3484 | printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) |