From dd2ef78efb970f88da0e5ce919eda3c896df97e5 Mon Sep 17 00:00:00 2001 From: rread Date: Thu, 3 Jul 2003 23:05:04 +0000 Subject: [PATCH] b=1469 Create a simple wrapper around gethostbyname, so we can print a sane error message when the host is not found, instead of "No such file or directory." --- lnet/utils/portals.c | 45 +++++++++++++++++++++++++++--------------- lustre/portals/utils/portals.c | 45 +++++++++++++++++++++++++++--------------- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/lnet/utils/portals.c b/lnet/utils/portals.c index 90d66f5..a89f4f7 100644 --- a/lnet/utils/portals.c +++ b/lnet/utils/portals.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -106,6 +107,27 @@ nal2name (int nal) return ((e == NULL) ? "???" : e->name); } +static struct hostent * +ptl_gethostbyname(char * hname) { + struct hostent *he; + he = gethostbyname(hname); + if (!he) { + switch(h_errno) { + case HOST_NOT_FOUND: + case NO_ADDRESS: + fprintf(stderr, "Unable to resolve hostname: %s\n", + hname); + break; + default: + fprintf(stderr, "gethostbyname error: %s\n", + strerror(errno)); + break; + } + return NULL; + } + return he; +} + int ptl_parse_nid (ptl_nid_t *nidp, char *str) { @@ -127,7 +149,7 @@ ptl_parse_nid (ptl_nid_t *nidp, char *str) if ((('a' <= str[0] && str[0] <= 'z') || ('A' <= str[0] && str[0] <= 'Z')) && - (he = gethostbyname (str)) != NULL) + (he = ptl_gethostbyname (str)) != NULL) { __u32 addr = *(__u32 *)he->h_addr; @@ -351,12 +373,9 @@ int jt_ptl_connect(int argc, char **argv) goto usage; } - he = gethostbyname(argv[1]); - if (!he) { - fprintf(stderr, "gethostbyname error: %s\n", - strerror(errno)); + he = ptl_gethostbyname(argv[1]); + if (!he) return -1; - } g_port = atol(argv[2]); @@ -525,12 +544,9 @@ int jt_ptl_disconnect(int argc, char **argv) PORTAL_IOC_INIT(data); if (argc == 2) { - he = gethostbyname(argv[1]); - if (!he) { - fprintf(stderr, "gethostbyname error: %s\n", - strerror(errno)); + he = ptl_gethostbyname(argv[1]); + if (!he) return -1; - } data.ioc_nid = ntohl (*(__u32 *)he->h_addr); /* HOST byte order */ @@ -582,12 +598,9 @@ int jt_ptl_push_connection (int argc, char **argv) PORTAL_IOC_INIT(data); if (argc == 2) { - he = gethostbyname(argv[1]); - if (!he) { - fprintf(stderr, "gethostbyname error: %s\n", - strerror(errno)); + he = ptl_gethostbyname(argv[1]); + if (!he) return -1; - } data.ioc_nid = ntohl (*(__u32 *)he->h_addr); /* HOST byte order */ diff --git a/lustre/portals/utils/portals.c b/lustre/portals/utils/portals.c index 90d66f5..a89f4f7 100644 --- a/lustre/portals/utils/portals.c +++ b/lustre/portals/utils/portals.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -106,6 +107,27 @@ nal2name (int nal) return ((e == NULL) ? "???" : e->name); } +static struct hostent * +ptl_gethostbyname(char * hname) { + struct hostent *he; + he = gethostbyname(hname); + if (!he) { + switch(h_errno) { + case HOST_NOT_FOUND: + case NO_ADDRESS: + fprintf(stderr, "Unable to resolve hostname: %s\n", + hname); + break; + default: + fprintf(stderr, "gethostbyname error: %s\n", + strerror(errno)); + break; + } + return NULL; + } + return he; +} + int ptl_parse_nid (ptl_nid_t *nidp, char *str) { @@ -127,7 +149,7 @@ ptl_parse_nid (ptl_nid_t *nidp, char *str) if ((('a' <= str[0] && str[0] <= 'z') || ('A' <= str[0] && str[0] <= 'Z')) && - (he = gethostbyname (str)) != NULL) + (he = ptl_gethostbyname (str)) != NULL) { __u32 addr = *(__u32 *)he->h_addr; @@ -351,12 +373,9 @@ int jt_ptl_connect(int argc, char **argv) goto usage; } - he = gethostbyname(argv[1]); - if (!he) { - fprintf(stderr, "gethostbyname error: %s\n", - strerror(errno)); + he = ptl_gethostbyname(argv[1]); + if (!he) return -1; - } g_port = atol(argv[2]); @@ -525,12 +544,9 @@ int jt_ptl_disconnect(int argc, char **argv) PORTAL_IOC_INIT(data); if (argc == 2) { - he = gethostbyname(argv[1]); - if (!he) { - fprintf(stderr, "gethostbyname error: %s\n", - strerror(errno)); + he = ptl_gethostbyname(argv[1]); + if (!he) return -1; - } data.ioc_nid = ntohl (*(__u32 *)he->h_addr); /* HOST byte order */ @@ -582,12 +598,9 @@ int jt_ptl_push_connection (int argc, char **argv) PORTAL_IOC_INIT(data); if (argc == 2) { - he = gethostbyname(argv[1]); - if (!he) { - fprintf(stderr, "gethostbyname error: %s\n", - strerror(errno)); + he = ptl_gethostbyname(argv[1]); + if (!he) return -1; - } data.ioc_nid = ntohl (*(__u32 *)he->h_addr); /* HOST byte order */ -- 1.8.3.1