3
* Copyright (C) 1998, 1999 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: addrtoa.c,v 1.7.36.1 2004/03/21 05:23:31 mcr Exp $
20
#define NBYTES 4 /* bytes in an address */
21
#define PERBYTE 4 /* three digits plus a dot or NUL */
22
#define BUFLEN (NBYTES*PERBYTE)
24
#if BUFLEN != ADDRTOA_BUF
25
#error "ADDRTOA_BUF in openswan.h inconsistent with addrtoa() code"
29
- addrtoa - convert binary address to ASCII dotted decimal
31
size_t /* space needed for full conversion */
32
addrtoa(addr, format, dst, dstlen)
34
int format; /* character */
35
char *dst; /* need not be valid if dstlen is 0 */
38
unsigned long a = ntohl(addr.s_addr);
54
for (i = NBYTES-1; i >= 0; i--) {
55
byte = (a >> (i*8)) & 0xff;
56
p += ultoa(byte, 10, p, PERBYTE);
64
buf[dstlen - 1] = '\0';