20 #if defined(HAVE_ASSERT_H) && !defined(assert) 27 #ifdef HAVE_ARPA_INET_H 28 #include <arpa/inet.h> 39 #define min(a,b) ((a) < (b) ? (a) : (b)) 68 "EMRG",
"ALRT",
"CRIT",
"WARN",
"NOTE",
"INFO",
"DEBG" 77 return strftime(s, len,
"%b %d %H:%M:%S", tmp);
85 return snprintf(s, len,
"%u.%03u",
109 while(*s++ && n < maxlen)
116 #ifdef HAVE_ARPA_INET_H 117 const void *addrptr = NULL;
121 switch (addr->
addr.
sa.sa_family) {
123 if (len < INET_ADDRSTRLEN)
126 addrptr = &addr->
addr.
sin.sin_addr;
127 port = ntohs(addr->
addr.
sin.sin_port);
130 if (len < INET6_ADDRSTRLEN + 2)
135 addrptr = &addr->
addr.
sin6.sin6_addr;
136 port = ntohs(addr->
addr.
sin6.sin6_port);
140 memcpy(buf,
"(unknown address type)",
min(22, len));
144 if (inet_ntop(addr->
addr.
sa.sa_family, addrptr, p, len) == 0) {
145 perror(
"dsrv_print_addr");
151 if (addr->
addr.
sa.sa_family == AF_INET6) {
158 p += snprintf(p, buf + len - p + 1,
":%d", port);
164 # if NETSTACK_CONF_WITH_IPV6 166 const char hex[] =
"0123456789ABCDEF";
173 for (i=0; i < 16; i += 2) {
177 *p++ = hex[(addr->
addr.u8[i] & 0xf0) >> 4];
178 *p++ = hex[(addr->
addr.u8[i] & 0x0f)];
179 *p++ = hex[(addr->
addr.u8[i+1] & 0xf0) >> 4];
180 *p++ = hex[(addr->
addr.u8[i+1] & 0x0f)];
187 p += sprintf(p,
"%u.%u.%u.%u",
189 addr->
addr.u8[2], addr->
addr.u8[3]);
191 if (buf + len - p < 6)
194 p += sprintf(p,
":%d", uip_htons(addr->port));
199 # warning "inet_ntop() not available, network addresses will not be included in debug output" 210 static char timebuf[32];
220 fprintf(log_fd,
"%s ", timebuf);
223 fprintf(log_fd,
"%s ",
loglevels[level]);
225 va_start(ap, format);
226 vfprintf(log_fd, format, ap);
230 #elif defined (HAVE_VPRINTF) 233 static char timebuf[32];
245 va_start(ap, format);
253 void hexdump(
const unsigned char *packet,
int length) {
260 printf(
"%02X ", *packet++);
273 void dump(
unsigned char *buf,
size_t len) {
275 printf(
"%02x", *buf++);
286 dsrv_log(level,
"%s: %s\n", name, addrbuf);
292 static char timebuf[32];
302 fprintf(log_fd,
"%s ", timebuf);
305 fprintf(log_fd,
"%s ",
loglevels[level]);
308 fprintf(log_fd,
"%s: (%zu bytes):\n", name, length);
312 fprintf(log_fd,
"%08X ", n);
314 fprintf(log_fd,
"%02X ", *buf++);
319 fprintf(log_fd,
"\n");
321 fprintf(log_fd,
" ");
325 fprintf(log_fd,
"%s: (%zu bytes): ", name, length);
327 fprintf(log_fd,
"%02X", *buf++);
329 fprintf(log_fd,
"\n");
336 static char timebuf[32];
349 PRINTF(
"%s: (%zu bytes):\n", name, length);
366 PRINTF(
"%s: (%zu bytes): ", name, length);
void dtls_set_log_level(log_t level)
log_t dtls_get_log_level()
static char * loglevels[]
static size_t print_timestamp(char *s, size_t len, time_t t)
void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend)
void dsrv_log(log_t level, char *format,...)
void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr)
static size_t dsrv_print_addr(const session_t *addr, char *buf, size_t len)
const char * dtls_package_name()
void hexdump(const unsigned char *packet, int length)
const char * dtls_package_version()
static size_t dtls_strnlen(const char *s, size_t maxlen)
void dump(unsigned char *buf, size_t len)