OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [ipsec/] [libipsec/] [current/] [src/] [pfkey_dump.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      src/pfkey_dump.c
4
//
5
//==========================================================================
6
// ####BSDCOPYRIGHTBEGIN####                                    
7
// -------------------------------------------                  
8
// This file is part of eCos, the Embedded Configurable Operating System.
9
//
10
// Portions of this software may have been derived from FreeBSD, OpenBSD,
11
// or other sources, and if so are covered by the appropriate copyright
12
// and license included herein.                                 
13
//
14
// Portions created by the Free Software Foundation are         
15
// Copyright (C) 2002 Free Software Foundation, Inc.            
16
// -------------------------------------------                  
17
// ####BSDCOPYRIGHTEND####                                      
18
//==========================================================================
19
 
20
/*      $KAME: pfkey_dump.c,v 1.45 2003/09/08 10:14:56 itojun Exp $     */
21
 
22
/*
23
 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
24
 * All rights reserved.
25
 *
26
 * Redistribution and use in source and binary forms, with or without
27
 * modification, are permitted provided that the following conditions
28
 * are met:
29
 * 1. Redistributions of source code must retain the above copyright
30
 *    notice, this list of conditions and the following disclaimer.
31
 * 2. Redistributions in binary form must reproduce the above copyright
32
 *    notice, this list of conditions and the following disclaimer in the
33
 *    documentation and/or other materials provided with the distribution.
34
 * 3. Neither the name of the project nor the names of its contributors
35
 *    may be used to endorse or promote products derived from this software
36
 *    without specific prior written permission.
37
 *
38
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
39
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
42
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
 * SUCH DAMAGE.
49
 */
50
 
51
#include <sys/types.h>
52
#include <sys/param.h>
53
#include <sys/socket.h>
54
#include <netinet6/ipsec.h>
55
#include <net/pfkeyv2.h>
56
#include <netkey/key_var.h>
57
#include <netkey/key_debug.h>
58
 
59
#include <netinet/in.h>
60
#include <netinet6/ipsec.h>
61
#include <arpa/inet.h>
62
 
63
#include <stdlib.h>
64
#include <unistd.h>
65
#include <stdio.h>
66
#include <string.h>
67
#include <time.h>
68
#include <netdb.h>
69
 
70
#include "ipsec_strerror.h"
71
#include "libpfkey.h"
72
 
73
/* cope with old kame headers - ugly */
74
#ifndef SADB_X_AALG_MD5
75
#define SADB_X_AALG_MD5         SADB_AALG_MD5   
76
#endif
77
#ifndef SADB_X_AALG_SHA
78
#define SADB_X_AALG_SHA         SADB_AALG_SHA
79
#endif
80
#ifndef SADB_X_AALG_NULL
81
#define SADB_X_AALG_NULL        SADB_AALG_NULL
82
#endif
83
 
84
#ifndef SADB_X_EALG_BLOWFISHCBC
85
#define SADB_X_EALG_BLOWFISHCBC SADB_EALG_BLOWFISHCBC
86
#endif
87
#ifndef SADB_X_EALG_CAST128CBC
88
#define SADB_X_EALG_CAST128CBC  SADB_EALG_CAST128CBC
89
#endif
90
#ifndef SADB_X_EALG_RC5CBC
91
#ifdef SADB_EALG_RC5CBC
92
#define SADB_X_EALG_RC5CBC      SADB_EALG_RC5CBC
93
#endif
94
#endif
95
 
96
#define GETMSGSTR(str, num) \
97
do { \
98
        if (sizeof((str)[0]) == 0 \
99
         || num >= sizeof(str)/sizeof((str)[0])) \
100
                printf("%u ", (num)); \
101
        else if (strlen((str)[(num)]) == 0) \
102
                printf("%u ", (num)); \
103
        else \
104
                printf("%s ", (str)[(num)]); \
105
} while (0)
106
 
107
#define GETMSGV2S(v2s, num) \
108
do { \
109
        struct val2str *p;  \
110
        for (p = (v2s); p && p->str; p++) { \
111
                if (p->val == (num)) \
112
                        break; \
113
        } \
114
        if (p && p->str) \
115
                printf("%s ", p->str); \
116
        else \
117
                printf("%u ", (num)); \
118
} while (0)
119
 
120
static char *str_ipaddr __P((struct sockaddr *));
121
static char *str_prefport __P((u_int, u_int, u_int, u_int));
122
static void str_upperspec __P((u_int, u_int, u_int));
123
static char *str_time __P((time_t));
124
static void str_lifetime_byte __P((struct sadb_lifetime *, char *));
125
 
126
struct val2str {
127
        int val;
128
        const char *str;
129
};
130
 
131
/*
132
 * Must to be re-written about following strings.
133
 */
134
static char *str_satype[] = {
135
        "unspec",
136
        "unknown",
137
        "ah",
138
        "esp",
139
        "unknown",
140
        "rsvp",
141
        "ospfv2",
142
        "ripv2",
143
        "mip",
144
        "ipcomp",
145
};
146
 
147
static char *str_mode[] = {
148
        "any",
149
        "transport",
150
        "tunnel",
151
};
152
 
153
static char *str_state[] = {
154
        "larval",
155
        "mature",
156
        "dying",
157
        "dead",
158
};
159
 
160
static struct val2str str_alg_auth[] = {
161
        { SADB_AALG_NONE, "none", },
162
        { SADB_AALG_MD5HMAC, "hmac-md5", },
163
        { SADB_AALG_SHA1HMAC, "hmac-sha1", },
164
        { SADB_X_AALG_MD5, "md5", },
165
        { SADB_X_AALG_SHA, "sha", },
166
        { SADB_X_AALG_NULL, "null", },
167
#ifdef SADB_X_AALG_SHA2_256
168
        { SADB_X_AALG_SHA2_256, "hmac-sha2-256", },
169
#endif
170
#ifdef SADB_X_AALG_SHA2_384
171
        { SADB_X_AALG_SHA2_384, "hmac-sha2-384", },
172
#endif
173
#ifdef SADB_X_AALG_SHA2_512
174
        { SADB_X_AALG_SHA2_512, "hmac-sha2-512", },
175
#endif
176
#ifdef SADB_X_AALG_RIPEMD160HMAC
177
        { SADB_X_AALG_RIPEMD160HMAC, "hmac-ripemd160", },
178
#endif
179
#ifdef SADB_X_AALG_AES_XCBC_MAC
180
        { SADB_X_AALG_AES_XCBC_MAC, "aes-xcbc-mac", },
181
#endif
182
        { -1, NULL, },
183
};
184
 
185
static struct val2str str_alg_enc[] = {
186
        { SADB_EALG_NONE, "none", },
187
        { SADB_EALG_DESCBC, "des-cbc", },
188
        { SADB_EALG_3DESCBC, "3des-cbc", },
189
        { SADB_EALG_NULL, "null", },
190
#ifdef SADB_X_EALG_RC5CBC
191
        { SADB_X_EALG_RC5CBC, "rc5-cbc", },
192
#endif
193
        { SADB_X_EALG_CAST128CBC, "cast128-cbc", },
194
        { SADB_X_EALG_BLOWFISHCBC, "blowfish-cbc", },
195
#ifdef SADB_X_EALG_RIJNDAELCBC
196
        { SADB_X_EALG_RIJNDAELCBC, "rijndael-cbc", },
197
#endif
198
#ifdef SADB_X_EALG_TWOFISHCBC
199
        { SADB_X_EALG_TWOFISHCBC, "twofish-cbc", },
200
#endif
201
#ifdef SADB_X_EALG_AESCTR
202
        { SADB_X_EALG_AESCTR, "aes-ctr", },
203
#endif
204
        { -1, NULL, },
205
};
206
 
207
static struct val2str str_alg_comp[] = {
208
        { SADB_X_CALG_NONE, "none", },
209
        { SADB_X_CALG_OUI, "oui", },
210
        { SADB_X_CALG_DEFLATE, "deflate", },
211
        { SADB_X_CALG_LZS, "lzs", },
212
        { -1, NULL, },
213
};
214
 
215
/*
216
 * dump SADB_MSG formated.  For debugging, you should use kdebug_sadb().
217
 */
218
void
219
pfkey_sadump(m)
220
        struct sadb_msg *m;
221
{
222
        caddr_t mhp[SADB_EXT_MAX + 1];
223
        struct sadb_sa *m_sa;
224
        struct sadb_x_sa2 *m_sa2;
225
        struct sadb_lifetime *m_lftc, *m_lfth, *m_lfts;
226
        struct sadb_address *m_saddr, *m_daddr, *m_paddr;
227
        struct sadb_key *m_auth, *m_enc;
228
        struct sadb_ident *m_sid, *m_did;
229
        struct sadb_sens *m_sens;
230
 
231
        /* check pfkey message. */
232
        if (pfkey_align(m, mhp)) {
233
                printf("%s\n", ipsec_strerror());
234
                return;
235
        }
236
        if (pfkey_check(mhp)) {
237
                printf("%s\n", ipsec_strerror());
238
                return;
239
        }
240
 
241
        m_sa = (struct sadb_sa *)mhp[SADB_EXT_SA];
242
        m_sa2 = (struct sadb_x_sa2 *)mhp[SADB_X_EXT_SA2];
243
        m_lftc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
244
        m_lfth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
245
        m_lfts = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_SOFT];
246
        m_saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC];
247
        m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
248
        m_paddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_PROXY];
249
        m_auth = (struct sadb_key *)mhp[SADB_EXT_KEY_AUTH];
250
        m_enc = (struct sadb_key *)mhp[SADB_EXT_KEY_ENCRYPT];
251
        m_sid = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_SRC];
252
        m_did = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_DST];
253
        m_sens = (struct sadb_sens *)mhp[SADB_EXT_SENSITIVITY];
254
 
255
        /* source address */
256
        if (m_saddr == NULL) {
257
                printf("no ADDRESS_SRC extension.\n");
258
                return;
259
        }
260
        printf("%s ", str_ipaddr((struct sockaddr *)(m_saddr + 1)));
261
 
262
        /* destination address */
263
        if (m_daddr == NULL) {
264
                printf("no ADDRESS_DST extension.\n");
265
                return;
266
        }
267
        printf("%s ", str_ipaddr((struct sockaddr *)(m_daddr + 1)));
268
 
269
        /* SA type */
270
        if (m_sa == NULL) {
271
                printf("no SA extension.\n");
272
                return;
273
        }
274
        if (m_sa2 == NULL) {
275
                printf("no SA2 extension.\n");
276
                return;
277
        }
278
        printf("\n\t");
279
 
280
        GETMSGSTR(str_satype, m->sadb_msg_satype);
281
 
282
        printf("mode=");
283
        GETMSGSTR(str_mode, m_sa2->sadb_x_sa2_mode);
284
 
285
        printf("spi=%u(0x%08x) reqid=%u(0x%08x)\n",
286
                (u_int32_t)ntohl(m_sa->sadb_sa_spi),
287
                (u_int32_t)ntohl(m_sa->sadb_sa_spi),
288
                (u_int32_t)m_sa2->sadb_x_sa2_reqid,
289
                (u_int32_t)m_sa2->sadb_x_sa2_reqid);
290
 
291
        /* encryption key */
292
        if (m->sadb_msg_satype == SADB_X_SATYPE_IPCOMP) {
293
                printf("\tC: ");
294
                GETMSGV2S(str_alg_comp, m_sa->sadb_sa_encrypt);
295
        } else if (m->sadb_msg_satype == SADB_SATYPE_ESP) {
296
                if (m_enc != NULL) {
297
                        printf("\tE: ");
298
                        GETMSGV2S(str_alg_enc, m_sa->sadb_sa_encrypt);
299
                        ipsec_hexdump((caddr_t)m_enc + sizeof(*m_enc),
300
                                      m_enc->sadb_key_bits / 8);
301
                        printf("\n");
302
                }
303
        }
304
 
305
        /* authentication key */
306
        if (m_auth != NULL) {
307
                printf("\tA: ");
308
                GETMSGV2S(str_alg_auth, m_sa->sadb_sa_auth);
309
                ipsec_hexdump((caddr_t)m_auth + sizeof(*m_auth),
310
                              m_auth->sadb_key_bits / 8);
311
                printf("\n");
312
        }
313
 
314
        /* replay windoe size & flags */
315
        printf("\tseq=0x%08x replay=%u flags=0x%08x ",
316
                m_sa2->sadb_x_sa2_sequence,
317
                m_sa->sadb_sa_replay,
318
                m_sa->sadb_sa_flags);
319
 
320
        /* state */
321
        printf("state=");
322
        GETMSGSTR(str_state, m_sa->sadb_sa_state);
323
        printf("\n");
324
 
325
        /* lifetime */
326
        if (m_lftc != NULL) {
327
                time_t tmp_time = time(0);
328
 
329
                printf("\tcreated: %s",
330
                        str_time(m_lftc->sadb_lifetime_addtime));
331
                printf("\tcurrent: %s\n", str_time(tmp_time));
332
                printf("\tdiff: %lu(s)",
333
                        (u_long)(m_lftc->sadb_lifetime_addtime == 0 ?
334
 
335
 
336
                printf("\thard: %lu(s)",
337
                        (u_long)(m_lfth == NULL ?
338
 
339
                printf("\tsoft: %lu(s)\n",
340
                        (u_long)(m_lfts == NULL ?
341
 
342
 
343
                printf("\tlast: %s",
344
                        str_time(m_lftc->sadb_lifetime_usetime));
345
                printf("\thard: %lu(s)",
346
                        (u_long)(m_lfth == NULL ?
347
 
348
                printf("\tsoft: %lu(s)\n",
349
                        (u_long)(m_lfts == NULL ?
350
 
351
 
352
                str_lifetime_byte(m_lftc, "current");
353
                str_lifetime_byte(m_lfth, "hard");
354
                str_lifetime_byte(m_lfts, "soft");
355
                printf("\n");
356
 
357
                printf("\tallocated: %lu",
358
                        (unsigned long)m_lftc->sadb_lifetime_allocations);
359
                printf("\thard: %lu",
360
                        (u_long)(m_lfth == NULL ?
361
 
362
                printf("\tsoft: %lu\n",
363
                        (u_long)(m_lfts == NULL ?
364
 
365
        }
366
 
367
        printf("\tsadb_seq=%lu pid=%lu ",
368
                (u_long)m->sadb_msg_seq,
369
                (u_long)m->sadb_msg_pid);
370
 
371
        /* XXX DEBUG */
372
        printf("refcnt=%u\n", m->sadb_msg_reserved);
373
 
374
        return;
375
}
376
 
377
void
378
pfkey_spdump(m)
379
        struct sadb_msg *m;
380
{
381
        char pbuf[NI_MAXSERV];
382
        caddr_t mhp[SADB_EXT_MAX + 1];
383
        struct sadb_address *m_saddr, *m_daddr;
384
#ifdef SADB_X_EXT_TAG
385
        struct sadb_x_tag *m_tag;
386
#endif
387
        struct sadb_x_policy *m_xpl;
388
        struct sadb_lifetime *m_lftc = NULL, *m_lfth = NULL;
389
        struct sockaddr *sa;
390
        u_int16_t sport = 0, dport = 0;
391
 
392
        /* check pfkey message. */
393
        if (pfkey_align(m, mhp)) {
394
                printf("%s\n", ipsec_strerror());
395
                return;
396
        }
397
        if (pfkey_check(mhp)) {
398
                printf("%s\n", ipsec_strerror());
399
                return;
400
        }
401
 
402
        m_saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC];
403
        m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
404
#ifdef SADB_X_EXT_TAG
405
        m_tag = (struct sadb_x_tag *)mhp[SADB_X_EXT_TAG];
406
#endif
407
        m_xpl = (struct sadb_x_policy *)mhp[SADB_X_EXT_POLICY];
408
        m_lftc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
409
        m_lfth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
410
 
411
        if (m_saddr && m_daddr) {
412
                /* source address */
413
                sa = (struct sockaddr *)(m_saddr + 1);
414
                switch (sa->sa_family) {
415
                case AF_INET:
416
                case AF_INET6:
417
                        if (getnameinfo(sa, sa->sa_len, NULL, 0,
418
                            pbuf, sizeof(pbuf), NI_NUMERICSERV) != 0)
419
                                sport = 0;       /*XXX*/
420
                        else
421
                                sport = atoi(pbuf);
422
                        printf("%s%s ", str_ipaddr(sa),
423
                                str_prefport(sa->sa_family,
424
                                    m_saddr->sadb_address_prefixlen, sport,
425
                                    m_saddr->sadb_address_proto));
426
                        break;
427
                default:
428
                        printf("unknown-af ");
429
                        break;
430
                }
431
 
432
                /* destination address */
433
                sa = (struct sockaddr *)(m_daddr + 1);
434
                switch (sa->sa_family) {
435
                case AF_INET:
436
                case AF_INET6:
437
                        if (getnameinfo(sa, sa->sa_len, NULL, 0,
438
                            pbuf, sizeof(pbuf), NI_NUMERICSERV) != 0)
439
                                dport = 0;       /*XXX*/
440
                        else
441
                                dport = atoi(pbuf);
442
                        printf("%s%s ", str_ipaddr(sa),
443
                                str_prefport(sa->sa_family,
444
                                    m_daddr->sadb_address_prefixlen, dport,
445
                                    m_saddr->sadb_address_proto));
446
                        break;
447
                default:
448
                        printf("unknown-af ");
449
                        break;
450
                }
451
 
452
                /* upper layer protocol */
453
                if (m_saddr->sadb_address_proto !=
454
                    m_daddr->sadb_address_proto) {
455
                        printf("upper layer protocol mismatched.\n");
456
                        return;
457
                }
458
                str_upperspec(m_saddr->sadb_address_proto, sport, dport);
459
        }
460
#ifdef SADB_X_EXT_TAG
461
        else if (m_tag)
462
                printf("tagged \"%s\" ", m_tag->sadb_x_tag_name);
463
#endif
464
        else
465
                printf("(no selector, probably per-socket policy) ");
466
 
467
        /* policy */
468
    {
469
        char *d_xpl;
470
 
471
        if (m_xpl == NULL) {
472
                printf("no X_POLICY extension.\n");
473
                return;
474
        }
475
        d_xpl = ipsec_dump_policy((char *)m_xpl, "\n\t");
476
 
477
        /* dump SPD */
478
        printf("\n\t%s\n", d_xpl);
479
        free(d_xpl);
480
    }
481
 
482
        /* lifetime */
483
        if (m_lftc) {
484
                printf("\tcreated: %s  ",
485
                        str_time(m_lftc->sadb_lifetime_addtime));
486
                printf("lastused: %s\n",
487
                        str_time(m_lftc->sadb_lifetime_usetime));
488
        }
489
        if (m_lfth) {
490
                printf("\tlifetime: %lu(s) ",
491
                        (u_long)m_lfth->sadb_lifetime_addtime);
492
                printf("validtime: %lu(s)\n",
493
                        (u_long)m_lfth->sadb_lifetime_usetime);
494
        }
495
 
496
 
497
        printf("\tspid=%ld seq=%ld pid=%ld\n",
498
                (u_long)m_xpl->sadb_x_policy_id,
499
                (u_long)m->sadb_msg_seq,
500
                (u_long)m->sadb_msg_pid);
501
 
502
        /* XXX TEST */
503
        printf("\trefcnt=%u\n", m->sadb_msg_reserved);
504
 
505
        return;
506
}
507
 
508
/*
509
 * set "ipaddress" to buffer.
510
 */
511
static char *
512
str_ipaddr(sa)
513
        struct sockaddr *sa;
514
{
515
        static char buf[NI_MAXHOST];
516
        const int niflag = NI_NUMERICHOST;
517
 
518
        if (sa == NULL)
519
                return "";
520
 
521
        if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), NULL, 0, niflag) == 0)
522
                return buf;
523
        return NULL;
524
}
525
 
526
/*
527
 * set "/prefix[port number]" to buffer.
528
 */
529
static char *
530
str_prefport(family, pref, port, ulp)
531
        u_int family, pref, port, ulp;
532
{
533
        static char buf[128];
534
        char prefbuf[128];
535
        char portbuf[128];
536
        int plen;
537
 
538
        switch (family) {
539
        case AF_INET:
540
                plen = sizeof(struct in_addr) << 3;
541
                break;
542
        case AF_INET6:
543
                plen = sizeof(struct in6_addr) << 3;
544
                break;
545
        default:
546
                return "?";
547
        }
548
 
549
        if (pref == plen)
550
                prefbuf[0] = '\0';
551
        else
552
                snprintf(prefbuf, sizeof(prefbuf), "/%u", pref);
553
 
554
        if (ulp == IPPROTO_ICMPV6)
555
                memset(portbuf, 0, sizeof(portbuf));
556
        else {
557
                if (port == IPSEC_PORT_ANY)
558
                        snprintf(portbuf, sizeof(portbuf), "[%s]", "any");
559
                else
560
                        snprintf(portbuf, sizeof(portbuf), "[%u]", port);
561
        }
562
 
563
        snprintf(buf, sizeof(buf), "%s%s", prefbuf, portbuf);
564
 
565
        return buf;
566
}
567
 
568
static void
569
str_upperspec(ulp, p1, p2)
570
        u_int ulp, p1, p2;
571
{
572
        if (ulp == IPSEC_ULPROTO_ANY)
573
                printf("any");
574
        else if (ulp == IPPROTO_ICMPV6) {
575
                printf("icmp6");
576
                if (!(p1 == IPSEC_PORT_ANY && p2 == IPSEC_PORT_ANY))
577
                        printf(" %u,%u", p1, p2);
578
        } else {
579
                struct protoent *ent;
580
 
581
                switch (ulp) {
582
                case IPPROTO_IPV4:
583
                        printf("ip4");
584
                        break;
585
                default:
586
                        ent = getprotobynumber(ulp);
587
                        if (ent)
588
                                printf("%s", ent->p_name);
589
                        else
590
                                printf("%u", ulp);
591
 
592
                        endprotoent();
593
                        break;
594
                }
595
        }
596
}
597
 
598
/*
599
 * set "Mon Day Time Year" to buffer
600
 */
601
static char *
602
str_time(t)
603
        time_t t;
604
{
605
        static char buf[128];
606
 
607
        if (t == 0) {
608
                int i = 0;
609
                for (;i < 20;) buf[i++] = ' ';
610
        } else {
611
                char *t0;
612
                t0 = ctime(&t);
613
                memcpy(buf, t0 + 4, 20);
614
        }
615
 
616
        buf[20] = '\0';
617
 
618
        return(buf);
619
}
620
 
621
static void
622
str_lifetime_byte(x, str)
623
        struct sadb_lifetime *x;
624
        char *str;
625
{
626
        double y;
627
        char *unit;
628
        int w;
629
 
630
        if (x == NULL) {
631
                printf("\t%s: 0(bytes)", str);
632
                return;
633
        }
634
 
635
#if 0
636
        if ((x->sadb_lifetime_bytes) / 1024 / 1024) {
637
                y = (x->sadb_lifetime_bytes) * 1.0 / 1024 / 1024;
638
                unit = "M";
639
                w = 1;
640
        } else if ((x->sadb_lifetime_bytes) / 1024) {
641
                y = (x->sadb_lifetime_bytes) * 1.0 / 1024;
642
                unit = "K";
643
                w = 1;
644
        } else {
645
                y = (x->sadb_lifetime_bytes) * 1.0;
646
                unit = "";
647
                w = 0;
648
        }
649
#else
650
        y = (x->sadb_lifetime_bytes) * 1.0;
651
        unit = "";
652
        w = 0;
653
#endif
654
        printf("\t%s: %.*f(%sbytes)", str, w, y, unit);
655
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.