MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_string

Function get_string

tools/ifconfig/ifieee80211.c:5616–5670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5614}
5615
5616static const char *
5617get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
5618{
5619 int len;
5620 int hexstr;
5621 u_int8_t *p;
5622
5623 len = *lenp;
5624 p = buf;
5625 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
5626 if (hexstr)
5627 val += 2;
5628 for (;;) {
5629 if (*val == '\0')
5630 break;
5631 if (sep != NULL && strchr(sep, *val) != NULL) {
5632 val++;
5633 break;
5634 }
5635 if (hexstr) {
5636 if (!isxdigit((u_char)val[0])) {
5637 warnx("bad hexadecimal digits");
5638 return NULL;
5639 }
5640 if (!isxdigit((u_char)val[1])) {
5641 warnx("odd count hexadecimal digits");
5642 return NULL;
5643 }
5644 }
5645 if (p >= buf + len) {
5646 if (hexstr)
5647 warnx("hexadecimal digits too long");
5648 else
5649 warnx("string too long");
5650 return NULL;
5651 }
5652 if (hexstr) {
5653#define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5654 *p++ = (tohex((u_char)val[0]) << 4) |
5655 tohex((u_char)val[1]);
5656#undef tohex
5657 val += 2;
5658 } else
5659 *p++ = *val++;
5660 }
5661 len = p - buf;
5662 /* The string "-" is treated as the empty string. */
5663 if (!hexstr && len == 1 && buf[0] == '-') {
5664 len = 0;
5665 memset(buf, 0, *lenp);
5666 } else if (len < *lenp)
5667 memset(p, 0, *lenp - len);
5668 *lenp = len;
5669 return val;
5670}
5671
5672static void
5673print_string(const u_int8_t *buf, int len)

Callers 5

set80211ssidFunction · 0.70
set80211meshidFunction · 0.70
set80211stationnameFunction · 0.70
set80211wepkeyFunction · 0.70
set80211nwkeyFunction · 0.70

Calls 4

tolowerFunction · 0.85
strchrFunction · 0.85
isxdigitFunction · 0.85
memsetFunction · 0.85

Tested by

no test coverage detected