2 * convert from binary form of SA ID to ASCII
3 * Copyright (C) 1998, 1999, 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: satoa.c,v 1.12 2001/09/25 00:09:51 rgb Exp $
20 static struct typename {
33 - satoa - convert SA to ASCII "ah507@1.2.3.4"
35 size_t /* space needed for full conversion */
36 satoa(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 handled yet */
45 char buf[30+ADDRTOA_BUF];
49 base = 16; /* temporarily at least */
59 for (tn = typenames; tn->name != NULL; tn++)
60 if (sa.proto == tn->type)
65 if (strcmp(tn->name, PASSTHROUGHTYPE) == 0 &&
66 sa.spi == PASSTHROUGHSPI &&
67 sa.dst.s_addr == PASSTHROUGHDST) {
68 strcpy(buf, PASSTHROUGHNAME);
70 } else if (sa.proto == SA_INT && sa.dst.s_addr == 0) {
73 switch (ntohl(sa.spi)) {
74 case SPI_PASS: p = "%pass"; break;
75 case SPI_DROP: p = "%drop"; break;
76 case SPI_REJECT: p = "%reject"; break;
77 case SPI_HOLD: p = "%hold"; break;
78 case SPI_TRAP: p = "%trap"; break;
79 case SPI_TRAPSUBNET: p = "%trapsubnet"; break;
80 default: p = NULL; break;
89 strcpy(buf, tn->name);
91 len += ultoa(ntohl(sa.spi), base, buf+len, sizeof(buf)-len);
93 len += addrtoa(sa.dst, 0, buf+len, sizeof(buf)-len);
98 *(buf+dstlen-1) = '\0';