1 /* $KAME: kmpstat.c,v 1.33 2004/08/16 08:20:28 itojun Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
42 #include <System/net/pfkeyv2.h>
48 #if TIME_WITH_SYS_TIME
49 # include <sys/time.h>
53 # include <sys/time.h>
63 #include <sys/ioctl.h>
75 #include "racoonctl.h"
78 #include "isakmp_var.h"
80 #include "isakmp_xauth.h"
81 #include "isakmp_var.h"
82 #include "isakmp_cfg.h"
83 #include "isakmp_unity.h"
89 #include "admin_var.h"
90 #include "ipsec_doi.h"
92 u_int32_t racoonctl_interface
= RACOONCTL_INTERFACE
;
93 u_int32_t racoonctl_interface_major
= RACOONCTL_INTERFACE_MAJOR
;
96 u_int32_t loglevel
= 0;
101 union { // Wcast-align fix - force alignment of sockaddr_un
102 struct sockaddr_storage ss
;
103 struct sockaddr_un name
;
106 memset(&u
, 0, sizeof(struct sockaddr_un
));
107 u
.name
.sun_family
= AF_UNIX
;
108 snprintf(u
.name
.sun_path
, sizeof(u
.name
.sun_path
),
109 "%s", adminsock_path
);
111 so
= socket(AF_UNIX
, SOCK_STREAM
, 0);
115 if (connect(so
, (struct sockaddr
*)&u
.ss
, sizeof(struct sockaddr_un
)) < 0) {
129 if ((len
= send(so
, combuf
->v
, combuf
->l
, 0)) == -1) {
150 /* receive by PEEK */
151 if ((len
= recv(so
, &h
, sizeof(h
), MSG_PEEK
)) == -1)
163 /* allocate buffer */
164 if ((*combufp
= vmalloc(h
.ac_len
)) == NULL
)
167 /* read real message */
170 if ((len
= recv(so
, p
, h
.ac_len
, 0)) < 0) {
188 * Dumb plog functions (used by sockmisc.c)
191 plog_func(int pri
, const char *func
, struct sockaddr_storage
*sa
, const char *fmt
, ...)
201 plogdump(pri
, data
, len
)
210 get_sockaddr(family
, name
, port
)
214 struct addrinfo hint
, *ai
;
217 memset(&hint
, 0, sizeof(hint
));
218 hint
.ai_family
= PF_UNSPEC
;
219 hint
.ai_family
= family
;
220 hint
.ai_socktype
= SOCK_STREAM
;
222 error
= getaddrinfo(name
, port
, &hint
, &ai
);
224 printf("%s: %s/%s\n", gai_strerror(error
), name
, port
);