From 01deed2d864586fd85326f5a34b090485b1deecf Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Sat, 1 May 2010 10:17:09 +0200 Subject: [PATCH] Fix compilation on modern Linux platforms. Other operating systems should function as before, but Linux platforms running glibc-2.1 or older will probably fail. (we're talking glibc releases more than 10 years old) Also fix a 64 bit typing error in the DNS resolution code. --- Config | 5 --- Makefile.dist | 4 +- include/nameser.h | 6 +++ include/resolv.h | 78 -------------------------------------- include/resolv_legacy.h | 83 +++++++++++++++++++++++++++++++++++++++++ src/Makefile | 4 +- src/res.c | 8 +++- src/res_init.c | 3 +- src/res_mkquery.c | 2 +- src/s_bsd.c | 2 +- 10 files changed, 102 insertions(+), 93 deletions(-) create mode 100644 include/resolv_legacy.h diff --git a/Config b/Config index 45d1f51..69399c4 100755 --- a/Config +++ b/Config @@ -738,11 +738,6 @@ if [ $? -ne 0 -o "$OSNAME" = "Linux RedHat 5.0" -o -n "$NEEDSKIPNAME" -o "$GLIBC sed -e "s@^RES=\(.*\)@RES=res_skipname.o@" Makefile > Makefile.tmp cp Makefile.tmp Makefile $RM -f Makefile.tmp -else - $RM -f Makefile.tmp - sed -e "s@^RES=\(.*\)@RES=res_init.o@" Makefile > Makefile.tmp - cp Makefile.tmp Makefile - $RM -f Makefile.tmp fi $RM -f $EXEC $TMP cat > $TMP <<__EOF__ diff --git a/Makefile.dist b/Makefile.dist index 7a27634..32c9656 100755 --- a/Makefile.dist +++ b/Makefile.dist @@ -91,10 +91,8 @@ IRCDDIR=/usr/local/lib/ircd #RES=res_init.o res_comp.o res_mkquery.o # BSDI systems want this. #RES=res_skipname.o -# Recent Linux systems seem to expect this: -RES=res_init.o # The rest are perfectly content with this. -#RES= +RES= # [CHANGEME] # If you get a compile-time error dealing with u_int32_t, comment out diff --git a/include/nameser.h b/include/nameser.h index 9e06b97..280828e 100644 --- a/include/nameser.h +++ b/include/nameser.h @@ -19,6 +19,9 @@ * @(#)nameser.h 5.24 (Berkeley) 6/1/90 */ +#include +#ifndef __GLIBC__ + /* * Define constants based on rfc883 */ @@ -246,3 +249,6 @@ extern u_long _getlong(); (cp)[0] = l >> 8; \ (cp) += sizeof(u_long); \ } + +#endif + diff --git a/include/resolv.h b/include/resolv.h index d9feb76..e69de29 100644 --- a/include/resolv.h +++ b/include/resolv.h @@ -1,78 +0,0 @@ -/* - * Copyright (c) 1983, 1987, 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that: (1) source distributions retain this entire copyright - * notice and comment, and (2) distributions including binaries display - * the following acknowledgement: ``This product includes software - * developed by the University of California, Berkeley and its contributors'' - * in the documentation or other materials provided with the distribution - * and in all advertising materials mentioning features or use of this - * software. Neither the name of the University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * @(#)resolv.h 5.10.1 (Berkeley) 6/1/90 - */ - -/* - * Resolver configuration file. - * Normally not present, but may contain the address of the - * inital name server(s) to query and the domain search list. - */ - -#ifndef _PATH_RESCONF -#define _PATH_RESCONF "/etc/resolv.conf" -#endif - -/* - * Global defines and variables for resolver stub. - */ -#define MAXNS 3 /* max # name servers we'll track */ -#define MAXDFLSRCH 3 /* # default domain levels to try */ -#define MAXDNSRCH 6 /* max # domains in search path */ -#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */ -#define MAXSERVICES 2 /* max # of services to search */ - -#define RES_TIMEOUT 5 /* min. seconds between retries */ - -struct state { - int retrans; /* retransmition time interval */ - int retry; /* number of times to retransmit */ - long options; /* option flags - see below. */ - int nscount; /* number of name servers */ - struct sockaddr_in nsaddr_list[MAXNS]; /* address of name server */ -#define nsaddr nsaddr_list[0] /* for backward compatibility */ - unsigned short id; /* current packet id */ - char defdname[MAXDNAME]; /* default domain */ - char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */ - unsigned short order[MAXSERVICES+1]; /* search service order */ -}; - -#define RES_SERVICE_NONE 0 -#define RES_SERVICE_BIND 1 -#define RES_SERVICE_LOCAL 2 - -/* - * Resolver options - */ -#define RES_INIT 0x0001 /* address initialized */ -#define RES_DEBUG 0x0002 /* print debug messages */ -#define RES_AAONLY 0x0004 /* authoritative answers only */ -#define RES_USEVC 0x0008 /* use virtual circuit */ -#define RES_PRIMARY 0x0010 /* query primary server only */ -#define RES_IGNTC 0x0020 /* ignore trucation errors */ -#define RES_RECURSE 0x0040 /* recursion desired */ -#define RES_DEFNAMES 0x0080 /* use default domain name */ -#define RES_STAYOPEN 0x0100 /* Keep TCP socket open */ -#define RES_DNSRCH 0x0200 /* search up local domain tree */ - -#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH) - -extern struct state _res; -extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time(); - diff --git a/include/resolv_legacy.h b/include/resolv_legacy.h new file mode 100644 index 0000000..845d5e0 --- /dev/null +++ b/include/resolv_legacy.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1983, 1987, 1989 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that: (1) source distributions retain this entire copyright + * notice and comment, and (2) distributions including binaries display + * the following acknowledgement: ``This product includes software + * developed by the University of California, Berkeley and its contributors'' + * in the documentation or other materials provided with the distribution + * and in all advertising materials mentioning features or use of this + * software. Neither the name of the University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#)resolv.h 5.10.1 (Berkeley) 6/1/90 + */ + +#include +#ifndef __GLIBC__ + +/* + * Resolver configuration file. + * Normally not present, but may contain the address of the + * inital name server(s) to query and the domain search list. + */ + +#ifndef _PATH_RESCONF +#define _PATH_RESCONF "/etc/resolv.conf" +#endif + +/* + * Global defines and variables for resolver stub. + */ +#define MAXNS 3 /* max # name servers we'll track */ +#define MAXDFLSRCH 3 /* # default domain levels to try */ +#define MAXDNSRCH 6 /* max # domains in search path */ +#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */ +#define MAXSERVICES 2 /* max # of services to search */ + +#define RES_TIMEOUT 5 /* min. seconds between retries */ + +struct state { + int retrans; /* retransmition time interval */ + int retry; /* number of times to retransmit */ + long options; /* option flags - see below. */ + int nscount; /* number of name servers */ + struct sockaddr_in nsaddr_list[MAXNS]; /* address of name server */ +#define nsaddr nsaddr_list[0] /* for backward compatibility */ + unsigned short id; /* current packet id */ + char defdname[MAXDNAME]; /* default domain */ + char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */ + unsigned short order[MAXSERVICES+1]; /* search service order */ +}; + +#define RES_SERVICE_NONE 0 +#define RES_SERVICE_BIND 1 +#define RES_SERVICE_LOCAL 2 + +/* + * Resolver options + */ +#define RES_INIT 0x0001 /* address initialized */ +#define RES_DEBUG 0x0002 /* print debug messages */ +#define RES_AAONLY 0x0004 /* authoritative answers only */ +#define RES_USEVC 0x0008 /* use virtual circuit */ +#define RES_PRIMARY 0x0010 /* query primary server only */ +#define RES_IGNTC 0x0020 /* ignore trucation errors */ +#define RES_RECURSE 0x0040 /* recursion desired */ +#define RES_DEFNAMES 0x0080 /* use default domain name */ +#define RES_STAYOPEN 0x0100 /* Keep TCP socket open */ +#define RES_DNSRCH 0x0200 /* search up local domain tree */ + +#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH) + +extern struct state _res; +extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time(); + +#endif + diff --git a/src/Makefile b/src/Makefile index 5dcd0f0..8fa24f0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -164,7 +164,7 @@ res.o: res.c ../include/struct.h ../include/config.h \ ../include/setup.h ../include/common.h \ ../include/sys.h ../include/class.h ../include/dbuf.h \ ../include/whowas.h ../include/res.h ../include/numeric.h \ - ../include/h.h ../include/nameser.h ../include/resolv.h \ + ../include/h.h ../include/nameser.h ../include/resolv_legacy.h \ ../include/inet.h masking.o: masking.c ../include/struct.h ../include/config.h \ ../include/setup.h ../include/common.h \ @@ -176,7 +176,7 @@ s_bsd.o: s_bsd.c ../include/struct.h ../include/config.h \ ../include/sys.h ../include/class.h ../include/dbuf.h \ ../include/whowas.h ../include/res.h ../include/numeric.h \ ../include/patchlevel.h ../include/inet.h ../include/nameser.h \ - ../include/resolv.h ../include/sock.h ../include/h.h + ../include/resolv_legacy.h ../include/sock.h ../include/h.h s_conf.o: s_conf.c ../include/struct.h ../include/config.h \ ../include/setup.h ../include/common.h \ ../include/sys.h ../include/class.h ../include/dbuf.h \ diff --git a/src/res.c b/src/res.c index dbfd0eb..5b6b67b 100644 --- a/src/res.c +++ b/src/res.c @@ -15,16 +15,20 @@ #include #include #include +#include +#include #include "nameser.h" -#include "resolv.h" +#include "resolv_legacy.h" #include "inet.h" /* inet_addr() */ #undef DEBUG /* because there is a lot of debug code in here :-) */ +#ifndef __GLIBC__ extern int dn_expand PROTO ((char *, char *, char *, char *, int)); extern int dn_skipname PROTO ((char *, char *)); extern int res_mkquery PROTO ((int, char *, int, int, char *, int, struct rrec *, char *, int)); +#endif extern int errno, h_errno; extern int highest_fd; @@ -528,7 +532,7 @@ static int proc_answer (rptr, hptr, buf, eob) class = (int) _getshort (cp); cp += sizeof (short); rptr->ttl = _getlong (cp); - cp += sizeof (rptr->ttl); + cp += 4; dlen = (int) _getshort (cp); cp += sizeof (short); rptr->type = type; diff --git a/src/res_init.c b/src/res_init.c index eb31335..ca025df 100644 --- a/src/res_init.c +++ b/src/res_init.c @@ -22,11 +22,12 @@ #include #include #include +#include #include "config.h" /* To get #define SOL20 Vesa */ #include "sys.h" #include "common.h" #include "nameser.h" -#include "resolv.h" +#include "resolv_legacy.h" /* * Resolver state default settings diff --git a/src/res_mkquery.c b/src/res_mkquery.c index c342fdc..c9c03e4 100644 --- a/src/res_mkquery.c +++ b/src/res_mkquery.c @@ -23,7 +23,7 @@ #include "config.h" #include "sys.h" #include "nameser.h" -#include "resolv.h" +#include "resolv_legacy.h" /* * Form all types of queries. diff --git a/src/s_bsd.c b/src/s_bsd.c index 7079253..4dc0161 100644 --- a/src/s_bsd.c +++ b/src/s_bsd.c @@ -45,7 +45,7 @@ #else #include "nameser.h" #endif -#include "resolv.h" +#include "resolv_legacy.h" #include "sock.h" /* If FD_ZERO isn't define up to this point, */ /* define it (BSD4.2 needs this) */ #include "h.h" -- 2.30.2