diff options
author | Harald Welte <laforge@gnumonks.org> | 2009-02-28 13:08:01 +0000 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2009-02-28 13:08:01 +0000 |
commit | 3cc4bf517f4eb7f5ab0dd9e02cf7a7bc3106e1ff (patch) | |
tree | 6743514de65bc3ba99cd1f94634940c6117d04ab | |
parent | 51f38457e54a9d8c50d7d77e9b7e92465475cf84 (diff) |
make hexdump return a 'char *' rather than printing by itself
-rw-r--r-- | include/openbsc/debug.h | 2 | ||||
-rw-r--r-- | src/debug.c | 16 | ||||
-rw-r--r-- | src/input/ipaccess.c | 10 | ||||
-rw-r--r-- | src/input/misdn.c | 23 | ||||
-rw-r--r-- | src/rs232.c | 10 |
5 files changed, 25 insertions, 36 deletions
diff --git a/include/openbsc/debug.h b/include/openbsc/debug.h index e42c9f192..ec9cbbb3c 100644 --- a/include/openbsc/debug.h +++ b/include/openbsc/debug.h @@ -27,7 +27,7 @@ #define static_assert(exp, name) typedef int dummy##name [(exp) ? 1 : -1]; -void hexdump(unsigned char *buf, int len); +char *hexdump(unsigned char *buf, int len); void debugp(unsigned int subsys, char *file, int line, int cont, const char *format, ...); void debug_parse_category_mask(const char* mask); void debug_use_color(int use_color); diff --git a/src/debug.c b/src/debug.c index c071df0a9..735fce391 100644 --- a/src/debug.c +++ b/src/debug.c @@ -127,12 +127,22 @@ void debugp(unsigned int subsys, char *file, int line, int cont, const char *for fflush(outfd); } -void hexdump(unsigned char *buf, int len) +static char hexd_buff[4096]; + +char *hexdump(unsigned char *buf, int len) { int i; + char *cur = hexd_buff; + + hexd_buff[0] = 0; for (i = 0; i < len; i++) { - fprintf(stdout, "%02x ", buf[i]); + int len_remain = sizeof(hexd_buff) - (cur - hexd_buff); + int rc = snprintf(cur, len_remain, "%02x ", buf[i]); + if (rc <= 0) + break; + cur += rc; } - fprintf(stdout, "\n"); + hexd_buff[sizeof(hexd_buff)-1] = 0; + return hexd_buff; } diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 98f47fb6c..6c83d6d3d 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -124,10 +124,7 @@ static int handle_ts1_read(struct bsc_fd *bfd) if (hh->proto == IPAC_PROTO_IPACCESS) return ipaccess_rcvmsg(msg, bfd->fd); - if (debug_mask & DMI) { - fprintf(stdout, "RX %u: ", ts_nr); - hexdump(msgb_l2(msg), ret); - } + DEBUGP(DMI, "RX %u: %s\n", ts_nr, hexdump(msgb_l2(msg), ret)); link = e1inp_lookup_sign_link(e1i_ts, 0, hh->proto); if (!link) { @@ -197,10 +194,7 @@ static int handle_ts1_write(struct bsc_fd *bfd) return -EINVAL; } - if (debug_mask & DMI) { - fprintf(stdout, "TX %u: ", ts_nr); - hexdump(l2_data, hh->len); - } + DEBUGP(DMI, "TX %u: %s\n", ts_nr, hexdump(l2_data, hh->len)); ret = send(bfd->fd, msg->data, msg->len, 0); msgb_free(msg); diff --git a/src/input/misdn.c b/src/input/misdn.c index 8acf4c901..245df50d8 100644 --- a/src/input/misdn.c +++ b/src/input/misdn.c @@ -148,10 +148,7 @@ static int handle_ts1_read(struct bsc_fd *bfd) break; case DL_DATA_IND: msg->l2h = msg->data + MISDN_HEADER_LEN; - if (debug_mask & DMI) { - fprintf(stdout, "RX: "); - hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN); - } + DEBUGP(DMI, "RX: %s\n", hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN)); ret = e1inp_rx_ts(e1i_ts, msg, l2addr.tei, l2addr.sapi); break; default: @@ -185,10 +182,8 @@ static int handle_ts1_write(struct bsc_fd *bfd) hh = (struct mISDNhead *) msgb_push(msg, sizeof(*hh)); hh->prim = DL_DATA_REQ; - if (debug_mask & DMI) { - fprintf(stdout, "TX TEI(%d): ", sign_link->tei); - hexdump(l2_data, msg->len - MISDN_HEADER_LEN); - } + DEBUGP(DMI, "TX TEI(%d): %s\n", sign_link->tei, + hexdump(l2_data, msg->len - MISDN_HEADER_LEN)); /* construct the sockaddr */ sa.family = AF_ISDN; @@ -223,10 +218,8 @@ static int handle_tsX_write(struct bsc_fd *bfd) subchan_mux_out(mx, tx_buf+sizeof(*hh), BCHAN_TX_GRAN); - if (debug_mask & DMIB) { - fprintf(stdout, "BCHAN TX: "); - hexdump(tx_buf+sizeof(*hh), BCHAN_TX_GRAN); - } + DEBUGP(DMIB, "BCHAN TX: %s\n", + hexdump(tx_buf+sizeof(*hh), BCHAN_TX_GRAN)); ret = send(bfd->fd, tx_buf, sizeof(*hh) + BCHAN_TX_GRAN, 0); if (ret < sizeof(*hh) + BCHAN_TX_GRAN) @@ -266,10 +259,8 @@ static int handle_tsX_read(struct bsc_fd *bfd) switch (hh->prim) { case PH_DATA_IND: msg->l2h = msg->data + MISDN_HEADER_LEN; - if (debug_mask & DMIB) { - fprintf(stdout, "BCHAN RX: "); - hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN); - } + DEBUGP(DMIB, "BCHAN RX: %s\n", + hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN)); ret = e1inp_rx_ts(e1i_ts, msg, 0, 0); break; case PH_ACTIVATE_IND: diff --git a/src/rs232.c b/src/rs232.c index d0825d9a0..24577ea87 100644 --- a/src/rs232.c +++ b/src/rs232.c @@ -100,10 +100,7 @@ static int handle_ser_write(struct bsc_fd *bfd) return 0; } - if (debug_mask & DMI) { - fprintf(stdout, "RS232 TX: "); - hexdump(msg->data, msg->len); - } + DEBUGP(DMI, "RS232 TX: %s", hexdump(msg->data, msg->len)); /* send over serial line */ written = write(bfd->fd, msg->data, msg->len); @@ -175,10 +172,7 @@ static int handle_ser_read(struct bsc_fd *bfd) if (msg->len > LAPD_HDR_LEN) msg->l2h = msg->data + LAPD_HDR_LEN; - if (debug_mask & DMI) { - fprintf(stdout, "RS232 RX: "); - hexdump(msg->data, msg->len); - } + DEBUGP(DMI, "RS232 RX: %s\n", hexdump(msg->data, msg->len)); rc = handle_serial_msg(msg); } } |