]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libcharon/plugins/error_notify/error_notify.c
2 * Copyright (C) 2012 Martin Willi
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include "error_notify_msg.h"
24 #include <sys/socket.h>
27 #include <arpa/inet.h>
30 * Connect to the daemon, return FD
32 static int make_connection()
35 struct sockaddr_un un
;
36 struct sockaddr_in in
;
41 if (getenv("TCP_PORT"))
43 addr
.in
.sin_family
= AF_INET
;
44 addr
.in
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
45 addr
.in
.sin_port
= htons(atoi(getenv("TCP_PORT")));
46 len
= sizeof(addr
.in
);
50 addr
.un
.sun_family
= AF_UNIX
;
51 strcpy(addr
.un
.sun_path
, ERROR_NOTIFY_SOCKET
);
53 len
= offsetof(struct sockaddr_un
, sun_path
) + strlen(addr
.un
.sun_path
);
55 fd
= socket(addr
.sa
.sa_family
, SOCK_STREAM
, 0);
58 fprintf(stderr
, "opening socket failed: %s\n", strerror(errno
));
61 if (connect(fd
, &addr
.sa
, len
) < 0)
63 fprintf(stderr
, "connecting failed: %s\n", strerror(errno
));
71 * Example of a simple notification listener
73 int main(int argc
, char *argv
[])
75 error_notify_msg_t msg
;
79 s
= make_connection();
89 while (total
< sizeof(msg
))
91 len
= read(s
, pos
, sizeof(msg
) - total
);
94 fprintf(stderr
, "read failed: %s\n", strerror(errno
));
101 printf("%d %s %s %s %s\n",
102 ntohl(msg
.type
), msg
.name
, msg
.id
, msg
.ip
, msg
.str
);