|
From: <bul...@us...> - 2013-06-03 18:10:07
|
Revision: 22793
http://sourceforge.net/p/bzflag/code/22793
Author: bullet_catcher
Date: 2013-06-03 18:10:04 +0000 (Mon, 03 Jun 2013)
Log Message:
-----------
Define MAXHOSTNAMELEN if it does not already exist.
Ensure host name buffer null termination regardless of gethostname() implementation details.
Modified Paths:
--------------
trunk/bzflag/include/network.h
trunk/bzflag/src/net/Address.cxx
Modified: trunk/bzflag/include/network.h
===================================================================
--- trunk/bzflag/include/network.h 2013-06-02 20:16:08 UTC (rev 22792)
+++ trunk/bzflag/include/network.h 2013-06-03 18:10:04 UTC (rev 22793)
@@ -93,8 +93,6 @@
#else /* !defined(_WIN32) */
-#define MAXHOSTNAMELEN 64
-
#ifndef EINPROGRESS
#define EINPROGRESS WSAEWOULDBLOCK
#endif
Modified: trunk/bzflag/src/net/Address.cxx
===================================================================
--- trunk/bzflag/src/net/Address.cxx 2013-06-02 20:16:08 UTC (rev 22792)
+++ trunk/bzflag/src/net/Address.cxx 2013-06-03 18:10:04 UTC (rev 22793)
@@ -37,6 +37,17 @@
extern "C" int inet_aton(const char *, struct in_addr *);
#endif
+// RFC 1035 limits the length of a fully qualified domain name to 255
+// octets, so calling sysconf(_SC_HOST_NAME_MAX) to find some other
+// limit and/or dynamically expanding the gethostname() buffer on
+// demand are complex solutions to a problem that does not exist in
+// the environments for which BZFlag is designed. The value chosen
+// here provides a substantial margin in case the RFC 1035 limit is
+// raised in the future.
+#ifndef MAXHOSTNAMELEN
+#define MAXHOSTNAMELEN 511
+#endif
+
//
// Address
//
@@ -136,10 +147,14 @@
if (name.length() > 0)
hent = gethostbyname(name.c_str());
else {
+ // use our own host name if none is specified
char hostname[MAXHOSTNAMELEN+1];
- if (gethostname(hostname, sizeof(hostname)) >= 0)
- // use our own host name if none is specified
+ if (gethostname(hostname, MAXHOSTNAMELEN) >= 0) {
+ // ensure null termination regardless of
+ // gethostname() implementation details
+ hostname[MAXHOSTNAMELEN] = '\0';
hent = gethostbyname(hostname);
+ }
}
return hent;
}
@@ -263,4 +278,3 @@
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|