Permalink
Browse files

alert_unixsock: Get rid of global alertaddr by connecting to the sock…

…et at

startup.  This should allow multiple sockets to be used at the same time.
This also checks the socket name, whereas previously incorrect filenames
were simply ignored.
  • Loading branch information...
Martijn van Oosterhout authored and firnsy committed Mar 10, 2012
1 parent c571f09 commit 55bad05c8a906b23b132d63bf4db7a2ab6524d2a
Showing with 14 additions and 9 deletions.
  1. +14 −9 src/output-plugins/spo_alert_unixsock.c
@@ -78,12 +78,6 @@ typedef struct _SpoAlertUnixSockData
} SpoAlertUnixSockData;
-#ifndef WIN32
-struct sockaddr_un alertaddr;
-#else
-struct sockaddr_in alertaddr;
-#endif
-
void AlertUnixSockInit(char *);
void AlertUnixSock(Packet *, void *, uint32_t, void *);
SpoAlertUnixSockData *ParseAlertUnixSockArgs(char *);
@@ -304,8 +298,7 @@ void AlertUnixSock(Packet *p, void *event, uint32_t event_type, void *arg)
}
- if(sendto(data->alertsd,(const void *)&alertpkt,sizeof(Alertpkt),
- 0,(struct sockaddr *)&alertaddr,sizeof(alertaddr))==-1)
+ if(send(data->alertsd,(const void *)&alertpkt,sizeof(Alertpkt),0)==-1)
{
/* whatever we do to sign that some alerts could be missed */
}
@@ -326,6 +319,12 @@ void AlertUnixSock(Packet *p, void *event, uint32_t event_type, void *arg)
*/
void OpenAlertSock(SpoAlertUnixSockData *data)
{
+#ifndef WIN32
+ struct sockaddr_un alertaddr;
+#else
+ struct sockaddr_in alertaddr;
+#endif
+
if(access(data->filename, W_OK))
{
ErrorMessage("%s file doesn't exist or isn't writable!\n",
@@ -339,10 +338,16 @@ void OpenAlertSock(SpoAlertUnixSockData *data)
alertaddr.sun_family = AF_UNIX;
- if((data->alertsd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
+ if((data->alertsd = socket(AF_UNIX, data->sync?SOCK_STREAM:SOCK_DGRAM, 0)) < 0)
{
FatalError("socket() call failed: %s", strerror(errno));
}
+
+ /* Connect to the target */
+ if( connect(data->alertsd, (struct sockaddr *)&alertaddr, sizeof(alertaddr)) < 0)
+ {
+ FatalError("connect() to '%s' failed: %s", data->filename, strerror(errno));
+ }
}
void AlertUnixSockCleanExit(int signal, void *arg)

0 comments on commit 55bad05

Please sign in to comment.