29 #if defined(HAVE_ASSERT_H) && !defined(assert)
36 #ifdef HAVE_ARPA_INET_H
37 #include <arpa/inet.h>
69 "EMRG",
"ALRT",
"CRIT",
"WARN",
"NOTE",
"INFO",
"DEBG"
78 return strftime(s, len,
"%b %d %H:%M:%S", tmp);
86 return snprintf(s, len,
"%u.%03u",
108 while(*s++ && n < maxlen)
114 #define min(a,b) ((a) < (b) ? (a) : (b))
119 #ifdef HAVE_ARPA_INET_H
120 const void *addrptr = NULL;
124 switch (addr->
addr.
sa.sa_family) {
126 if (len < INET_ADDRSTRLEN)
129 addrptr = &addr->
addr.
sin.sin_addr;
130 port = ntohs(addr->
addr.
sin.sin_port);
133 if (len < INET6_ADDRSTRLEN + 2)
138 addrptr = &addr->
addr.
sin6.sin6_addr;
139 port = ntohs(addr->
addr.
sin6.sin6_port);
143 memcpy(buf,
"(unknown address type)",
min(22, len));
147 if (inet_ntop(addr->
addr.
sa.sa_family, addrptr, p, len) == 0) {
148 perror(
"dsrv_print_addr");
154 if (addr->
addr.
sa.sa_family == AF_INET6) {
161 p += snprintf(p, buf + len - p + 1,
":%d", port);
167 # ifdef UIP_CONF_IPV6
169 const char hex[] =
"0123456789ABCDEF";
176 for (i=0; i < 16; i += 2) {
180 *p++ = hex[(addr->
addr.u8[i] & 0xf0) >> 4];
181 *p++ = hex[(addr->
addr.u8[i] & 0x0f)];
182 *p++ = hex[(addr->
addr.u8[i+1] & 0xf0) >> 4];
183 *p++ = hex[(addr->
addr.u8[i+1] & 0x0f)];
187 # warning "IPv4 network addresses will not be included in debug output"
192 if (buf + len - p < 6)
195 p += sprintf(p,
":%d", uip_htons(addr->port));
200 # warning "inet_ntop() not available, network addresses will not be included in debug output"
209 static char timebuf[32];
219 fprintf(log_fd,
"%s ", timebuf);
222 fprintf(log_fd,
"%s ",
loglevels[level]);
224 va_start(ap, format);
225 vfprintf(log_fd, format, ap);
229 #elif defined (HAVE_VPRINTF)
232 static char timebuf[32];
244 va_start(ap, format);
252 void hexdump(
const unsigned char *packet,
int length) {
259 printf(
"%02X ", *packet++);
272 void dump(
unsigned char *buf,
size_t len) {
274 printf(
"%02x", *buf++);
285 dsrv_log(level,
"%s: %s\n", name, addrbuf);
291 static char timebuf[32];
301 fprintf(log_fd,
"%s ", timebuf);
304 fprintf(log_fd,
"%s ",
loglevels[level]);
307 fprintf(log_fd,
"%s: (%zu bytes):\n", name, length);
311 fprintf(log_fd,
"%08X ", n);
313 fprintf(log_fd,
"%02X ", *buf++);
318 fprintf(log_fd,
"\n");
320 fprintf(log_fd,
" ");
324 fprintf(log_fd,
"%s: (%zu bytes): ", name, length);
326 fprintf(log_fd,
"%02X", *buf++);
328 fprintf(log_fd,
"\n");
335 static char timebuf[32];
348 PRINTF(
"%s: (%zu bytes):\n", name, length);
365 PRINTF(
"%s: (%zu bytes): ", name, length);
static size_t print_timestamp(char *s, size_t len, time_t t)
log_t dtls_get_log_level()
static char * loglevels[]
void dsrv_log(log_t level, char *format,...)
void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend)
void dtls_set_log_level(log_t level)
static size_t dsrv_print_addr(const session_t *addr, char *buf, size_t len)
const char * dtls_package_version()
void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr)
void dump(unsigned char *buf, size_t len)
void hexdump(const unsigned char *packet, int length)
static size_t dtls_strnlen(const char *s, size_t maxlen)
const char * dtls_package_name()