Skip to content

Commit fe937d1

Browse files
committed
orte: !FQDN implementation to use opal_net_isaddr
* Switch to use opal_net_isaddr() for checking if a name is an IP address - as it is a bit cleaner, and uses common functionality.
1 parent 3274203 commit fe937d1

File tree

5 files changed

+35
-77
lines changed

5 files changed

+35
-77
lines changed

orte/mca/rmaps/rank_file/rmaps_rank_file.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@
3434
#ifdef HAVE_UNISTD_H
3535
#include <unistd.h>
3636
#endif /* HAVE_UNISTD_H */
37-
#if HAVE_ARPA_INET_H
38-
#include <arpa/inet.h>
39-
#endif
4037
#include <string.h>
4138

4239
#include "opal/util/argv.h"
4340
#include "opal/util/if.h"
41+
#include "opal/util/net.h"
4442
#include "opal/class/opal_pointer_array.h"
4543
#include "opal/mca/hwloc/base/base.h"
4644

@@ -493,16 +491,11 @@ static int orte_rmaps_rank_file_parse(const char *rankfile)
493491
}
494492
opal_argv_free (argv);
495493

496-
// Strip off the FQDN if present
497-
if( !orte_keep_fqdn_hostnames ) {
494+
// Strip off the FQDN if present, ignore IP addresses
495+
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(node_name) ) {
498496
char *ptr;
499-
struct in_addr buf;
500-
/* if the nodename is an IP address, do not mess with it! */
501-
if (0 == inet_pton(AF_INET, node_name, &buf) &&
502-
0 == inet_pton(AF_INET6, node_name, &buf)) {
503-
if (NULL != (ptr = strchr(node_name, '.'))) {
504-
*ptr = '\0';
505-
}
497+
if (NULL != (ptr = strchr(node_name, '.'))) {
498+
*ptr = '\0';
506499
}
507500
}
508501

orte/mca/rmaps/seq/rmaps_seq.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <ctype.h>
3636

3737
#include "opal/util/if.h"
38+
#include "opal/util/net.h"
3839
#include "opal/mca/hwloc/hwloc.h"
3940

4041
#include "orte/util/show_help.h"
@@ -191,17 +192,11 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
191192
sq->cpuset = strdup(sep);
192193
}
193194

194-
// Strip off the FQDN if present
195-
if( !orte_keep_fqdn_hostnames ) {
195+
// Strip off the FQDN if present, ignore IP addresses
196+
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(hstname) ) {
196197
char *ptr;
197-
struct in_addr buf;
198-
199-
/* if the nodename is an IP address, do not mess with it! */
200-
if (0 == inet_pton(AF_INET, hstname, &buf) &&
201-
0 == inet_pton(AF_INET6, hstname, &buf)) {
202-
if (NULL != (ptr = strchr(hstname, '.'))) {
203-
*ptr = '\0';
204-
}
198+
if (NULL != (ptr = strchr(hstname, '.'))) {
199+
*ptr = '\0';
205200
}
206201
}
207202

@@ -301,16 +296,11 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
301296
sq->cpuset = strdup(sep);
302297
}
303298

304-
// Strip off the FQDN if present
305-
if( !orte_keep_fqdn_hostnames ) {
299+
// Strip off the FQDN if present, ignore IP addresses
300+
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(hstname) ) {
306301
char *ptr;
307-
struct in_addr buf;
308-
/* if the nodename is an IP address, do not mess with it! */
309-
if (0 == inet_pton(AF_INET, hstname, &buf) &&
310-
0 == inet_pton(AF_INET6, hstname, &buf)) {
311-
if (NULL != (ptr = strchr(hstname, '.'))) {
312-
(*ptr) = '\0';
313-
}
302+
if (NULL != (ptr = strchr(hstname, '.'))) {
303+
(*ptr) = '\0';
314304
}
315305
}
316306

orte/util/dash_host/dash_host.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424
#include "orte_config.h"
2525

2626
#include <string.h>
27-
#if HAVE_ARPA_INET_H
28-
#include <arpa/inet.h>
29-
#endif
3027

3128
#include "orte/constants.h"
3229
#include "orte/types.h"
3330

3431
#include "orte/util/show_help.h"
3532
#include "opal/util/argv.h"
3633
#include "opal/util/if.h"
34+
#include "opal/util/net.h"
3735

3836
#include "orte/mca/ras/base/base.h"
3937
#include "orte/mca/plm/plm_types.h"
@@ -211,16 +209,11 @@ int orte_util_add_dash_host_nodes(opal_list_t *nodes,
211209
ndname = mini_map[i];
212210
}
213211

214-
// Strip off the FQDN if present
215-
if( !orte_keep_fqdn_hostnames ) {
212+
// Strip off the FQDN if present, ignore IP addresses
213+
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(ndname) ) {
216214
char *ptr;
217-
struct in_addr buf;
218-
/* if the nodename is an IP address, do not mess with it! */
219-
if (0 == inet_pton(AF_INET, ndname, &buf) &&
220-
0 == inet_pton(AF_INET6, ndname, &buf)) {
221-
if (NULL != (ptr = strchr(ndname, '.'))) {
222-
*ptr = '\0';
223-
}
215+
if (NULL != (ptr = strchr(ndname, '.'))) {
216+
*ptr = '\0';
224217
}
225218
}
226219

orte/util/hostfile/hostfile.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
#ifdef HAVE_UNISTD_H
2929
#include <unistd.h>
3030
#endif
31-
#if HAVE_ARPA_INET_H
32-
#include <arpa/inet.h>
33-
#endif
3431
#include <errno.h>
3532
#include <string.h>
3633
#include <sys/stat.h>
@@ -41,6 +38,7 @@
4138
#include "opal/mca/mca.h"
4239
#include "opal/mca/base/base.h"
4340
#include "opal/util/if.h"
41+
#include "opal/util/net.h"
4442
#include "opal/mca/installdirs/installdirs.h"
4543

4644
#include "orte/util/show_help.h"
@@ -168,16 +166,11 @@ static int hostfile_parse_line(int token, opal_list_t* updates,
168166
}
169167
opal_argv_free (argv);
170168

171-
// Strip off the FQDN if present
172-
if( !orte_keep_fqdn_hostnames ) {
169+
// Strip off the FQDN if present, ignore IP addresses
170+
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(node_name) ) {
173171
char *ptr;
174-
struct in_addr buf;
175-
/* if the nodename is an IP address, do not mess with it! */
176-
if (0 == inet_pton(AF_INET, node_name, &buf) &&
177-
0 == inet_pton(AF_INET6, node_name, &buf)) {
178-
if (NULL != (ptr = strchr(node_name, '.'))) {
179-
*ptr = '\0';
180-
}
172+
if (NULL != (ptr = strchr(node_name, '.'))) {
173+
*ptr = '\0';
181174
}
182175
}
183176

@@ -288,16 +281,11 @@ static int hostfile_parse_line(int token, opal_list_t* updates,
288281
}
289282
opal_argv_free (argv);
290283

291-
// Strip off the FQDN if present
292-
if( !orte_keep_fqdn_hostnames ) {
284+
// Strip off the FQDN if present, ignore IP addresses
285+
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(node_name) ) {
293286
char *ptr;
294-
struct in_addr buf;
295-
/* if the nodename is an IP address, do not mess with it! */
296-
if (0 == inet_pton(AF_INET, node_name, &buf) &&
297-
0 == inet_pton(AF_INET6, node_name, &buf)) {
298-
if (NULL != (ptr = strchr(node_name, '.'))) {
299-
*ptr = '\0';
300-
}
287+
if (NULL != (ptr = strchr(node_name, '.'))) {
288+
*ptr = '\0';
301289
}
302290
}
303291

orte/util/proc_info.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (c) 2012 Los Alamos National Security, LLC.
1414
* All rights reserved.
1515
* Copyright (c) 2014-2016 Intel, Inc. All rights reserved
16+
* Copyright (c) 2016 IBM Corporation. All rights reserved.
1617
* $COPYRIGHT$
1718
*
1819
* Additional copyrights may follow
@@ -32,9 +33,6 @@
3233
#ifdef HAVE_SYS_TYPES_H
3334
#include <sys/types.h>
3435
#endif
35-
#if HAVE_ARPA_INET_H
36-
#include <arpa/inet.h>
37-
#endif
3836
#include <ctype.h>
3937

4038
#include "opal/mca/base/base.h"
@@ -173,16 +171,12 @@ int orte_proc_info(void)
173171
/* add this to our list of aliases */
174172
opal_argv_append_nosize(&orte_process_info.aliases, hostname);
175173

176-
if (!orte_keep_fqdn_hostnames) {
177-
/* if the nodename is an IP address, do not mess with it! */
178-
if (0 == inet_pton(AF_INET, hostname, &buf) &&
179-
0 == inet_pton(AF_INET6, hostname, &buf)) {
180-
/* not an IP address, so remove any domain info */
181-
if (NULL != (ptr = strchr(hostname, '.'))) {
182-
*ptr = '\0';
183-
/* add this to our list of aliases */
184-
opal_argv_append_nosize(&orte_process_info.aliases, hostname);
185-
}
174+
// Strip off the FQDN if present, ignore IP addresses
175+
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(hostname) ) {
176+
if (NULL != (ptr = strchr(hostname, '.'))) {
177+
*ptr = '\0';
178+
/* add this to our list of aliases */
179+
opal_argv_append_nosize(&orte_process_info.aliases, hostname);
186180
}
187181
}
188182

0 commit comments

Comments
 (0)