Deleted Added
full compact
pfkey_dump.c (55505) pfkey_dump.c (62583)
1/* $FreeBSD: head/lib/libipsec/pfkey_dump.c 62583 2000-07-04 16:22:05Z itojun $ */
2/* $KAME: pfkey_dump.c,v 1.19 2000/06/10 06:47:11 sakane Exp $ */
3
1/*
2 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
4/*
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/lib/libipsec/pfkey_dump.c 55505 2000-01-06 12:40:54Z shin $
30 */
31
32#include <sys/types.h>
33#include <sys/param.h>
34#include <sys/socket.h>
35#include <netinet6/ipsec.h>
36#include <net/pfkeyv2.h>
37#include <netkey/key_var.h>
38#include <netkey/key_debug.h>
39
40#include <netinet/in.h>
41#include <netinet6/ipsec.h>
31 */
32
33#include <sys/types.h>
34#include <sys/param.h>
35#include <sys/socket.h>
36#include <netinet6/ipsec.h>
37#include <net/pfkeyv2.h>
38#include <netkey/key_var.h>
39#include <netkey/key_debug.h>
40
41#include <netinet/in.h>
42#include <netinet6/ipsec.h>
42#ifdef INET6
43#include <netinet6/in6.h>
44#endif
45#include <arpa/inet.h>
46
47#include <stdlib.h>
48#include <unistd.h>
49#include <stdio.h>
50#include <string.h>
51#include <time.h>
43#include <arpa/inet.h>
44
45#include <stdlib.h>
46#include <unistd.h>
47#include <stdio.h>
48#include <string.h>
49#include <time.h>
50#include <netdb.h>
52
53#include "ipsec_strerror.h"
51
52#include "ipsec_strerror.h"
53#include "libpfkey.h"
54
54
55#define GETMSGSTR(str, num) \
56{ \
55#define GETMSGSTR(str, num) \
56do { \
57 if (sizeof((str)[0]) == 0 \
58 || num >= sizeof(str)/sizeof((str)[0])) \
59 printf("%d ", (num)); \
60 else if (strlen((str)[(num)]) == 0) \
61 printf("%d ", (num)); \
62 else \
63 printf("%s ", (str)[(num)]); \
57 if (sizeof((str)[0]) == 0 \
58 || num >= sizeof(str)/sizeof((str)[0])) \
59 printf("%d ", (num)); \
60 else if (strlen((str)[(num)]) == 0) \
61 printf("%d ", (num)); \
62 else \
63 printf("%s ", (str)[(num)]); \
64}
64} while (0)
65
65
66#define GETAF(p) \
67 (((struct sockaddr *)(p))->sa_family)
66static char *str_ipaddr __P((struct sockaddr *));
67static char *str_prefport __P((u_int, u_int, u_int));
68static char *str_time __P((time_t));
69static void str_lifetime_byte __P((struct sadb_lifetime *, char *));
68
70
69static char *_str_ipaddr __P((u_int family, caddr_t addr));
70static char *_str_prefport __P((u_int family, u_int pref, u_int port));
71static char *_str_time __P((time_t t));
72static void _str_lifetime_byte __P((struct sadb_lifetime *x, char *str));
73
74/*
75 * Must to be re-written about following strings.
76 */
77static char *_str_satype[] = {
78 "unspec",
79 "unknown",
80 "ah",
81 "esp",

--- 64 unchanged lines hidden (view full) ---

146 * dump SADB_MSG formated. For debugging, you should use kdebug_sadb().
147 */
148void
149pfkey_sadump(m)
150 struct sadb_msg *m;
151{
152 caddr_t mhp[SADB_EXT_MAX + 1];
153 struct sadb_sa *m_sa;
71/*
72 * Must to be re-written about following strings.
73 */
74static char *_str_satype[] = {
75 "unspec",
76 "unknown",
77 "ah",
78 "esp",

--- 64 unchanged lines hidden (view full) ---

143 * dump SADB_MSG formated. For debugging, you should use kdebug_sadb().
144 */
145void
146pfkey_sadump(m)
147 struct sadb_msg *m;
148{
149 caddr_t mhp[SADB_EXT_MAX + 1];
150 struct sadb_sa *m_sa;
151 struct sadb_x_sa2 *m_sa2;
154 struct sadb_lifetime *m_lftc, *m_lfth, *m_lfts;
155 struct sadb_address *m_saddr, *m_daddr, *m_paddr;
156 struct sadb_key *m_auth, *m_enc;
157 struct sadb_ident *m_sid, *m_did;
158 struct sadb_sens *m_sens;
159
160 /* check pfkey message. */
161 if (pfkey_align(m, mhp)) {
162 printf("%s\n", ipsec_strerror());
163 return;
164 }
165 if (pfkey_check(mhp)) {
166 printf("%s\n", ipsec_strerror());
167 return;
168 }
169
170 m_sa = (struct sadb_sa *)mhp[SADB_EXT_SA];
152 struct sadb_lifetime *m_lftc, *m_lfth, *m_lfts;
153 struct sadb_address *m_saddr, *m_daddr, *m_paddr;
154 struct sadb_key *m_auth, *m_enc;
155 struct sadb_ident *m_sid, *m_did;
156 struct sadb_sens *m_sens;
157
158 /* check pfkey message. */
159 if (pfkey_align(m, mhp)) {
160 printf("%s\n", ipsec_strerror());
161 return;
162 }
163 if (pfkey_check(mhp)) {
164 printf("%s\n", ipsec_strerror());
165 return;
166 }
167
168 m_sa = (struct sadb_sa *)mhp[SADB_EXT_SA];
169 m_sa2 = (struct sadb_x_sa2 *)mhp[SADB_X_EXT_SA2];
171 m_lftc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
172 m_lfth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
173 m_lfts = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_SOFT];
174 m_saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC];
175 m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
176 m_paddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_PROXY];
177 m_auth = (struct sadb_key *)mhp[SADB_EXT_KEY_AUTH];
178 m_enc = (struct sadb_key *)mhp[SADB_EXT_KEY_ENCRYPT];
179 m_sid = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_SRC];
170 m_lftc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
171 m_lfth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
172 m_lfts = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_SOFT];
173 m_saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC];
174 m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
175 m_paddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_PROXY];
176 m_auth = (struct sadb_key *)mhp[SADB_EXT_KEY_AUTH];
177 m_enc = (struct sadb_key *)mhp[SADB_EXT_KEY_ENCRYPT];
178 m_sid = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_SRC];
180 m_did = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_SRC];
179 m_did = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_DST];
181 m_sens = (struct sadb_sens *)mhp[SADB_EXT_SENSITIVITY];
182
183 /* source address */
184 if (m_saddr == NULL) {
185 printf("no ADDRESS_SRC extension.\n");
186 return;
187 }
180 m_sens = (struct sadb_sens *)mhp[SADB_EXT_SENSITIVITY];
181
182 /* source address */
183 if (m_saddr == NULL) {
184 printf("no ADDRESS_SRC extension.\n");
185 return;
186 }
188 printf("%s ",
189 _str_ipaddr(GETAF(m_saddr + 1), _INADDRBYSA(m_saddr + 1)));
187 printf("%s ", str_ipaddr((struct sockaddr *)(m_saddr + 1)));
190
191 /* destination address */
192 if (m_daddr == NULL) {
193 printf("no ADDRESS_DST extension.\n");
194 return;
195 }
188
189 /* destination address */
190 if (m_daddr == NULL) {
191 printf("no ADDRESS_DST extension.\n");
192 return;
193 }
196 printf("%s ",
197 _str_ipaddr(GETAF(m_daddr + 1), _INADDRBYSA(m_daddr + 1)));
194 printf("%s ", str_ipaddr((struct sockaddr *)(m_daddr + 1)));
198
199 /* SA type */
200 if (m_sa == NULL) {
201 printf("no SA extension.\n");
202 return;
203 }
195
196 /* SA type */
197 if (m_sa == NULL) {
198 printf("no SA extension.\n");
199 return;
200 }
201 if (m_sa2 == NULL) {
202 printf("no SA2 extension.\n");
203 return;
204 }
204 printf("\n\t");
205
206 GETMSGSTR(_str_satype, m->sadb_msg_satype);
207
208 printf("mode=");
205 printf("\n\t");
206
207 GETMSGSTR(_str_satype, m->sadb_msg_satype);
208
209 printf("mode=");
209 GETMSGSTR(_str_mode, m->sadb_msg_mode);
210 GETMSGSTR(_str_mode, m_sa2->sadb_x_sa2_mode);
210
211
211 printf("spi=%u(0x%08x) replay=%u flags=0x%08x\n",
212 printf("spi=%u(0x%08x) reqid=%u(0x%08x)\n",
212 (u_int32_t)ntohl(m_sa->sadb_sa_spi),
213 (u_int32_t)ntohl(m_sa->sadb_sa_spi),
213 (u_int32_t)ntohl(m_sa->sadb_sa_spi),
214 (u_int32_t)ntohl(m_sa->sadb_sa_spi),
214 m_sa->sadb_sa_replay,
215 m_sa->sadb_sa_flags);
215 (u_int32_t)m_sa2->sadb_x_sa2_reqid,
216 (u_int32_t)m_sa2->sadb_x_sa2_reqid);
216
217 /* encryption key */
218 if (m->sadb_msg_satype == SADB_X_SATYPE_IPCOMP) {
219 printf("\tC: ");
220 GETMSGSTR(_str_alg_comp, m_sa->sadb_sa_encrypt);
221 } else if (m->sadb_msg_satype == SADB_SATYPE_ESP) {
222 if (m_enc != NULL) {
223 printf("\tE: ");

--- 8 unchanged lines hidden (view full) ---

232 if (m_auth != NULL) {
233 printf("\tA: ");
234 GETMSGSTR(_str_alg_auth, m_sa->sadb_sa_auth);
235 ipsec_hexdump((caddr_t)m_auth + sizeof(*m_auth),
236 m_auth->sadb_key_bits / 8);
237 printf("\n");
238 }
239
217
218 /* encryption key */
219 if (m->sadb_msg_satype == SADB_X_SATYPE_IPCOMP) {
220 printf("\tC: ");
221 GETMSGSTR(_str_alg_comp, m_sa->sadb_sa_encrypt);
222 } else if (m->sadb_msg_satype == SADB_SATYPE_ESP) {
223 if (m_enc != NULL) {
224 printf("\tE: ");

--- 8 unchanged lines hidden (view full) ---

233 if (m_auth != NULL) {
234 printf("\tA: ");
235 GETMSGSTR(_str_alg_auth, m_sa->sadb_sa_auth);
236 ipsec_hexdump((caddr_t)m_auth + sizeof(*m_auth),
237 m_auth->sadb_key_bits / 8);
238 printf("\n");
239 }
240
241 /* replay windoe size & flags */
242 printf("\treplay=%u flags=0x%08x ",
243 m_sa->sadb_sa_replay,
244 m_sa->sadb_sa_flags);
245
240 /* state */
246 /* state */
241 printf("\tstate=");
247 printf("state=");
242 GETMSGSTR(_str_state, m_sa->sadb_sa_state);
243
244 printf("seq=%lu pid=%lu\n",
245 (u_long)m->sadb_msg_seq,
246 (u_long)m->sadb_msg_pid);
247
248 /* lifetime */
249 if (m_lftc != NULL) {
250 time_t tmp_time = time(0);
251
252 printf("\tcreated: %s",
248 GETMSGSTR(_str_state, m_sa->sadb_sa_state);
249
250 printf("seq=%lu pid=%lu\n",
251 (u_long)m->sadb_msg_seq,
252 (u_long)m->sadb_msg_pid);
253
254 /* lifetime */
255 if (m_lftc != NULL) {
256 time_t tmp_time = time(0);
257
258 printf("\tcreated: %s",
253 _str_time(m_lftc->sadb_lifetime_addtime));
254 printf("\tcurrent: %s\n", _str_time(tmp_time));
259 str_time(m_lftc->sadb_lifetime_addtime));
260 printf("\tcurrent: %s\n", str_time(tmp_time));
255 printf("\tdiff: %lu(s)",
256 (u_long)(m_lftc->sadb_lifetime_addtime == 0 ?
257 0 : (tmp_time - m_lftc->sadb_lifetime_addtime)));
258
259 printf("\thard: %lu(s)",
260 (u_long)(m_lfth == NULL ?
261 0 : m_lfth->sadb_lifetime_addtime));
262 printf("\tsoft: %lu(s)\n",
263 (u_long)(m_lfts == NULL ?
264 0 : m_lfts->sadb_lifetime_addtime));
265
266 printf("\tlast: %s",
261 printf("\tdiff: %lu(s)",
262 (u_long)(m_lftc->sadb_lifetime_addtime == 0 ?
263 0 : (tmp_time - m_lftc->sadb_lifetime_addtime)));
264
265 printf("\thard: %lu(s)",
266 (u_long)(m_lfth == NULL ?
267 0 : m_lfth->sadb_lifetime_addtime));
268 printf("\tsoft: %lu(s)\n",
269 (u_long)(m_lfts == NULL ?
270 0 : m_lfts->sadb_lifetime_addtime));
271
272 printf("\tlast: %s",
267 _str_time(m_lftc->sadb_lifetime_usetime));
273 str_time(m_lftc->sadb_lifetime_usetime));
268 printf("\thard: %lu(s)",
269 (u_long)(m_lfth == NULL ?
270 0 : m_lfth->sadb_lifetime_usetime));
271 printf("\tsoft: %lu(s)\n",
272 (u_long)(m_lfts == NULL ?
273 0 : m_lfts->sadb_lifetime_usetime));
274
274 printf("\thard: %lu(s)",
275 (u_long)(m_lfth == NULL ?
276 0 : m_lfth->sadb_lifetime_usetime));
277 printf("\tsoft: %lu(s)\n",
278 (u_long)(m_lfts == NULL ?
279 0 : m_lfts->sadb_lifetime_usetime));
280
275 _str_lifetime_byte(m_lftc, "current");
276 _str_lifetime_byte(m_lfth, "hard");
277 _str_lifetime_byte(m_lfts, "soft");
281 str_lifetime_byte(m_lftc, "current");
282 str_lifetime_byte(m_lfth, "hard");
283 str_lifetime_byte(m_lfts, "soft");
278 printf("\n");
279
280 printf("\tallocated: %lu",
281 (unsigned long)m_lftc->sadb_lifetime_allocations);
282 printf("\thard: %lu",
283 (u_long)(m_lfth == NULL ?
284 0 : m_lfth->sadb_lifetime_allocations));
285 printf("\tsoft: %lu\n",
286 (u_long)(m_lfts == NULL ?
287 0 : m_lfts->sadb_lifetime_allocations));
288 }
289
290 /* XXX DEBUG */
284 printf("\n");
285
286 printf("\tallocated: %lu",
287 (unsigned long)m_lftc->sadb_lifetime_allocations);
288 printf("\thard: %lu",
289 (u_long)(m_lfth == NULL ?
290 0 : m_lfth->sadb_lifetime_allocations));
291 printf("\tsoft: %lu\n",
292 (u_long)(m_lfts == NULL ?
293 0 : m_lfts->sadb_lifetime_allocations));
294 }
295
296 /* XXX DEBUG */
291 printf("\trefcnt=%d\n", m->sadb_msg_reserved);
297 printf("\trefcnt=%u\n", m->sadb_msg_reserved);
292
293 return;
294}
295
296void
297pfkey_spdump(m)
298 struct sadb_msg *m;
299{
298
299 return;
300}
301
302void
303pfkey_spdump(m)
304 struct sadb_msg *m;
305{
306 char pbuf[NI_MAXSERV];
300 caddr_t mhp[SADB_EXT_MAX + 1];
301 struct sadb_address *m_saddr, *m_daddr;
302 struct sadb_x_policy *m_xpl;
307 caddr_t mhp[SADB_EXT_MAX + 1];
308 struct sadb_address *m_saddr, *m_daddr;
309 struct sadb_x_policy *m_xpl;
310 struct sockaddr *sa;
311 u_int16_t port;
303
304 /* check pfkey message. */
305 if (pfkey_align(m, mhp)) {
306 printf("%s\n", ipsec_strerror());
307 return;
308 }
309 if (pfkey_check(mhp)) {
310 printf("%s\n", ipsec_strerror());

--- 4 unchanged lines hidden (view full) ---

315 m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
316 m_xpl = (struct sadb_x_policy *)mhp[SADB_X_EXT_POLICY];
317
318 /* source address */
319 if (m_saddr == NULL) {
320 printf("no ADDRESS_SRC extension.\n");
321 return;
322 }
312
313 /* check pfkey message. */
314 if (pfkey_align(m, mhp)) {
315 printf("%s\n", ipsec_strerror());
316 return;
317 }
318 if (pfkey_check(mhp)) {
319 printf("%s\n", ipsec_strerror());

--- 4 unchanged lines hidden (view full) ---

324 m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
325 m_xpl = (struct sadb_x_policy *)mhp[SADB_X_EXT_POLICY];
326
327 /* source address */
328 if (m_saddr == NULL) {
329 printf("no ADDRESS_SRC extension.\n");
330 return;
331 }
323 printf("%s%s ",
324 _str_ipaddr(GETAF(m_saddr + 1), _INADDRBYSA(m_saddr + 1)),
325 _str_prefport(GETAF(m_saddr + 1),
326 m_saddr->sadb_address_prefixlen,
327 _INPORTBYSA(m_saddr + 1)));
332 sa = (struct sockaddr *)(m_saddr + 1);
333 switch (sa->sa_family) {
334 case AF_INET:
335 case AF_INET6:
336 if (getnameinfo(sa, sa->sa_len, NULL, 0, pbuf, sizeof(pbuf),
337 NI_NUMERICSERV) != 0)
338 port = 0; /*XXX*/
339 else
340 port = atoi(pbuf);
341 printf("%s%s ", str_ipaddr(sa),
342 str_prefport(sa->sa_family,
343 m_saddr->sadb_address_prefixlen, port));
344 break;
345 default:
346 printf("unknown-af ");
347 break;
348 }
328
329 /* destination address */
330 if (m_daddr == NULL) {
331 printf("no ADDRESS_DST extension.\n");
332 return;
333 }
349
350 /* destination address */
351 if (m_daddr == NULL) {
352 printf("no ADDRESS_DST extension.\n");
353 return;
354 }
334 printf("%s%s ",
335 _str_ipaddr(GETAF(m_daddr + 1), _INADDRBYSA(m_daddr + 1)),
336 _str_prefport(GETAF(m_daddr + 1),
337 m_daddr->sadb_address_prefixlen,
338 _INPORTBYSA(m_daddr + 1)));
355 sa = (struct sockaddr *)(m_daddr + 1);
356 switch (sa->sa_family) {
357 case AF_INET:
358 case AF_INET6:
359 if (getnameinfo(sa, sa->sa_len, NULL, 0, pbuf, sizeof(pbuf),
360 NI_NUMERICSERV) != 0)
361 port = 0; /*XXX*/
362 else
363 port = atoi(pbuf);
364 printf("%s%s ", str_ipaddr(sa),
365 str_prefport(sa->sa_family,
366 m_daddr->sadb_address_prefixlen, port));
367 break;
368 default:
369 printf("unknown-af ");
370 break;
371 }
339
340 /* upper layer protocol */
372
373 /* upper layer protocol */
341 if (m_saddr->sadb_address_proto != m_saddr->sadb_address_proto) {
374 if (m_saddr->sadb_address_proto != m_daddr->sadb_address_proto) {
342 printf("upper layer protocol mismatched.\n");
343 return;
344 }
345 if (m_saddr->sadb_address_proto == IPSEC_ULPROTO_ANY)
346 printf("any");
347 else
348 GETMSGSTR(_str_upper, m_saddr->sadb_address_proto);
349

--- 7 unchanged lines hidden (view full) ---

357 }
358 d_xpl = ipsec_dump_policy((char *)m_xpl, "\n\t");
359
360 /* dump SPD */
361 printf("\n\t%s\n", d_xpl);
362 free(d_xpl);
363 }
364
375 printf("upper layer protocol mismatched.\n");
376 return;
377 }
378 if (m_saddr->sadb_address_proto == IPSEC_ULPROTO_ANY)
379 printf("any");
380 else
381 GETMSGSTR(_str_upper, m_saddr->sadb_address_proto);
382

--- 7 unchanged lines hidden (view full) ---

390 }
391 d_xpl = ipsec_dump_policy((char *)m_xpl, "\n\t");
392
393 /* dump SPD */
394 printf("\n\t%s\n", d_xpl);
395 free(d_xpl);
396 }
397
365 printf("\tseq=%ld pid=%ld\n",
398 printf("\tspid=%ld seq=%ld pid=%ld\n",
399 (u_long)m_xpl->sadb_x_policy_id,
366 (u_long)m->sadb_msg_seq,
367 (u_long)m->sadb_msg_pid);
368
369 /* XXX TEST */
400 (u_long)m->sadb_msg_seq,
401 (u_long)m->sadb_msg_pid);
402
403 /* XXX TEST */
370 printf("\trefcnt=%d\n", m->sadb_msg_reserved);
404 printf("\trefcnt=%u\n", m->sadb_msg_reserved);
371
372 return;
373}
374
375/*
376 * set "ipaddress" to buffer.
377 */
378static char *
405
406 return;
407}
408
409/*
410 * set "ipaddress" to buffer.
411 */
412static char *
379_str_ipaddr(family, addr)
380 u_int family;
381 caddr_t addr;
413str_ipaddr(sa)
414 struct sockaddr *sa;
382{
415{
383 static char buf[128];
384 char addrbuf[128];
416 static char buf[NI_MAXHOST];
417#ifdef NI_WITHSCOPEID
418 const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
419#else
420 const int niflag = NI_NUMERICHOST;
421#endif
385
422
386 if (addr == NULL)
423 if (sa == NULL)
387 return "";
388
424 return "";
425
389 inet_ntop(family, addr, addrbuf, sizeof(addrbuf));
390
391 snprintf(buf, sizeof(buf), "%s", addrbuf);
392
393 return buf;
426 if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), NULL, 0, niflag) == 0)
427 return buf;
428 return NULL;
394}
395
396/*
397 * set "/prefix[port number]" to buffer.
398 */
399static char *
429}
430
431/*
432 * set "/prefix[port number]" to buffer.
433 */
434static char *
400_str_prefport(family, pref, port)
435str_prefport(family, pref, port)
401 u_int family, pref, port;
402{
403 static char buf[128];
404 char prefbuf[10];
405 char portbuf[10];
436 u_int family, pref, port;
437{
438 static char buf[128];
439 char prefbuf[10];
440 char portbuf[10];
441 int plen;
406
442
407 if (pref == (_INALENBYAF(family) << 3))
443 switch (family) {
444 case AF_INET:
445 plen = sizeof(struct in_addr) << 3;
446 break;
447 case AF_INET6:
448 plen = sizeof(struct in6_addr) << 3;
449 break;
450 default:
451 return "?";
452 }
453
454 if (pref == plen)
408 prefbuf[0] = '\0';
409 else
410 snprintf(prefbuf, sizeof(prefbuf), "/%u", pref);
411
412 if (port == IPSEC_PORT_ANY)
413 snprintf(portbuf, sizeof(portbuf), "[%s]", "any");
414 else
455 prefbuf[0] = '\0';
456 else
457 snprintf(prefbuf, sizeof(prefbuf), "/%u", pref);
458
459 if (port == IPSEC_PORT_ANY)
460 snprintf(portbuf, sizeof(portbuf), "[%s]", "any");
461 else
415 snprintf(portbuf, sizeof(portbuf), "[%u]", ntohs(port));
462 snprintf(portbuf, sizeof(portbuf), "[%u]", port);
416
417 snprintf(buf, sizeof(buf), "%s%s", prefbuf, portbuf);
418
419 return buf;
420}
421
422/*
423 * set "Mon Day Time Year" to buffer
424 */
425static char *
463
464 snprintf(buf, sizeof(buf), "%s%s", prefbuf, portbuf);
465
466 return buf;
467}
468
469/*
470 * set "Mon Day Time Year" to buffer
471 */
472static char *
426_str_time(t)
473str_time(t)
427 time_t t;
428{
429 static char buf[128];
430
431 if (t == 0) {
432 int i = 0;
433 for (;i < 20;) buf[i++] = ' ';
434 } else {
435 char *t0;
436 t0 = ctime(&t);
437 memcpy(buf, t0 + 4, 20);
438 }
439
440 buf[20] = '\0';
441
442 return(buf);
443}
444
445static void
474 time_t t;
475{
476 static char buf[128];
477
478 if (t == 0) {
479 int i = 0;
480 for (;i < 20;) buf[i++] = ' ';
481 } else {
482 char *t0;
483 t0 = ctime(&t);
484 memcpy(buf, t0 + 4, 20);
485 }
486
487 buf[20] = '\0';
488
489 return(buf);
490}
491
492static void
446_str_lifetime_byte(x, str)
493str_lifetime_byte(x, str)
447 struct sadb_lifetime *x;
448 char *str;
449{
450 double y;
451 char *unit;
452 int w;
453
454 if (x == NULL) {
455 printf("\t%s: 0(bytes)", str);
456 return;
457 }
458
494 struct sadb_lifetime *x;
495 char *str;
496{
497 double y;
498 char *unit;
499 int w;
500
501 if (x == NULL) {
502 printf("\t%s: 0(bytes)", str);
503 return;
504 }
505
506#if 0
507 if ((x->sadb_lifetime_bytes) / 1024 / 1024) {
508 y = (x->sadb_lifetime_bytes) * 1.0 / 1024 / 1024;
509 unit = "M";
510 w = 1;
511 } else if ((x->sadb_lifetime_bytes) / 1024) {
512 y = (x->sadb_lifetime_bytes) * 1.0 / 1024;
513 unit = "K";
514 w = 1;
515 } else {
516 y = (x->sadb_lifetime_bytes) * 1.0;
517 unit = "";
518 w = 0;
519 }
520#else
459 y = (x->sadb_lifetime_bytes) * 1.0;
460 unit = "";
461 w = 0;
521 y = (x->sadb_lifetime_bytes) * 1.0;
522 unit = "";
523 w = 0;
524#endif
462 printf("\t%s: %.*f(%sbytes)", str, w, y, unit);
463}
525 printf("\t%s: %.*f(%sbytes)", str, w, y, unit);
526}