diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-04-16 16:58:15 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-04-16 16:58:15 +0200 |
commit | c5178a4d21cf8ca3362b8a8394d0e762801550a4 (patch) | |
tree | 0916303e0cd18e00397a6eb28a64b32aa5908c4d /net.c | |
parent | 65cdfc1777e1c189f28dfe11fa1ab0d08930b458 (diff) | |
parent | 11a526bcee95dab6a5bf2cc25a07dc6d65eaa177 (diff) | |
download | rsyslog-c5178a4d21cf8ca3362b8a8394d0e762801550a4.tar.gz rsyslog-c5178a4d21cf8ca3362b8a8394d0e762801550a4.tar.bz2 rsyslog-c5178a4d21cf8ca3362b8a8394d0e762801550a4.zip |
Merge branch 'master' into beta
3.17.x is the new beta
Conflicts:
ChangeLog
configure.ac
Diffstat (limited to 'net.c')
-rw-r--r-- | net.c | 47 |
1 files changed, 43 insertions, 4 deletions
@@ -580,7 +580,7 @@ static int isAllowedSender(struct AllowedSenders *pAllowRoot, struct sockaddr *p static int should_use_so_bsdcompat(void) { -#ifndef BSD +#ifndef OS_BSD static int init_done; static int so_bsdcompat_is_obsolete; @@ -608,9 +608,9 @@ should_use_so_bsdcompat(void) so_bsdcompat_is_obsolete = 1; } return !so_bsdcompat_is_obsolete; -#else /* #ifndef BSD */ +#else /* #ifndef OS_BSD */ return 1; -#endif /* #ifndef BSD */ +#endif /* #ifndef OS_BSD */ } #ifndef SO_BSDCOMPAT /* this shall prevent compiler errors due to undfined name */ @@ -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. */ @@ -948,7 +986,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) /* We need to enable BSD compatibility. Otherwise an attacker * could flood our log files by sending us tons of ICMP errors. */ -#if !defined(BSD) && !defined(__hpux) +#if !defined(OS_BSD) && !defined(__hpux) if (should_use_so_bsdcompat()) { if (setsockopt(*s, SOL_SOCKET, SO_BSDCOMPAT, (char *) &on, sizeof(on)) < 0) { @@ -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) |