From 9b09738891770367f9878a1a4d1b83bc23217383 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 12 Oct 2015 14:00:19 +0200 Subject: gtp.c: improve 3 error logs. It would print the memory location of the address buffer. Instead, print the human readable host address and port. The current code base supports only IPv4, and thread safety is apparently not required, hence just use inet_ntoa(). (The IPv6 and thread capable version is 4 times longer and harder to read.) --- gtp/gtp.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'gtp') diff --git a/gtp/gtp.c b/gtp/gtp.c index cfce244..08a9d61 100644 --- a/gtp/gtp.c +++ b/gtp/gtp.c @@ -71,6 +71,11 @@ len, osmo_hexdump((const uint8_t *) pack, len), \ ##args); +#define LOGP_WITH_ADDR(ss, level, addr, fmt, args...) \ + LOGP(ss, level, "addr(%s:%d) " fmt, \ + inet_ntoa((addr).sin_addr), htons((addr).sin_port), \ + ##args); + /* API Functions */ const char *gtp_version() @@ -739,10 +744,9 @@ int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen, if (bind((*gsn)->fd0, (struct sockaddr *)&addr, sizeof(addr)) < 0) { (*gsn)->err_socket++; - LOGP(DLGTP, LOGL_ERROR, - "bind(fd0=%d, addr=%lx, len=%d) failed: Error = %s\n", - (*gsn)->fd0, (unsigned long)&addr, sizeof(addr), - strerror(errno)); + LOGP_WITH_ADDR(DLGTP, LOGL_ERROR, addr, + "bind(fd0=%d) failed: Error = %s\n", + (*gsn)->fd0, strerror(errno)); return -1; } @@ -765,10 +769,9 @@ int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen, if (bind((*gsn)->fd1c, (struct sockaddr *)&addr, sizeof(addr)) < 0) { (*gsn)->err_socket++; - LOGP(DLGTP, LOGL_ERROR, - "bind(fd1c=%d, addr=%lx, len=%d) failed: Error = %s\n", - (*gsn)->fd1c, (unsigned long)&addr, sizeof(addr), - strerror(errno)); + LOGP_WITH_ADDR(DLGTP, LOGL_ERROR, addr, + "bind(fd1c=%d) failed: Error = %s\n", + (*gsn)->fd1c, strerror(errno)); return -1; } @@ -791,10 +794,9 @@ int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen, if (bind((*gsn)->fd1u, (struct sockaddr *)&addr, sizeof(addr)) < 0) { (*gsn)->err_socket++; - LOGP(DLGTP, LOGL_ERROR, - "bind(fd1c=%d, addr=%lx, len=%d) failed: Error = %s\n", - (*gsn)->fd1c, (unsigned long)&addr, sizeof(addr), - strerror(errno)); + LOGP_WITH_ADDR(DLGTP, LOGL_ERROR, addr, + "bind(fd1c=%d) failed: Error = %s\n", + (*gsn)->fd1c, strerror(errno)); return -1; } -- cgit v1.2.3