ea7fc621ce
- Update the resolver in libc to BIND9's one. - make reentrant version of netdb functions glibc style API, and expose them to outside of libc. - make netdb functions NSS friendly. include/Makefile 1.261 include/arpa/inet.h 1.26 include/arpa/nameser.h 1.18 include/arpa/nameser_compat.h 1.5 include/netdb.h 1.40-1.42 include/res_update.h 1.1 include/resolv.h 1.29-1.30 lib/libc/Makefile 1.64 lib/libc/include/isc/eventlib.h 1.1.1.1 lib/libc/include/port_after.h 1.1-1.2 lib/libc/include/port_before.h 1.1 lib/libc/include/resolv_mt.h 1.1.1.1 lib/libc/inet/Makefile.inc 1.1 lib/libc/inet/inet_addr.c 1.1.1.1, 1.2 lib/libc/inet/inet_cidr_ntop.c 1.1.1.1 lib/libc/inet/inet_cidr_pton.c 1.1.1.1, 1.2 lib/libc/inet/inet_lnaof.c 1.1.1.1, 1.2 lib/libc/inet/inet_makeaddr.c 1.1.1.1, 1.2 lib/libc/inet/inet_net_ntop.c 1.1.1.1, 1.2 lib/libc/inet/inet_net_pton.c 1.1.1.1, 1.2 lib/libc/inet/inet_neta.c 1.1.1.1, 1.2 lib/libc/inet/inet_netof.c 1.1.1.1, 1.2 lib/libc/inet/inet_network.c 1.1.1.1, 1.2 lib/libc/inet/inet_ntoa.c 1.1.1.1, 1.2 lib/libc/inet/inet_ntop.c 1.1.1.1, 1.2 lib/libc/inet/inet_pton.c 1.1.1.1, 1.2 lib/libc/inet/nsap_addr.c 1.1.1.1, 1.2 lib/libc/isc/Makefile.inc 1.1 lib/libc/isc/ev_streams.c 1.1.1.1, 1.2 lib/libc/isc/ev_timers.c 1.1.1.1, 1.2 lib/libc/isc/eventlib_p.h 1.1.1.1, 1.2 lib/libc/nameser/Makefile.inc 1.1 lib/libc/nameser/ns_name.c 1.1.1.1 lib/libc/nameser/ns_netint.c 1.1.1.1 lib/libc/nameser/ns_parse.c 1.1.1.1 lib/libc/nameser/ns_print.c 1.1.1.1, 1.2 lib/libc/nameser/ns_samedomain.c 1.1.1.1, 1.2 lib/libc/nameser/ns_ttl.c 1.1.1.1 lib/libc/net/Makefile.inc 1.58 lib/libc/net/getaddrinfo.c 1.74, 1.77-1.78 lib/libc/net/gethostbydns.c 1.55-1.57 lib/libc/net/gethostbyht.c 1.24-1.26 lib/libc/net/gethostbyname.3 1.35 lib/libc/net/gethostbynis.c 1.26-1.28 lib/libc/net/gethostnamadr.c 1.29-1.30, 1.32 lib/libc/net/getnameinfo.c 1.18 lib/libc/net/getnetbydns.c 1.32-1.33 lib/libc/net/getnetbyht.c 1.17-1.18 lib/libc/net/getnetbynis.c 1.20-1.21 lib/libc/net/getnetnamadr.c 1.22 lib/libc/net/getproto.c 1.5 lib/libc/net/getprotoent.c 1.7 lib/libc/net/getprotoname.c 1.5 lib/libc/net/getservbyname.c 1.8 lib/libc/net/getservbyport.c 1.8 lib/libc/net/getservent.c 1.21 lib/libc/net/name6.c 1.56-1.57 lib/libc/net/netdb_private.h 1.10-1.11, 1.13 lib/libc/net/res_config.h 1.9 lib/libc/net/res_mkupdate.c 1.7-1.8 lib/libc/net/res_update.c 1.8-1.9 lib/libc/resolv/Makefile.inc 1.1 lib/libc/resolv/h_errno.c 1.1 lib/libc/resolv/herror.c 1.1.1.1, 1.2 lib/libc/resolv/mtctxres.c 1.1.1.1, 1.2 lib/libc/resolv/res_comp.c 1.1.1.1, 1.2 lib/libc/resolv/res_data.c 1.1.1.1, 1.2-1.3 lib/libc/resolv/res_debug.c 1.1.1.1, 1.2 lib/libc/resolv/res_debug.h 1.1.1.1 lib/libc/resolv/res_init.c 1.1.1.1, 1.2 lib/libc/resolv/res_mkquery.c 1.1.1.1, 1.2 lib/libc/resolv/res_private.h 1.1.1.1 lib/libc/resolv/res_query.c 1.1.1.1, 1.2-1.3 lib/libc/resolv/res_send.c 1.1.1.1, 1.2 lib/libc/resolv/res_state.c 1.1-1.2 Tested by: nork
163 lines
3.2 KiB
C
163 lines
3.2 KiB
C
/*
|
|
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
|
* Copyright (c) 1996,1999 by Internet Software Consortium.
|
|
*
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#ifndef lint
|
|
static const char rcsid[] = "$Id: ns_ttl.c,v 1.1.206.2 2005/07/28 07:43:21 marka Exp $";
|
|
#endif
|
|
#include <sys/cdefs.h>
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
/* Import. */
|
|
|
|
#include "port_before.h"
|
|
|
|
#include <arpa/nameser.h>
|
|
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "port_after.h"
|
|
|
|
#ifdef SPRINTF_CHAR
|
|
# define SPRINTF(x) strlen(sprintf/**/x)
|
|
#else
|
|
# define SPRINTF(x) ((size_t)sprintf x)
|
|
#endif
|
|
|
|
/* Forward. */
|
|
|
|
static int fmt1(int t, char s, char **buf, size_t *buflen);
|
|
|
|
/* Macros. */
|
|
|
|
#define T(x) if ((x) < 0) return (-1); else (void)NULL
|
|
|
|
/* Public. */
|
|
|
|
int
|
|
ns_format_ttl(u_long src, char *dst, size_t dstlen) {
|
|
char *odst = dst;
|
|
int secs, mins, hours, days, weeks, x;
|
|
char *p;
|
|
|
|
secs = src % 60; src /= 60;
|
|
mins = src % 60; src /= 60;
|
|
hours = src % 24; src /= 24;
|
|
days = src % 7; src /= 7;
|
|
weeks = src; src = 0;
|
|
|
|
x = 0;
|
|
if (weeks) {
|
|
T(fmt1(weeks, 'W', &dst, &dstlen));
|
|
x++;
|
|
}
|
|
if (days) {
|
|
T(fmt1(days, 'D', &dst, &dstlen));
|
|
x++;
|
|
}
|
|
if (hours) {
|
|
T(fmt1(hours, 'H', &dst, &dstlen));
|
|
x++;
|
|
}
|
|
if (mins) {
|
|
T(fmt1(mins, 'M', &dst, &dstlen));
|
|
x++;
|
|
}
|
|
if (secs || !(weeks || days || hours || mins)) {
|
|
T(fmt1(secs, 'S', &dst, &dstlen));
|
|
x++;
|
|
}
|
|
|
|
if (x > 1) {
|
|
int ch;
|
|
|
|
for (p = odst; (ch = *p) != '\0'; p++)
|
|
if (isascii(ch) && isupper(ch))
|
|
*p = tolower(ch);
|
|
}
|
|
|
|
return (dst - odst);
|
|
}
|
|
|
|
int
|
|
ns_parse_ttl(const char *src, u_long *dst) {
|
|
u_long ttl, tmp;
|
|
int ch, digits, dirty;
|
|
|
|
ttl = 0;
|
|
tmp = 0;
|
|
digits = 0;
|
|
dirty = 0;
|
|
while ((ch = *src++) != '\0') {
|
|
if (!isascii(ch) || !isprint(ch))
|
|
goto einval;
|
|
if (isdigit(ch)) {
|
|
tmp *= 10;
|
|
tmp += (ch - '0');
|
|
digits++;
|
|
continue;
|
|
}
|
|
if (digits == 0)
|
|
goto einval;
|
|
if (islower(ch))
|
|
ch = toupper(ch);
|
|
switch (ch) {
|
|
case 'W': tmp *= 7;
|
|
case 'D': tmp *= 24;
|
|
case 'H': tmp *= 60;
|
|
case 'M': tmp *= 60;
|
|
case 'S': break;
|
|
default: goto einval;
|
|
}
|
|
ttl += tmp;
|
|
tmp = 0;
|
|
digits = 0;
|
|
dirty = 1;
|
|
}
|
|
if (digits > 0) {
|
|
if (dirty)
|
|
goto einval;
|
|
else
|
|
ttl += tmp;
|
|
} else if (!dirty)
|
|
goto einval;
|
|
*dst = ttl;
|
|
return (0);
|
|
|
|
einval:
|
|
errno = EINVAL;
|
|
return (-1);
|
|
}
|
|
|
|
/* Private. */
|
|
|
|
static int
|
|
fmt1(int t, char s, char **buf, size_t *buflen) {
|
|
char tmp[50];
|
|
size_t len;
|
|
|
|
len = SPRINTF((tmp, "%d%c", t, s));
|
|
if (len + 1 > *buflen)
|
|
return (-1);
|
|
strcpy(*buf, tmp);
|
|
*buf += len;
|
|
*buflen -= len;
|
|
return (0);
|
|
}
|