mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-10 16:31:44 +00:00
Fix #1888: add %I *printf specifier for IP address. Remove mg_ntoa, mg_straddr
This commit is contained in:
1 parent
89fb3a3d6e
commit
b01989f041
12 files changed
+105
-144
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#include "fmt.h"
|
||||
#include "iobuf.h"
|
||||
#include "util.h"
|
||||
|
||||
static void mg_pfn_iobuf_private(char ch, void *param, bool expand) {
|
||||
struct mg_iobuf *io = (struct mg_iobuf *) param;
|
||||
@@ -309,6 +310,20 @@ size_t mg_vxprintf(void (*out)(char, void *), void *param, const char *fmt,
|
||||
n += scpy(out, param, (char *) &hex[p[j] & 15], 1);
|
||||
}
|
||||
n += scpy(out, param, (char *) &dquote, 1);
|
||||
} else if (c == 'I') {
|
||||
// Print IPv4 or IPv6 address
|
||||
size_t len = (size_t) va_arg(*ap, int); // Length 16 means IPv6 address
|
||||
uint8_t *buf = va_arg(*ap, uint8_t *); // Pointer to the IP address
|
||||
if (len == 6) {
|
||||
uint16_t *p = (uint16_t *) buf;
|
||||
n += mg_xprintf(out, param, "%x:%x:%x:%x:%x:%x:%x:%x", mg_htons(p[0]),
|
||||
mg_htons(p[1]), mg_htons(p[2]), mg_htons(p[3]),
|
||||
mg_htons(p[4]), mg_htons(p[5]), mg_htons(p[6]),
|
||||
mg_htons(p[7]));
|
||||
} else {
|
||||
n += mg_xprintf(out, param, "%d.%d.%d.%d", (int) buf[0], (int) buf[1],
|
||||
(int) buf[2], (int) buf[3]);
|
||||
}
|
||||
} else if (c == 'V') {
|
||||
// Print base64-encoded double-quoted string
|
||||
size_t len = (size_t) va_arg(*ap, int);
|
||||
|
||||
Reference in new issue
Block a user