Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/hostname fix error handling.



details:   https://anonhg.NetBSD.org/src/rev/88321d02ea76
branches:  trunk
changeset: 788780:88321d02ea76
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jul 19 15:53:00 2013 +0000

description:
fix error handling.

diffstat:

 bin/hostname/hostname.c |  13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diffs (48 lines):

diff -r 7c6c08483910 -r 88321d02ea76 bin/hostname/hostname.c
--- a/bin/hostname/hostname.c   Fri Jul 19 12:00:30 2013 +0000
+++ b/bin/hostname/hostname.c   Fri Jul 19 15:53:00 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hostname.c,v 1.19 2013/07/19 11:19:23 wiz Exp $ */
+/* $NetBSD: hostname.c,v 1.20 2013/07/19 15:53:00 christos Exp $ */
 
 /*
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)hostname.c 8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: hostname.c,v 1.19 2013/07/19 11:19:23 wiz Exp $");
+__RCSID("$NetBSD: hostname.c,v 1.20 2013/07/19 15:53:00 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -134,7 +134,7 @@
                        i = getnameinfo(ifp->ifa_addr, ifp->ifa_addr->sa_len,
                            buf, sizeof(buf), NULL, 0,
                            Iflag ? NI_NUMERICHOST: NI_NAMEREQD);
-                       if (i == -1) {
+                       if (i) {
                                if (Iflag && i != EAI_NONAME)
                                        errx(1, "getnameinfo: %s",
                                            gai_strerror(i));
@@ -157,8 +157,9 @@
                        hints.ai_family = AF_UNSPEC;
                        hints.ai_socktype = SOCK_DGRAM;
                        hints.ai_flags = AI_CANONNAME;
-                       if (getaddrinfo(hostname, NULL, &hints, &ainfos) == -1)
-                               err(1, "getaddrinfo");
+                       i = getaddrinfo(hostname, NULL, &hints, &ainfos);
+                       if (i)
+                               errx(1, "getaddrinfo: %s", gai_strerror(i));
                        if (ainfos) {
                                if (dflag) {
                                        if ((p = strchr(ainfos->ai_canonname,
@@ -171,7 +172,7 @@
                                                    ai->ai_addrlen,
                                                    buf, sizeof(buf), NULL, 0,
                                                    NI_NUMERICHOST);
-                                               if (i == -1)
+                                               if (i)
                                                        errx(1,
                                                            "getnameinfo: %s",
                                                            gai_strerror(i));



Home | Main Index | Thread Index | Old Index