]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add wpa_snprintf_hex_sep()
authorJouni Malinen <j@w1.fi>
Sun, 29 Mar 2015 19:27:43 +0000 (22:27 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 29 Mar 2015 19:27:43 +0000 (22:27 +0300)
This can be used to print a hexdump with the specified separator between
octets.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/common.c
src/utils/common.h

index 5fd795f3f30364da665483060fc447b440d6064b..0bdc38db3a57d9ef94c3b3219528dd8a441afac2 100644 (file)
@@ -277,6 +277,31 @@ int wpa_scnprintf(char *buf, size_t size, const char *fmt, ...)
        return ret;
 }
 
+
+int wpa_snprintf_hex_sep(char *buf, size_t buf_size, const u8 *data, size_t len,
+                        char sep)
+{
+       size_t i;
+       char *pos = buf, *end = buf + buf_size;
+       int ret;
+
+       if (buf_size == 0)
+               return 0;
+
+       for (i = 0; i < len; i++) {
+               ret = os_snprintf(pos, end - pos, "%02x%c",
+                                 data[i], sep);
+               if (os_snprintf_error(end - pos, ret)) {
+                       end[-1] = '\0';
+                       return pos - buf;
+               }
+               pos += ret;
+       }
+       pos[-1] = '\0';
+       return pos - buf;
+}
+
+
 static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data,
                                    size_t len, int uppercase)
 {
index 576e8e7e2d4ebf80886255253dd8df25ebeddc0b..a0eda4a2c48bb8054f0a8a96e814d46581aae6e8 100644 (file)
@@ -480,6 +480,8 @@ int hexstr2bin(const char *hex, u8 *buf, size_t len);
 void inc_byte_array(u8 *counter, size_t len);
 void wpa_get_ntp_timestamp(u8 *buf);
 int wpa_scnprintf(char *buf, size_t size, const char *fmt, ...);
+int wpa_snprintf_hex_sep(char *buf, size_t buf_size, const u8 *data, size_t len,
+                        char sep);
 int wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len);
 int wpa_snprintf_hex_uppercase(char *buf, size_t buf_size, const u8 *data,
                               size_t len);