Skip to content

No standardization on hostname max length #1551

@ghost

Description

I was tracing a program in examples/ this evening and noticed that we have a myriad of different max hostname lengths ranging from 20 - 1024, and slight variations in handling gethostname():

https://gist.github.com/kmroz/6fb7699712d41abb4cd2ba9553163c82

I thought it might be a good idea to use, if available, what's in limits.h:HOST_NAME_MAX. Something like:

diff --git a/opal/include/opal_config_bottom.h b/opal/include/opal_config_bottom.hindex f906278..c2f1643 100644
--- a/opal/include/opal_config_bottom.h
+++ b/opal/include/opal_config_bottom.h
@@ -491,7 +491,14 @@ static inline uint16_t ntohs(uint16_t netvar) { return netvar; }      
#include <hostLib.h>

#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 64
+/* From limits.h. Since we're using gethostname(), we add 1 to the max to allow
+ * for null termination.
+ */
+#ifdef HOST_NAME_MAX
+#define MAXHOSTNAMELEN HOST_NAME_MAX + 1
+#else
+#define MAXHOSTNAMELEN 64 + 1
+#endif
#endif
#endif

and sift through all callers of gethostname(). I have some concerns though:

  1. I'm probably going to be stomping on components that may have an 'upstream' somewhere?
  2. Non-POSIX systems might have some issue with this?

Perhaps this is barking up the wrong tree?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions