From fc9707c334a319edd760405053d169c873b08847 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Fri, 23 Oct 2015 17:36:55 +0000 Subject: [PATCH] Quagga needs better debugs in lib/sockunion.c Signed-off-by: Daniel Walton Reviewed-by: Donald Sharp Reviewed-by: Dinesh G Dutt Ticket: CM-7233 --- lib/sockunion.c | 50 ++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/lib/sockunion.c b/lib/sockunion.c index 968b126ee2..7e9e78628c 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -206,6 +206,25 @@ sockunion_normalise_mapped (union sockunion *su) #endif /* HAVE_IPV6 */ } +/* return sockunion structure : this function should be revised. */ +static const char * +sockunion_log (union sockunion *su, char *buf, size_t len) +{ + switch (su->sa.sa_family) + { + case AF_INET: + return inet_ntop(AF_INET, &su->sin.sin_addr, buf, len); + + case AF_INET6: + return inet_ntop(AF_INET6, &(su->sin6.sin6_addr), buf, len); + break; + + default: + snprintf (buf, len, "af_unknown %d ", su->sa.sa_family); + return buf; + } +} + /* Return socket of sockunion. */ int sockunion_socket (union sockunion *su) @@ -215,7 +234,9 @@ sockunion_socket (union sockunion *su) sock = socket (su->sa.sa_family, SOCK_STREAM, 0); if (sock < 0) { - zlog (NULL, LOG_WARNING, "Can't make socket : %s", safe_strerror (errno)); + char buf[SU_ADDRSTRLEN]; + zlog (NULL, LOG_WARNING, "Can't make socket for %s : %s", + sockunion_log (su, buf, SU_ADDRSTRLEN), safe_strerror (errno)); return -1; } @@ -257,27 +278,6 @@ sockunion_sizeof (union sockunion *su) return ret; } -/* return sockunion structure : this function should be revised. */ -static const char * -sockunion_log (union sockunion *su, char *buf, size_t len) -{ - switch (su->sa.sa_family) - { - case AF_INET: - return inet_ntop(AF_INET, &su->sin.sin_addr, buf, len); - -#ifdef HAVE_IPV6 - case AF_INET6: - return inet_ntop(AF_INET6, &(su->sin6.sin6_addr), buf, len); - break; -#endif /* HAVE_IPV6 */ - - default: - snprintf (buf, len, "af_unknown %d ", su->sa.sa_family); - return buf; - } -} - /* sockunion_connect returns -1 : error occured 0 : connect success @@ -407,7 +407,11 @@ sockunion_bind (int sock, union sockunion *su, unsigned short port, ret = bind (sock, (struct sockaddr *)su, size); if (ret < 0) - zlog (NULL, LOG_WARNING, "can't bind socket : %s", safe_strerror (errno)); + { + char buf[SU_ADDRSTRLEN]; + zlog (NULL, LOG_WARNING, "can't bind socket for %s : %s", + sockunion_log (su, buf, SU_ADDRSTRLEN), safe_strerror (errno)); + } return ret; } -- 2.39.5