summaryrefslogtreecommitdiffstats
path: root/net.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-04-10 09:31:35 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2008-04-10 09:31:35 +0200
commita7860f4dab1afcf94698bc2f52413e94eed64b52 (patch)
tree5d0ec74cf113c9e1df9673ce26d5cb21c724cd23 /net.c
parent3d87bbfa9c9c6d111861fcfa393c887b0c7ef99e (diff)
downloadrsyslog-a7860f4dab1afcf94698bc2f52413e94eed64b52.tar.gz
rsyslog-a7860f4dab1afcf94698bc2f52413e94eed64b52.tar.xz
rsyslog-a7860f4dab1afcf94698bc2f52413e94eed64b52.zip
removed dependency on MAXHOSTNAMELEN as much as it made sense.
GNU/Hurd does not define it (because it has no limit), and we have taken care for cases where it is undefined now. However, some very few places remain where IMHO it currently is not worth fixing the code. If it is not defined, we have used a generous value of 1K, which is above IETF RFC's on hostname length at all. The memory consumption is no issue, as there are only a handful of this buffers allocated *per run* -- that's also the main reason why we consider it not worth to be fixed any further.
Diffstat (limited to 'net.c')
-rw-r--r--net.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/net.c b/net.c
index ab669323..43e13eb3 100644
--- a/net.c
+++ b/net.c
@@ -852,6 +852,44 @@ finalize_it:
}
+/* get the name of the local host. A pointer to a character pointer is passed
+ * in, which on exit points to the local hostname. This buffer is dynamically
+ * allocated and must be free()ed by the caller. If the functions returns an
+ * error, the pointer is NULL. This function is based on GNU/Hurd's localhostname
+ * function.
+ * rgerhards, 20080-04-10
+ */
+static rsRetVal
+getLocalHostname(uchar **ppName)
+{
+ DEFiRet;
+ uchar *buf = NULL;
+ size_t buf_len = 0;
+
+ assert(ppName != NULL);
+
+ do {
+ if(buf == NULL) {
+ buf_len = 128; /* Initial guess */
+ CHKmalloc(buf = malloc(buf_len));
+ } else {
+ buf_len += buf_len;
+ CHKmalloc(buf = realloc (buf, buf_len));
+ }
+ } while((gethostname((char*)buf, buf_len) == 0 && !memchr (buf, '\0', buf_len)) || errno == ENAMETOOLONG);
+
+ *ppName = buf;
+ buf = NULL;
+
+finalize_it:
+ if(iRet != RS_RET_OK) {
+ if(buf != NULL)
+ free(buf);
+ }
+ RETiRet;
+}
+
+
/* closes the UDP listen sockets (if they exist) and frees
* all dynamically assigned memory.
*/
@@ -1047,6 +1085,7 @@ CODESTARTobjQueryInterface(net)
pIf->closeUDPListenSockets = closeUDPListenSockets;
pIf->isAllowedSender = isAllowedSender;
pIf->should_use_so_bsdcompat = should_use_so_bsdcompat;
+ pIf->getLocalHostname = getLocalHostname;
finalize_it:
ENDobjQueryInterface(net)