11 #if defined(HAVE_ASSERT_H) && !defined(assert)
20 #ifdef HAVE_ARPA_INET_H
21 #include <arpa/inet.h>
33 # define DEBUG DEBUG_PRINT
35 #include "net/uip-debug.h"
52 "EMRG",
"ALRT",
"CRIT",
"ERR",
"WARN",
"NOTE",
"INFO",
"DEBG"
60 time_t now = clock_offset + (t / COAP_TICKS_PER_SECOND);
61 tmp = localtime(&now);
62 return strftime(s, len,
"%b %d %H:%M:%S", tmp);
70 return snprintf(s, len,
"%u.%03u",
71 (
unsigned int)(clock_offset + (t / COAP_TICKS_PER_SECOND)),
72 (
unsigned int)(t % COAP_TICKS_PER_SECOND));
93 strnlen(
const char *s,
size_t maxlen) {
95 while(*s++ && n < maxlen)
103 unsigned char *result,
unsigned int buflen,
int encode_always ) {
104 const unsigned char hex[] =
"0123456789ABCDEF";
105 unsigned int cnt = 0;
106 assert(data || len == 0);
108 if (buflen == 0 || len == 0)
112 if (!encode_always && isprint(*data)) {
118 if (cnt+4 < buflen) {
121 *result++ = hex[(*data & 0xf0) >> 4];
122 *result++ = hex[*data & 0x0f];
136 #define min(a,b) ((a) < (b) ? (a) : (b))
141 #ifdef HAVE_ARPA_INET_H
142 const void *addrptr = NULL;
144 unsigned char *p = buf;
146 switch (addr->addr.sa.sa_family) {
148 addrptr = &addr->addr.sin.sin_addr;
149 port = ntohs(addr->addr.sin.sin_port);
157 addrptr = &addr->addr.sin6.sin6_addr;
158 port = ntohs(addr->addr.sin6.sin6_port);
162 memcpy(buf,
"(unknown address type)",
min(22, len));
166 if (inet_ntop(addr->addr.sa.sa_family, addrptr, (
char *)p, len) == 0) {
167 perror(
"coap_print_addr");
171 p += strnlen((
char *)p, len);
173 if (addr->addr.sa.sa_family == AF_INET6) {
180 p += snprintf((
char *)p, buf + len - p + 1,
":%d", port);
182 return buf + len - p;
185 unsigned char *p = buf;
188 const unsigned char hex[] =
"0123456789ABCDEF";
195 for (i=0; i < 16; i += 2) {
199 *p++ = hex[(addr->addr.u8[i] & 0xf0) >> 4];
200 *p++ = hex[(addr->addr.u8[i] & 0x0f)];
201 *p++ = hex[(addr->addr.u8[i+1] & 0xf0) >> 4];
202 *p++ = hex[(addr->addr.u8[i+1] & 0x0f)];
206 # warning "IPv4 network addresses will not be included in debug output"
211 if (buf + len - p < 6)
215 p += snprintf((
char *)p, buf + len - p + 1,
":%d", uip_htons(addr->port));
223 # warning "inet_ntop() not available, network addresses will not be included in debug output"
233 int encode = 0, have_options = 0;
267 buf,
sizeof(buf), encode ))
278 buf,
sizeof(buf), 0 );
289 unsigned char buf[80];
291 PRINTF(
"v:%d t:%d oc:%d c:%d id:%u",
296 if (pdu->
hdr->optcnt) {
306 buf,
sizeof(buf), 0))
307 PRINTF(
" %d:%s", opt_iter.
type, buf);
314 buf,
sizeof(buf), 0 );
315 PRINTF(
" d:%s", buf);
338 fprintf(log_fd,
"%s ", timebuf);
340 if (level <= LOG_DEBUG)
341 fprintf(log_fd,
"%s ",
loglevels[level]);
343 va_start(ap, format);
344 vfprintf(log_fd, format, ap);
360 PRINTF(
"%s ", timebuf);
362 if (level <= LOG_DEBUG)
365 va_start(ap, format);
#define COAP_OPTION_PROXY_URI
static char * loglevels[]
void coap_show_pdu(const coap_pdu_t *pdu)
unsigned short length
PDU length (including header, options, data)
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
coap_log_t coap_get_log_level()
Returns the current log level.
#define COAP_OPTION_LOCATION_QUERY
size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t len)
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
Header structure for CoAP PDUs.
coap_opt_iterator_t * coap_option_iterator_init(coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t filter)
Initializes the given option iterator oi to point to the beginning of the pdu's option list...
unsigned int print_readable(const unsigned char *data, unsigned int len, unsigned char *result, unsigned int buflen, int encode_always)
Iterator to run through PDU options.
#define COAP_MAX_PDU_SIZE
unsigned short type
decoded option type
void coap_log_impl(coap_log_t level, const char *format,...)
Writes the given text to COAP_ERR_FD (for level <= LOG_CRIT) or COAP_DEBUG_FD (for level >= LOG_WARNI...
#define COAP_OPTION_LOCATION_PATH
#define COAP_OPT_LENGTH(opt)
unsigned int token_length
#define COAP_OPTION_URI_PATH
static size_t print_timestamp(char *s, size_t len, coap_tick_t t)
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
#define COAP_OPTION_URI_QUERY
unsigned char coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
#define COAP_OPTION_URI_HOST
unsigned char * data
payload
#define COAP_OPT_VALUE(opt)