Skip to content

Commit

Permalink
core: udp - print up to first 100 chars from received packet
Browse files Browse the repository at this point in the history
(cherry picked from commit 83c3704)
  • Loading branch information
miconda committed Nov 21, 2017
1 parent 055f6d2 commit 9f8c93e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/udp_server.c
Expand Up @@ -425,6 +425,10 @@ int udp_rcv_loop()
unsigned int fromlen;
struct receive_info ri;
sr_event_param_t evp = {0};
char printbuf[512];
int i;
int j;
int l;


from=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union));
Expand Down Expand Up @@ -466,6 +470,23 @@ int udp_rcv_loop()
/* we must 0-term the messages, receive_msg expects it */
buf[len]=0; /* no need to save the previous char */

if(is_printable(L_DBG) && len>10) {
j = 0;
for(i=0; i<len && i<100; i++) {
if(isprint(buf[i])) {
printbuf[j++] = buf[i];
} else {
l = snprintf(printbuf+j, 6, " %02X ", buf[i]);
if(l<0 || l>=6) {
LM_ERR("print buffer building failed\n");
goto error;
}
j += l;
}
}
LM_DBG("received on udp socket: (%d/%d) [[%.*s]]\n",
j, len, len, printbuf);
}
ri.src_su=*from;
su2ip_addr(&ri.src_ip, from);
ri.src_port=su_getport(from);
Expand Down

0 comments on commit 9f8c93e

Please sign in to comment.