summaryrefslogtreecommitdiffstats
path: root/plugins/imudp/imudp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/imudp/imudp.c')
-rw-r--r--plugins/imudp/imudp.c55
1 files changed, 51 insertions, 4 deletions
diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c
index f3a2b72a..f8bea91a 100644
--- a/plugins/imudp/imudp.c
+++ b/plugins/imudp/imudp.c
@@ -46,6 +46,7 @@ TERM_SYNC_TYPE(eTermSync_NONE)
DEF_IMOD_STATIC_DATA
static int *udpLstnSocks = NULL; /* Internet datagram sockets, first element is nbr of elements
* read-only after init(), but beware of restart! */
+static uchar *pszLstnPort = NULL;
typedef struct _instanceData {
} instanceData;
@@ -153,8 +154,47 @@ ENDrunInput
BEGINwillRun
CODESTARTwillRun
PrintAllowedSenders(1); /* UDP */
- if((udpLstnSocks = create_udp_socket(NULL, (uchar*)LogPort, 1)) != NULL)
+ if((udpLstnSocks = create_udp_socket(NULL, (pszLstnPort == NULL) ? (uchar*) "514" : pszLstnPort, 1)) != NULL)
dbgprintf("Opened %d syslog UDP port(s).\n", *udpLstnSocks);
+#if 0
+/* TODO: think if we need this code - so far, I simply use "syslog" as port name
+ * if none is specified. That looks OK to me - but I do not remove that code here
+ * so that we can think about it once again. Please note that the code here needs
+ * to be adapted, I haven't done that because I came to the idea I do not need it...
+ * rgerahrds, 2007-12-26
+ */
+ struct servent *sp;
+ if(pszLstnPort == NULL) {
+ /* I was told by an IPv6 expert that calling getservbyname() seems to be
+ * still valid, at least for the use case we have. So I re-enabled that
+ * code. rgerhards, 2007-07-02
+ */
+ /* we shall use the default syslog/udp port, so let's
+ * look it up.
+ * TODO: getservbyname() is not thread-safe, we need to replace it.
+ */
+ sp = getservbyname("syslog", "udp");
+ if (sp == NULL) {
+ errno = 0;
+ logerror("Could not find syslog/udp port in /etc/services. "
+ "Now using IANA-assigned default of 514.");
+ LogPort = "514";
+ } else {
+ /* we can dynamically allocate memory here and do NOT need
+ * to care about freeing it because even though init() is
+ * called on each restart, the LogPort can never again be
+ * "0". So we will only once run into this part of the code
+ * here. rgerhards, 2007-07-02
+ * We save ourselfs the hassle of dynamic memory management
+ * for the very same reason.
+ */
+// we need to do dynamic memory alloc here!
+
+ snprintf(defPort, sizeof(defPort), "%d", ntohs(sp->s_port));
+ LogPort = defPort;
+ }
+ }
+#endif
ENDwillRun
@@ -167,7 +207,10 @@ dbgprintf("call clearAllowedSenders(0x%lx)\n", (unsigned long) pAllowedSenders_U
clearAllowedSenders (pAllowedSenders_UDP);
pAllowedSenders_UDP = NULL;
}
- closeUDPListenSockets(udpLstnSocks);
+ if(udpLstnSocks != NULL)
+ closeUDPListenSockets(udpLstnSocks);
+ if(pszLstnPort != NULL)
+ free(pszLstnPort);
ENDafterRun
@@ -193,6 +236,10 @@ ENDqueryEtryPt
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
{
+ if(pszLstnPort != NULL) {
+ free(pszLstnPort);
+ pszLstnPort = NULL;
+ }
return RS_RET_OK;
}
@@ -202,8 +249,8 @@ CODESTARTmodInit
*ipIFVersProvided = 1; /* so far, we only support the initial definition */
CODEmodInit_QueryRegCFSLineHdlr
/* register config file handlers */
- //CHKiRet(omsdRegCFSLineHdlr((uchar *)"omitlocallogging", 0, eCmdHdlrBinary,
- // NULL, &bOmitLocalLogging, STD_LOADABLE_MODULE_ID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"udplistenport", 0, eCmdHdlrGetWord,
+ NULL, &pszLstnPort, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
ENDmodInit