2 * convert from binary form of SA ID to text
3 * Copyright (C) 2000, 2001 Henry Spencer.
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Library General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/lgpl.txt>.
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 * License for more details.
15 * RCSID $Id: satot.c,v 1.8 2001/10/23 03:06:16 henry Exp $
20 static struct typename {
33 - satot - convert SA to text "ah507@1.2.3.4"
35 size_t /* space needed for full conversion */
36 satot(sa, format, dst, dstlen)
38 int format; /* character */
39 char *dst; /* need not be valid if dstlen is 0 */
42 size_t len = 0; /* 0 means "not recognized yet" */
44 int showversion; /* use delimiter to show IP version? */
48 char buf[10+1+ULTOT_BUF+ADDRTOT_BUF];
74 for (tn = typenames; tn->name != NULL; tn++)
75 if (sa->proto == tn->type) {
77 break; /* NOTE BREAK OUT */
79 if (pre == NULL) { /* unknown protocol */
81 (void) ultot((unsigned char)sa->proto, 10, unk+strlen(unk),
82 sizeof(unk)-strlen(unk));
86 if (strcmp(pre, PASSTHROUGHTYPE) == 0 &&
87 sa->spi == PASSTHROUGHSPI &&
88 isunspecaddr(&sa->dst)) {
89 strcpy(buf, (addrtypeof(&sa->dst) == AF_INET) ?
95 if (sa->proto == SA_INT && addrtypeof(&sa->dst) == AF_INET &&
96 isunspecaddr(&sa->dst)) {
97 switch (ntohl(sa->spi)) {
98 case SPI_PASS: p = "%pass"; break;
99 case SPI_DROP: p = "%drop"; break;
100 case SPI_REJECT: p = "%reject"; break;
101 case SPI_HOLD: p = "%hold"; break;
102 case SPI_TRAP: p = "%trap"; break;
103 case SPI_TRAPSUBNET: p = "%trapsubnet"; break;
104 default: p = NULL; break;
112 if (len == 0) { /* general case needed */
116 *(buf+len) = (addrtypeof(&sa->dst) == AF_INET) ? '.' :
121 len += ultot(ntohl(sa->spi), base, buf+len, sizeof(buf)-len);
123 len += addrtot(&sa->dst, 0, buf+len, sizeof(buf)-len);
128 *(buf+dstlen-1) = '\0';