Skip to content

Commit

Permalink
debug: add method to log the session.
Browse files Browse the repository at this point in the history
Instead of coping code to write the session into a char buffer call a
function in debug.c now.

Signed-off-by: Hauke Mehrtens <[email protected]>
  • Loading branch information
hauke committed Jul 21, 2013
1 parent dd9055e commit 2e9415f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
7 changes: 7 additions & 0 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ void dump(unsigned char *buf, size_t len) {
printf("%02x", *buf++);
}

void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr)
{
unsigned char addrbuf[72];
dsrv_print_addr(addr, addrbuf, sizeof(addrbuf));
dsrv_log(level, "%s: %s\n", name, addrbuf);
}

#ifndef WITH_CONTIKI
void
dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend) {
Expand Down
6 changes: 6 additions & 0 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ size_t dsrv_print_addr(const struct __session_t *addr, unsigned char *buf, size_

void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend);

void dtls_dsrv_log_addr(log_t level, const char *name, const struct __session_t *addr);

#else /* NDEBUG */

static inline log_t get_log_level()
Expand Down Expand Up @@ -87,6 +89,10 @@ static inline void
dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend)
{}

static inline void
dtls_dsrv_log_addr(log_t level, const char *name, const struct __session_t *addr)
{}

#endif /* NDEBUG */

/* A set of convenience macros for common log levels. */
Expand Down
24 changes: 5 additions & 19 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,15 +933,7 @@ dtls_new_peer(dtls_context_t *ctx,
memset(peer, 0, sizeof(dtls_peer_t));
memcpy(&peer->session, session, sizeof(session_t));

#ifndef NDEBUG
{
unsigned char addrbuf[72];
dsrv_print_addr(session, addrbuf, sizeof(addrbuf));
printf("dtls_new_peer: %s\n", addrbuf);
dump((unsigned char *)session, sizeof(session_t));
printf("\n");
}
#endif
dtls_dsrv_log_addr(LOG_DEBUG, "dtls_new_peer", session);
/* initially allow the NULL cipher */
CURRENT_CONFIG(peer)->cipher = TLS_NULL_WITH_NULL_NULL;

Expand Down Expand Up @@ -2995,19 +2987,13 @@ dtls_handle_message(dtls_context_t *ctx,
(without MAC and padding) */

peer = dtls_get_peer(ctx, session);
#ifndef NDEBUG
if (!peer) {
unsigned char addrbuf[72];

printf("dtls_handle_message: PEER NOT FOUND\n");
dsrv_print_addr(session, addrbuf, sizeof(addrbuf));
printf(" %s\n", addrbuf);
dump((unsigned char *)session, sizeof(session_t));
printf("\n");
if (!peer) {
debug("dtls_handle_message: PEER NOT FOUND\n");
dtls_dsrv_log_addr(LOG_DEBUG, "peer addr", session);
} else {
printf("dtls_handle_message: FOUND PEER\n");
debug("dtls_handle_message: FOUND PEER\n");
}
#endif /* NDEBUG */

if (!peer) {

Expand Down

0 comments on commit 2e9415f

Please sign in to comment.