diff options
Diffstat (limited to 'lib/print.c')
-rw-r--r-- | lib/print.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/lib/print.c b/lib/print.c index bafe58f..6ea79cb 100644 --- a/lib/print.c +++ b/lib/print.c @@ -265,7 +265,7 @@ ipset_print_ip(char *buf, unsigned int len, assert(buf); assert(len > 0); assert(data); - assert(opt == IPSET_OPT_IP || opt == IPSET_OPT_IP2); + assert(opt == IPSET_OPT_IP || opt == IPSET_OPT_IP2 || opt == IPSET_OPT_BITMASK); D("len: %u", len); family = ipset_data_family(data); @@ -397,6 +397,51 @@ ipset_print_number(char *buf, unsigned int len, } /** + * ipset_print_hexnumber - print number in hex to string + * @buf: printing buffer + * @len: length of available buffer space + * @data: data blob + * @opt: the option kind + * @env: environment flags + * + * Print number in hex to output buffer. + * + * Return lenght of printed string or error size. + */ +int +ipset_print_hexnumber(char *buf, unsigned int len, + const struct ipset_data *data, enum ipset_opt opt, + uint8_t env) +{ + size_t maxsize; + const void *number; + const char *quoted = env & IPSET_ENV_QUOTED ? "\"" : ""; + + assert(buf); + assert(len > 0); + assert(data); + + number = ipset_data_get(data, opt); + maxsize = ipset_data_sizeof(opt, AF_INET); + D("opt: %u, maxsize %zu", opt, maxsize); + if (maxsize == sizeof(uint8_t)) + return snprintf(buf, len, "%s0x%02"PRIx8"%s", + quoted, *(const uint8_t *) number, quoted); + else if (maxsize == sizeof(uint16_t)) + return snprintf(buf, len, "%s0x%04"PRIx16"%s", + quoted, *(const uint16_t *) number, quoted); + else if (maxsize == sizeof(uint32_t)) + return snprintf(buf, len, "%s0x%08"PRIx32"%s", + quoted, *(const uint32_t *) number, quoted); + else if (maxsize == sizeof(uint64_t)) + return snprintf(buf, len, "%s0x%016"PRIx64"%s", + quoted, *(const uint64_t *) number, quoted); + else + assert(0); + return 0; +} + +/** * ipset_print_name - print setname element string * @buf: printing buffer * @len: length of available buffer space @@ -932,6 +977,7 @@ ipset_print_data(char *buf, unsigned int len, size = ipset_print_elem(buf, len, data, opt, env); break; case IPSET_OPT_IP: + case IPSET_OPT_BITMASK: size = ipset_print_ip(buf, len, data, opt, env); break; case IPSET_OPT_PORT: @@ -940,12 +986,12 @@ ipset_print_data(char *buf, unsigned int len, case IPSET_OPT_IFACE: size = ipset_print_iface(buf, len, data, opt, env); break; - case IPSET_OPT_GC: + case IPSET_OPT_INITVAL: case IPSET_OPT_HASHSIZE: case IPSET_OPT_MAXELEM: case IPSET_OPT_MARKMASK: case IPSET_OPT_NETMASK: - case IPSET_OPT_PROBES: + case IPSET_OPT_BUCKETSIZE: case IPSET_OPT_RESIZE: case IPSET_OPT_TIMEOUT: case IPSET_OPT_REFERENCES: |