aboutsummaryrefslogtreecommitdiffstats
path: root/gtp/gtp.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2015-10-12 14:00:19 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-10-12 14:09:57 +0200
commit9b09738891770367f9878a1a4d1b83bc23217383 (patch)
tree4cfa0b6f98aa6e7d2579632e0366996388016b9e /gtp/gtp.c
parentb07d07072e70ac4f920be9dfdf45615193b4ec2d (diff)
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.)
Diffstat (limited to 'gtp/gtp.c')
-rw-r--r--gtp/gtp.c26
1 files changed, 14 insertions, 12 deletions
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;
}