Get rid of Apple's RendezVous mDNS implementation

This commit is contained in:
Julien BLACHE 2009-04-01 15:00:59 +02:00
parent 1ca30657ac
commit 3a8c7b3c41
23 changed files with 6 additions and 25666 deletions

View File

@ -31,7 +31,6 @@ http://www.fireflymediaserver.org</a>.
<p>
This program makes use of the following libraries and packages:
<ul>
<li>Apple's <a href="http://bonjour.macosforge.org/">Bonjour v107.3</a> licensed under the <a href="apache-2.0.html">Apache 2.0 License</a></li>
<li>Fabrice Bellard's <a href="http://ffmpeg.mplayerhq.hu/">FFmpeg</a>, licensed under the <a href="gpl-license.html">GPL License</a></li>
<li>D. Richard Hipp's <a href="http://sqlite.org">SQLite</a> database, dedicated to the public domain</li>
<li>Underbit Technologies' <a href="http://www.underbit.com/products/mad/">libid3tag</a>, licensed under the <a href="gpl-license.html">GPL License</a></li>

View File

@ -1,9 +0,0 @@
@include hdr.html@
<h2>Apache 2.0 License</h2>
<p class="license"><pre>
@include apache-2.0.txt@
</pre></p>
@include ftr.html@

View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -39,7 +39,6 @@ fi
AC_DEFINE_UNQUOTED(CONFFILE,"${CONFFILE}",Where the config file is)
rend_posix=true
rend_avahi=false
db_sqlite=false
db_sqlite3=false
@ -80,7 +79,7 @@ AC_ARG_ENABLE(sqlite3,[ --enable-sqlite3 Enable sqlite3 db backend],
AC_ARG_ENABLE(mdns,[ --enable-mdns Enable mDNS support],
[ case "${enableval}" in
yes) ;;
no) rend_posix=false; rend_howl=false; rend_avahi=false; CPPFLAGS="${CPPFLAGS} -DWITHOUT_MDNS";;
no) rend_howl=false; rend_avahi=false; CPPFLAGS="${CPPFLAGS} -DWITHOUT_MDNS";;
*) AC_MSG_ERROR(bad value ${enableval} for --disable-mdns);;
esac ])
@ -90,7 +89,7 @@ AC_ARG_ENABLE(nslu2,[ --enable-nslu2 Build for NSLU2/uNSLUng],
AC_ARG_ENABLE(avahi,[ --enable-avahi Use avahi 0.6 or later],
[ case "${enableval}" in
yes) PKG_CHECK_MODULES(AVAHI, [ avahi-client >= 0.6 ]);
rend_avahi=true; rend_howl=false; rend_posix=false; LDFLAGS="${LDFLAGS} $AVAHI_LIBS";
rend_avahi=true; rend_howl=false; LDFLAGS="${LDFLAGS} $AVAHI_LIBS";
CPPFLAGS="${CPPFLAGS} $AVAHI_CFLAGS -DWITH_AVAHI";;
no) rend_avahi=false;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-avahi);;
@ -98,7 +97,7 @@ AC_ARG_ENABLE(avahi,[ --enable-avahi Use avahi 0.6 or later],
AC_ARG_ENABLE(howl,[ --enable-howl Use howl 0.9.2 or later],
[ case "${enableval}" in
yes) rend_howl=true; rend_posix=false; rend_avahi=false; LIBS="${LIBS} -lhowl";
yes) rend_howl=true; rend_avahi=false; LIBS="${LIBS} -lhowl";
CPPFLAGS="${CPPFLAGS} -DWITH_HOWL";;
no) rend_howl=false;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-howl);;
@ -137,7 +136,6 @@ AC_ARG_ENABLE(ssl,[ --enable-ssl Enable SSL support in web server],
CPPFLAGS="${CPPFLAGS} -DUSE_SSL"; use_ssl=true; )
AM_CONDITIONAL(COND_REND_HOWL, test x$rend_howl = xtrue)
AM_CONDITIONAL(COND_REND_POSIX, test x$rend_posix = xtrue)
AM_CONDITIONAL(COND_REND_AVAHI, test x$rend_avahi = xtrue)
AM_CONDITIONAL(COND_OGGVORBIS, test x$use_oggvorbis = xtrue)
AM_CONDITIONAL(COND_FLAC, test x$use_flac = xtrue)
@ -171,36 +169,6 @@ dnl Darwin's stupid cpp preprocessor....
echo Host type is $host
CPPFLAGS="$CPPFLAGS -DHOST='\"$host\"'"
dnl
dnl The apple mDNS stuff wants these compile flags.
dnl
case $host in
*solaris*)
CPPFLAGS="$CPPFLAGS -DNOT_HAVE_DAEMON -DNOT_HAVE_SA_LEN "
CPPFLAGS="$CPPFLAGS -DNOT_HAVE_SOCKLEN_T -DNOT_HAVE_IF_NAMETOINDEX "
CPPFLAGS="$CPPFLAGS -DLOG_PERROR=0 -D_XPG4_2 -D__EXTENSIONS__ "
CPPFLAGS="$CPPFLAGS -DHAVE_BROKEN_RECVIF_NAME "
CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
LIBS="${LIBS} -lnsl -lsocket -lresolv";;
*freebsd*)
CPPFLAGS="$CPPFLAGS -DFREEBSD"
LDFLAGS="${LDFLAGS} -Wl,--export-dynamic";;
*linux*)
CPPFLAGS="$CPPFLAGS -DNOT_HAVE_SA_LEN -DUSES_NETLINK -DHAVE_LINUX"
LDFLAGS="${LDFLAGS} -Wl,--export-dynamic";;
*openbsd*)
CPPFLAGS="$CPPFLAGS -DHAVE_BROKEN_RECVDSTADDR"
LDFLAGS="${LDFLAGS} -Wl,--export-dynamic";;
*darwin*)
CPPFLAGS="$CPPFLAGS -no-cpp-precomp -DMAC"
LDFLAGS="$LDFLAGS -framework CoreFoundation"
AM_CONDITIONAL(COND_REND_OSX,true)
AM_CONDITIONAL(COND_REND_HOWL,false)
AM_CONDITIONAL(COND_REND_POSIX,false);;
esac
dnl Checks for libraries.
AC_ARG_WITH(static-libs,
[--with-static-libs[[=DIR]] use static libs in DIR],[
@ -492,4 +460,4 @@ if test x$use_iconv = xtrue; then
LDFLAGS="${LDFLAGS} ${LIBICONV}"
fi
AC_OUTPUT(src/Makefile src/plugins/Makefile admin-root/Makefile admin-root/lib-js/Makefile admin-root/lib-js/script.aculo.us/Makefile contrib/Makefile contrib/init.d/Makefile src/mdns/Makefile Makefile)
AC_OUTPUT(src/Makefile src/plugins/Makefile admin-root/Makefile admin-root/lib-js/Makefile admin-root/lib-js/script.aculo.us/Makefile contrib/Makefile contrib/init.d/Makefile Makefile)

View File

@ -7,13 +7,6 @@ bin_PROGRAMS = wavstreamer
LDADD=
if COND_REND_POSIX
SUBDIRS += mdns
AM_CPPFLAGS = -I./mdns
LDADD+=mdns/libmdns.la
PRENDSRC=rend-unix.c rend-posix.c
endif
if COND_REND_HOWL
HRENDSRC=rend-howl.c rend-unix.c
endif
@ -72,11 +65,11 @@ mt_daapd_SOURCES = main.c daapd.h rend.h webserver.c \
os-unix.h os-unix.c os.h plugin.c plugin.h db-sql-updates.c \
memdebug.c memdebug.h ssl.h io.h io.c io-errors.h io-plugin.h \
bsd-snprintf.c bsd-snprintf.h \
$(PRENDSRC) $(ORENDSRC) $(HRENDSRC) $(ARENDSRC) $(OGGVORBISSRC) \
$(ORENDSRC) $(HRENDSRC) $(ARENDSRC) $(OGGVORBISSRC) \
$(FLACSRC) $(MUSEPACKSRC) $(SQLITEDB) $(SQLITE3DB) $(SQLDB) $(GDBM) \
$(UPNP)
EXTRA_DIST = rend-howl.c rend-posix.c rend-osx.c scan-mpc.c \
EXTRA_DIST = rend-howl.c rend-osx.c scan-mpc.c \
scan-ogg.c scan-flac.c db-sql.c db-sql.h \
db-sql-sqlite2.h db-sql-sqlite2.c \
db-sql-sqlite3.h db-sql-sqlite3.c \

File diff suppressed because it is too large Load Diff

View File

@ -1,366 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Change History (most recent first):
$Log: DNSCommon.h,v $
Revision 1.34.2.1 2006/08/29 06:24:22 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.34 2006/03/18 21:47:56 cheshire
<rdar://problem/4073825> Improve logic for delaying packets after repeated interface transitions
Revision 1.33 2006/03/10 21:51:41 cheshire
<rdar://problem/4111464> After record update, old record sometimes remains in cache
Split out SameRDataBody() into a separate routine so it can be called from other code
Revision 1.32 2005/03/21 00:33:51 shersche
<rdar://problem/4021486> Fix build warnings on Win32 platform
Revision 1.31 2005/02/18 00:43:11 cheshire
<rdar://problem/4010245> mDNSResponder should auto-truncate service names that are too long
Revision 1.30 2005/01/19 03:12:44 cheshire
Move LocalRecordReady() macro from mDNS.c to DNSCommon.h
Revision 1.29 2004/12/15 02:11:22 ksekar
<rdar://problem/3917317> Don't check for Dynamic DNS hostname uniqueness
Revision 1.28 2004/12/06 21:15:22 ksekar
<rdar://problem/3884386> mDNSResponder crashed in CheckServiceRegistrations
Revision 1.27 2004/12/03 07:20:50 ksekar
<rdar://problem/3674208> Wide-Area: Registration of large TXT record fails
Revision 1.26 2004/12/03 05:18:33 ksekar
<rdar://problem/3810596> mDNSResponder needs to return more specific TSIG errors
Revision 1.25 2004/10/26 03:52:02 cheshire
Update checkin comments
Revision 1.24 2004/10/23 01:16:00 cheshire
<rdar://problem/3851677> uDNS operations not always reliable on multi-homed hosts
Revision 1.23 2004/10/03 23:18:58 cheshire
Move address comparison macros from DNSCommon.h to mDNSEmbeddedAPI.h
Revision 1.22 2004/09/30 00:24:56 ksekar
<rdar://problem/3695802> Dynamically update default registration domains on config change
Revision 1.21 2004/09/17 01:08:48 cheshire
Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
declared in that file are ONLY appropriate to single-address-space embedded applications.
For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
Revision 1.20 2004/09/17 00:49:51 cheshire
Get rid of now-unused GetResourceRecord -- the correct (safe) routine to use
is GetLargeResourceRecord
Revision 1.19 2004/09/16 21:59:15 cheshire
For consistency with zerov6Addr, rename zeroIPAddr to zerov4Addr
Revision 1.18 2004/09/16 02:29:39 cheshire
Moved mDNS_Lock/mDNS_Unlock to DNSCommon.c; Added necessary locking around
uDNS_ReceiveMsg, uDNS_StartQuery, uDNS_UpdateRecord, uDNS_RegisterService
Revision 1.17 2004/09/14 23:27:46 cheshire
Fix compile errors
Revision 1.16 2004/08/13 23:46:58 cheshire
"asyncronous" -> "asynchronous"
Revision 1.15 2004/08/10 23:19:14 ksekar
<rdar://problem/3722542>: DNS Extension daemon for Wide Area Service Discovery
Moved routines/constants to allow extern access for garbage collection daemon
Revision 1.14 2004/05/28 23:42:36 ksekar
<rdar://problem/3258021>: Feature: DNS server->client notification on record changes (#7805)
Revision 1.13 2004/05/18 23:51:25 cheshire
Tidy up all checkin comments to use consistent "<rdar://problem/xxxxxxx>" format for bug numbers
Revision 1.12 2004/04/22 04:03:59 cheshire
Headers should use "extern" declarations, not "mDNSexport"
Revision 1.11 2004/04/14 23:09:28 ksekar
Support for TSIG signed dynamic updates.
Revision 1.10 2004/03/13 01:57:33 ksekar
<rdar://problem/3192546>: DynDNS: Dynamic update of service records
Revision 1.9 2004/02/21 08:56:58 bradley
Wrap prototypes with extern "C" for C++ builds.
Revision 1.8 2004/02/06 23:04:18 ksekar
Basic Dynamic Update support via mDNS_Register (dissabled via
UNICAST_REGISTRATION #define)
Revision 1.7 2004/02/03 19:47:36 ksekar
Added an asynchronous state machine mechanism to uDNS.c, including
calls to find the parent zone for a domain name. Changes include code
in repository previously dissabled via "#if 0 incomplete". Codepath
is currently unused, and will be called to create update records, etc.
Revision 1.6 2004/01/27 20:15:22 cheshire
<rdar://problem/3541288>: Time to prune obsolete code for listening on port 53
Revision 1.5 2004/01/24 03:40:56 cheshire
Move mDNSAddrIsDNSMulticast() from DNSCommon.h to mDNSEmbeddedAPI.h so embedded clients can use it
Revision 1.4 2004/01/24 03:38:27 cheshire
Fix minor syntactic error: Headers should use "extern" declarations, not "mDNSexport"
Revision 1.3 2004/01/23 23:23:14 ksekar
Added TCP support for truncated unicast messages.
Revision 1.2 2004/01/21 21:12:23 cheshire
Add missing newline at end of file to make Unix tools happier
Revision 1.1 2003/12/13 03:05:27 ksekar
<rdar://problem/3192548>: DynDNS: Unicast query of service records
*/
#ifndef __DNSCOMMON_H_
#define __DNSCOMMON_H_
#include "mDNSEmbeddedAPI.h"
#ifdef __cplusplus
extern "C" {
#endif
// ***************************************************************************
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark - DNS Protocol Constants
#endif
typedef enum
{
kDNSFlag0_QR_Mask = 0x80, // Query or response?
kDNSFlag0_QR_Query = 0x00,
kDNSFlag0_QR_Response = 0x80,
kDNSFlag0_OP_Mask = 0x78, // Operation type
kDNSFlag0_OP_StdQuery = 0x00,
kDNSFlag0_OP_Iquery = 0x08,
kDNSFlag0_OP_Status = 0x10,
kDNSFlag0_OP_Unused3 = 0x18,
kDNSFlag0_OP_Notify = 0x20,
kDNSFlag0_OP_Update = 0x28,
kDNSFlag0_QROP_Mask = kDNSFlag0_QR_Mask | kDNSFlag0_OP_Mask,
kDNSFlag0_AA = 0x04, // Authoritative Answer?
kDNSFlag0_TC = 0x02, // Truncated?
kDNSFlag0_RD = 0x01, // Recursion Desired?
kDNSFlag1_RA = 0x80, // Recursion Available?
kDNSFlag1_Zero = 0x40, // Reserved; must be zero
kDNSFlag1_AD = 0x20, // Authentic Data [RFC 2535]
kDNSFlag1_CD = 0x10, // Checking Disabled [RFC 2535]
kDNSFlag1_RC = 0x0F, // Response code
kDNSFlag1_RC_NoErr = 0x00,
kDNSFlag1_RC_FmtErr = 0x01,
kDNSFlag1_RC_SrvErr = 0x02,
kDNSFlag1_RC_NXDomain = 0x03,
kDNSFlag1_RC_NotImpl = 0x04,
kDNSFlag1_RC_Refused = 0x05,
kDNSFlag1_RC_YXDomain = 0x06,
kDNSFlag1_RC_YXRRSet = 0x07,
kDNSFlag1_RC_NXRRSet = 0x08,
kDNSFlag1_RC_NotAuth = 0x09,
kDNSFlag1_RC_NotZone = 0x0A
} DNS_Flags;
typedef enum
{
TSIG_ErrBadSig = 16,
TSIG_ErrBadKey = 17,
TSIG_ErrBadTime = 18
} TSIG_ErrorCode;
// ***************************************************************************
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark -
#pragma mark - General Utility Functions
#endif
extern const NetworkInterfaceInfo *GetFirstActiveInterface(const NetworkInterfaceInfo *intf);
extern mDNSInterfaceID GetNextActiveInterfaceID(const NetworkInterfaceInfo *intf);
extern mDNSu32 mDNSRandom(mDNSu32 max);
extern mDNSu32 mDNSRandomFromFixedSeed(mDNSu32 seed, mDNSu32 max);
// ***************************************************************************
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark -
#pragma mark - Domain Name Utility Functions
#endif
#define mdnsIsDigit(X) ((X) >= '0' && (X) <= '9')
#define mDNSIsUpperCase(X) ((X) >= 'A' && (X) <= 'Z')
#define mDNSIsLowerCase(X) ((X) >= 'a' && (X) <= 'z')
#define mdnsIsLetter(X) (mDNSIsUpperCase(X) || mDNSIsLowerCase(X))
#define mdnsValidHostChar(X, notfirst, notlast) (mdnsIsLetter(X) || mdnsIsDigit(X) || ((notfirst) && (notlast) && (X) == '-') )
extern mDNSu16 CompressedDomainNameLength(const domainname *const name, const domainname *parent);
extern mDNSu32 TruncateUTF8ToLength(mDNSu8 *string, mDNSu32 length, mDNSu32 max);
extern mDNSBool LabelContainsSuffix(const domainlabel *const name, const mDNSBool RichText);
extern mDNSu32 RemoveLabelSuffix(domainlabel *name, mDNSBool RichText);
extern void AppendLabelSuffix(domainlabel *name, mDNSu32 val, mDNSBool RichText);
extern void mDNS_HostNameCallback(mDNS *const m, AuthRecord *const rr, mStatus result);
#define ValidateDomainName(N) (DomainNameLength(N) <= MAX_DOMAIN_NAME)
// ***************************************************************************
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark -
#pragma mark - Resource Record Utility Functions
#endif
extern mDNSu32 RDataHashValue(mDNSu16 const rdlength, const RDataBody *const rdb);
extern mDNSBool SameRDataBody(const ResourceRecord *const r1, const RDataBody *const r2);
extern mDNSBool SameRData(const ResourceRecord *const r1, const ResourceRecord *const r2);
extern mDNSBool ResourceRecordAnswersQuestion(const ResourceRecord *const rr, const DNSQuestion *const q);
extern mDNSBool SameResourceRecord(ResourceRecord *r1, ResourceRecord *r2);
extern mDNSu16 GetRDLength(const ResourceRecord *const rr, mDNSBool estimate);
#define GetRRDomainNameTarget(RR) ( \
((RR)->rrtype == kDNSType_CNAME || (RR)->rrtype == kDNSType_PTR || (RR)->rrtype == kDNSType_NS) \
? &(RR)->rdata->u.name : \
((RR)->rrtype == kDNSType_SRV ) ? &(RR)->rdata->u.srv.target : mDNSNULL )
extern mDNSBool ValidateRData(const mDNSu16 rrtype, const mDNSu16 rdlength, const RData *const rd);
#define LocalRecordReady(X) ((X)->resrec.RecordType != kDNSRecordTypeUnique && (X)->resrec.RecordType != kDNSRecordTypeDeregistering)
// ***************************************************************************
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark -
#pragma mark -
#pragma mark - DNS Message Creation Functions
#endif
extern void InitializeDNSMessage(DNSMessageHeader *h, mDNSOpaque16 id, mDNSOpaque16 flags);
extern const mDNSu8 *FindCompressionPointer(const mDNSu8 *const base, const mDNSu8 *const end, const mDNSu8 *const domname);
extern mDNSu8 *putDomainNameAsLabels(const DNSMessage *const msg, mDNSu8 *ptr, const mDNSu8 *const limit, const domainname *const name);
extern mDNSu8 *putRData(const DNSMessage *const msg, mDNSu8 *ptr, const mDNSu8 *const limit, ResourceRecord *rr);
// If we have a single large record to put in the packet, then we allow the packet to be up to 9K bytes,
// but in the normal case we try to keep the packets below 1500 to avoid IP fragmentation on standard Ethernet
extern mDNSu8 *PutResourceRecordTTLWithLimit(DNSMessage *const msg, mDNSu8 *ptr, mDNSu16 *count, ResourceRecord *rr, mDNSu32 ttl, const mDNSu8 *limit);
#define PutResourceRecordTTL(msg, ptr, count, rr, ttl) PutResourceRecordTTLWithLimit((msg), (ptr), (count), (rr), (ttl), \
((msg)->h.numAnswers || (msg)->h.numAuthorities || (msg)->h.numAdditionals) ? (msg)->data + NormalMaxDNSMessageData : (msg)->data + AbsoluteMaxDNSMessageData)
#define PutResourceRecordTTLJumbo(msg, ptr, count, rr, ttl) PutResourceRecordTTLWithLimit((msg), (ptr), (count), (rr), (ttl), \
(msg)->data + AbsoluteMaxDNSMessageData)
extern mDNSu8 *PutResourceRecordCappedTTL(DNSMessage *const msg, mDNSu8 *ptr, mDNSu16 *count, ResourceRecord *rr, mDNSu32 maxttl);
extern mDNSu8 *putEmptyResourceRecord(DNSMessage *const msg, mDNSu8 *ptr, const mDNSu8 *const limit, mDNSu16 *count, const AuthRecord *rr);
extern mDNSu8 *putQuestion(DNSMessage *const msg, mDNSu8 *ptr, const mDNSu8 *const limit, const domainname *const name, mDNSu16 rrtype, mDNSu16 rrclass);
extern mDNSu8 *putZone(DNSMessage *const msg, mDNSu8 *ptr, mDNSu8 *limit, const domainname *zone, mDNSOpaque16 zoneClass);
extern mDNSu8 *putPrereqNameNotInUse(domainname *name, DNSMessage *msg, mDNSu8 *ptr, mDNSu8 *end);
extern mDNSu8 *putDeletionRecord(DNSMessage *msg, mDNSu8 *ptr, ResourceRecord *rr);
extern mDNSu8 *putDeleteRRSet(DNSMessage *msg, mDNSu8 *ptr, const domainname *name, mDNSu16 rrtype);
extern mDNSu8 *putDeleteAllRRSets(DNSMessage *msg, mDNSu8 *ptr, const domainname *name);
extern mDNSu8 *putUpdateLease(DNSMessage *msg, mDNSu8 *end, mDNSu32 lease);
#define PutResourceRecord(MSG, P, C, RR) PutResourceRecordTTL((MSG), (P), (C), (RR), (RR)->rroriginalttl)
// ***************************************************************************
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark -
#pragma mark - DNS Message Parsing Functions
#endif
extern mDNSu32 DomainNameHashValue(const domainname *const name);
extern void SetNewRData(ResourceRecord *const rr, RData *NewRData, mDNSu16 rdlength);
extern const mDNSu8 *skipDomainName(const DNSMessage *const msg, const mDNSu8 *ptr, const mDNSu8 *const end);
extern const mDNSu8 *getDomainName(const DNSMessage *const msg, const mDNSu8 *ptr, const mDNSu8 *const end,
domainname *const name);
extern const mDNSu8 *skipResourceRecord(const DNSMessage *msg, const mDNSu8 *ptr, const mDNSu8 *end);
extern const mDNSu8 *GetLargeResourceRecord(mDNS *const m, const DNSMessage * const msg, const mDNSu8 *ptr,
const mDNSu8 * end, const mDNSInterfaceID InterfaceID, mDNSu8 RecordType, LargeCacheRecord *largecr);
extern const mDNSu8 *skipQuestion(const DNSMessage *msg, const mDNSu8 *ptr, const mDNSu8 *end);
extern const mDNSu8 *getQuestion(const DNSMessage *msg, const mDNSu8 *ptr, const mDNSu8 *end, const mDNSInterfaceID InterfaceID,
DNSQuestion *question);
extern const mDNSu8 *LocateAnswers(const DNSMessage *const msg, const mDNSu8 *const end);
extern const mDNSu8 *LocateAuthorities(const DNSMessage *const msg, const mDNSu8 *const end);
extern const mDNSu8 *LocateAdditionals(const DNSMessage *const msg, const mDNSu8 *const end);
// ***************************************************************************
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark -
#pragma mark -
#pragma mark - Packet Sending Functions
#endif
extern mStatus mDNSSendDNSMessage(const mDNS *const m, DNSMessage *const msg, mDNSu8 *end,
mDNSInterfaceID InterfaceID, const mDNSAddr *dst, mDNSIPPort dstport, int sd, uDNS_AuthInfo *authInfo);
// ***************************************************************************
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark -
#pragma mark - RR List Management & Task Management
#endif
extern void mDNS_Lock(mDNS *const m);
extern void mDNS_Unlock(mDNS *const m);
#ifdef __cplusplus
}
#endif
#endif // __DNSCOMMON_H_

File diff suppressed because it is too large Load Diff

View File

@ -1,332 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
File: GenLinkedList.c
Contains: implementation of generic linked lists.
Version: 1.0
Tabs: 4 spaces
Change History (most recent first):
$Log: GenLinkedList.c,v $
Revision 1.4 2006/08/14 23:24:56 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.3 2004/04/22 21:14:42 cheshire
Fix comment spelling mistake
Revision 1.2 2004/02/05 07:41:08 cheshire
Add Log header
*/
#include "GenLinkedList.h"
// Return the link pointer contained within element e at offset o.
#define GETLINK( e, o) ( *(void**)((char*) (e) + (o)) )
// Assign the link pointer l to element e at offset o.
#define ASSIGNLINK( e, l, o) ( *((void**)((char*) (e) + (o))) = (l))
// GenLinkedList /////////////////////////////////////////////////////////////
void InitLinkedList( GenLinkedList *pList, size_t linkOffset)
/* Initialize the block of memory pointed to by pList as a linked list. */
{
pList->Head = NULL;
pList->Tail = NULL;
pList->LinkOffset = linkOffset;
}
void AddToTail( GenLinkedList *pList, void *elem)
/* Add a linked list element to the tail of the list. */
{
if ( pList->Tail) {
ASSIGNLINK( pList->Tail, elem, pList->LinkOffset);
} else
pList->Head = elem;
ASSIGNLINK( elem, NULL, pList->LinkOffset);
pList->Tail = elem;
}
void AddToHead( GenLinkedList *pList, void *elem)
/* Add a linked list element to the head of the list. */
{
ASSIGNLINK( elem, pList->Head, pList->LinkOffset);
if ( pList->Tail == NULL)
pList->Tail = elem;
pList->Head = elem;
}
int RemoveFromList( GenLinkedList *pList, void *elem)
/* Remove a linked list element from the list. Return 0 if it was not found. */
/* If the element is removed, its link will be set to NULL. */
{
void *iElem, *lastElem;
for ( iElem = pList->Head, lastElem = NULL; iElem; iElem = GETLINK( iElem, pList->LinkOffset)) {
if ( iElem == elem) {
if ( lastElem) { // somewhere past the head
ASSIGNLINK( lastElem, GETLINK( elem, pList->LinkOffset), pList->LinkOffset);
} else { // at the head
pList->Head = GETLINK( elem, pList->LinkOffset);
}
if ( pList->Tail == elem)
pList->Tail = lastElem ? lastElem : NULL;
ASSIGNLINK( elem, NULL, pList->LinkOffset); // maybe catch a stale reference bug.
return 1;
}
lastElem = iElem;
}
return 0;
}
int ReplaceElem( GenLinkedList *pList, void *elemInList, void *newElem)
/* Replace an element in the list with a new element, in the same position. */
{
void *iElem, *lastElem;
if ( elemInList == NULL || newElem == NULL)
return 0;
for ( iElem = pList->Head, lastElem = NULL; iElem; iElem = GETLINK( iElem, pList->LinkOffset))
{
if ( iElem == elemInList)
{
ASSIGNLINK( newElem, GETLINK( elemInList, pList->LinkOffset), pList->LinkOffset);
if ( lastElem) // somewhere past the head
{
ASSIGNLINK( lastElem, newElem, pList->LinkOffset);
}
else // at the head
{
pList->Head = newElem;
}
if ( pList->Tail == elemInList)
pList->Tail = newElem;
return 1;
}
lastElem = iElem;
}
return 0;
}
// GenDoubleLinkedList /////////////////////////////////////////////////////////
void InitDoubleLinkedList( GenDoubleLinkedList *pList, size_t fwdLinkOffset,
size_t backLinkOffset)
/* Initialize the block of memory pointed to by pList as a double linked list. */
{
pList->Head = NULL;
pList->Tail = NULL;
pList->FwdLinkOffset = fwdLinkOffset;
pList->BackLinkOffset = backLinkOffset;
}
void DLLAddToHead( GenDoubleLinkedList *pList, void *elem)
/* Add a linked list element to the head of the list. */
{
void *pNext;
pNext = pList->Head;
// fix up the forward links
ASSIGNLINK( elem, pList->Head, pList->FwdLinkOffset);
pList->Head = elem;
// fix up the backward links
if ( pNext) {
ASSIGNLINK( pNext, elem, pList->BackLinkOffset);
} else
pList->Tail = elem;
ASSIGNLINK( elem, NULL, pList->BackLinkOffset);
}
void DLLRemoveFromList( GenDoubleLinkedList *pList, void *elem)
/* Remove a linked list element from the list. */
/* When the element is removed, its link will be set to NULL. */
{
void *pNext, *pPrev;
pNext = GETLINK( elem, pList->FwdLinkOffset);
pPrev = GETLINK( elem, pList->BackLinkOffset);
// fix up the forward links
if ( pPrev)
ASSIGNLINK( pPrev, pNext, pList->FwdLinkOffset);
else
pList->Head = pNext;
// fix up the backward links
if ( pNext)
ASSIGNLINK( pNext, pPrev, pList->BackLinkOffset);
else
pList->Tail = pPrev;
ASSIGNLINK( elem, NULL, pList->FwdLinkOffset);
ASSIGNLINK( elem, NULL, pList->BackLinkOffset);
}
// GenLinkedOffsetList /////////////////////////////////////////////////////
// Extract the Next offset from element
#define GETOFFSET( e, o) ( *(size_t*)((char*) (e) + (o)) )
static void AssignOffsetLink( void *elem, void *link, size_t linkOffset);
static void AssignOffsetLink( void *elem, void *link, size_t linkOffset)
// Assign link to elem as an offset from elem. Assign 0 to elem if link is NULL.
{
GETOFFSET( elem, linkOffset) = link ? (size_t) link - (size_t) elem : 0;
}
void *GetHeadPtr( GenLinkedOffsetList *pList)
/* Return a pointer to the head element of a list, or NULL if none. */
{
return pList->Head ? ( (char*) (pList) + pList->Head) : NULL;
}
void *GetTailPtr( GenLinkedOffsetList *pList)
/* Return a pointer to the tail element of a list, or NULL if none. */
{
return pList->Tail ? ( (char*) (pList) + pList->Tail) : NULL;
}
void *GetOffsetLink( GenLinkedOffsetList *pList, void *elem)
/* Return the link pointer contained within element e for pList, or NULL if it is 0. */
{
size_t nextOffset;
nextOffset = GETOFFSET( elem, pList->LinkOffset);
return nextOffset ? (char*) elem + nextOffset : NULL;
}
void InitLinkedOffsetList( GenLinkedOffsetList *pList, size_t linkOffset)
/* Initialize the block of memory pointed to by pList as a linked list. */
{
pList->Head = 0;
pList->Tail = 0;
pList->LinkOffset = linkOffset;
}
void OffsetAddToTail( GenLinkedOffsetList *pList, void *elem)
/* Add a linked list element to the tail of the list. */
{
if ( pList->Tail) {
AssignOffsetLink( GetTailPtr( pList), elem, pList->LinkOffset);
} else
pList->Head = (size_t) elem - (size_t) pList;
AssignOffsetLink( elem, NULL, pList->LinkOffset);
pList->Tail = (size_t) elem - (size_t) pList;
}
void OffsetAddToHead( GenLinkedOffsetList *pList, void *elem)
/* Add a linked list element to the head of the list. */
{
AssignOffsetLink( elem, GetHeadPtr( pList), pList->LinkOffset);
if ( pList->Tail == 0)
pList->Tail = (size_t) elem - (size_t) pList;
pList->Head = (size_t) elem - (size_t) pList;
}
int OffsetRemoveFromList( GenLinkedOffsetList *pList, void *elem)
/* Remove a linked list element from the list. Return 0 if it was not found. */
/* If the element is removed, its link will be set to NULL. */
{
void *iElem, *lastElem;
for ( iElem = GetHeadPtr( pList), lastElem = NULL; iElem;
iElem = GetOffsetLink( pList, iElem))
{
if ( iElem == elem) {
if ( lastElem) { // somewhere past the head
AssignOffsetLink( lastElem, GetOffsetLink( pList, elem), pList->LinkOffset);
} else { // at the head
iElem = GetOffsetLink( pList, elem);
pList->Head = iElem ? (size_t) iElem - (size_t) pList : 0;
}
if ( GetTailPtr( pList) == elem)
pList->Tail = lastElem ? (size_t) lastElem - (size_t) pList : 0;
AssignOffsetLink( elem, NULL, pList->LinkOffset); // maybe catch a stale reference bug.
return 1;
}
lastElem = iElem;
}
return 0;
}
int OffsetReplaceElem( GenLinkedOffsetList *pList, void *elemInList, void *newElem)
/* Replace an element in the list with a new element, in the same position. */
{
void *iElem, *lastElem;
if ( elemInList == NULL || newElem == NULL)
return 0;
for ( iElem = GetHeadPtr( pList), lastElem = NULL; iElem;
iElem = GetOffsetLink( pList, iElem))
{
if ( iElem == elemInList)
{
AssignOffsetLink( newElem, GetOffsetLink( pList, elemInList), pList->LinkOffset);
if ( lastElem) // somewhere past the head
{
AssignOffsetLink( lastElem, newElem, pList->LinkOffset);
}
else // at the head
{
pList->Head = (size_t) newElem - (size_t) pList;
}
if ( GetTailPtr( pList) == elemInList)
pList->Tail = (size_t) newElem - (size_t) pList;
return 1;
}
lastElem = iElem;
}
return 0;
}

View File

@ -1,107 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
File: GenLinkedList.c
Contains: interface to generic linked lists.
Version: 1.0
Tabs: 4 spaces
Change History (most recent first):
$Log: GenLinkedList.h,v $
Revision 1.3 2006/08/14 23:24:56 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.2 2004/02/05 07:41:08 cheshire
Add Log header
*/
#ifndef __GenLinkedList__
#define __GenLinkedList__
#include <stddef.h>
struct GenLinkedList
{
void *Head,
*Tail;
size_t LinkOffset;
};
typedef struct GenLinkedList GenLinkedList;
void InitLinkedList( GenLinkedList *pList, size_t linkOffset);
void AddToHead( GenLinkedList *pList, void *elem);
void AddToTail( GenLinkedList *pList, void *elem);
int RemoveFromList( GenLinkedList *pList, void *elem);
int ReplaceElem( GenLinkedList *pList, void *elemInList, void *newElem);
struct GenDoubleLinkedList
{
void *Head,
*Tail;
size_t FwdLinkOffset,
BackLinkOffset;
};
typedef struct GenDoubleLinkedList GenDoubleLinkedList;
void InitDoubleLinkedList( GenDoubleLinkedList *pList, size_t fwdLinkOffset,
size_t backLinkOffset);
void DLLAddToHead( GenDoubleLinkedList *pList, void *elem);
void DLLRemoveFromList( GenDoubleLinkedList *pList, void *elem);
/* A GenLinkedOffsetList is like a GenLinkedList that stores the *Next field as a signed */
/* offset from the address of the beginning of the element, rather than as a pointer. */
struct GenLinkedOffsetList
{
size_t Head,
Tail;
size_t LinkOffset;
};
typedef struct GenLinkedOffsetList GenLinkedOffsetList;
void InitLinkedOffsetList( GenLinkedOffsetList *pList, size_t linkOffset);
void *GetHeadPtr( GenLinkedOffsetList *pList);
void *GetTailPtr( GenLinkedOffsetList *pList);
void *GetOffsetLink( GenLinkedOffsetList *pList, void *elem);
void OffsetAddToHead( GenLinkedOffsetList *pList, void *elem);
void OffsetAddToTail( GenLinkedOffsetList *pList, void *elem);
int OffsetRemoveFromList( GenLinkedOffsetList *pList, void *elem);
int OffsetReplaceElem( GenLinkedOffsetList *pList, void *elemInList, void *newElem);
#endif // __GenLinkedList__

View File

@ -1,11 +0,0 @@
AM_CPPFLAGS = -I..
noinst_LTLIBRARIES = libmdns.la
libmdns_la_SOURCES = mDNS.c mDNSPosix.c mDNSPosix.h mDNSUNP.c mDNSUNP.h \
DNSCommon.h DNSCommon.c uDNS.c uDNS.h mDNSEmbeddedAPI.h \
mDNSDebug.h DNSDigest.c GenLinkedList.c GenLinkedList.h \
dns_sd.h mDNSDebug.c

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +0,0 @@
/**
* wrapper for LogMsg to use built-in error logging
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "err.h"
void LogMsg(const char *format, ...) {
unsigned char buffer[512];
va_list ptr;
va_start(ptr,format);
memset(buffer,0,sizeof(buffer));
vsnprintf((char*)buffer, sizeof(buffer), format, ptr);
va_end(ptr);
DPRINTF(E_WARN,L_REND,"%s\n",buffer);
}

View File

@ -1,190 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Change History (most recent first):
$Log: mDNSDebug.h,v $
Revision 1.26.2.1 2006/08/29 06:24:22 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.26 2005/07/04 22:40:26 cheshire
Additional debugging code to help catch memory corruption
Revision 1.25 2004/12/14 21:34:16 cheshire
Add "#define ANSWER_REMOTE_HOSTNAME_QUERIES 0" and comment
Revision 1.24 2004/09/16 01:58:21 cheshire
Fix compiler warnings
Revision 1.23 2004/05/18 23:51:25 cheshire
Tidy up all checkin comments to use consistent "<rdar://problem/xxxxxxx>" format for bug numbers
Revision 1.22 2004/04/22 04:27:42 cheshire
Spacing tidyup
Revision 1.21 2004/04/14 23:21:41 ksekar
Removed accidental checkin of MALLOC_DEBUGING flag in 1.20
Revision 1.20 2004/04/14 23:09:28 ksekar
Support for TSIG signed dynamic updates.
Revision 1.19 2004/03/15 18:57:59 cheshire
Undo last checkin that accidentally made verbose debugging the default for all targets
Revision 1.18 2004/03/13 01:57:33 ksekar
<rdar://problem/3192546>: DynDNS: Dynamic update of service records
Revision 1.17 2004/01/28 21:14:23 cheshire
Reconcile debug_mode and gDebugLogging into a single flag (mDNS_DebugMode)
Revision 1.16 2003/12/09 01:30:06 rpantos
Fix usage of ARGS... macros to build properly on Windows.
Revision 1.15 2003/12/08 20:55:26 rpantos
Move some definitions here from mDNSMacOSX.h.
Revision 1.14 2003/08/12 19:56:24 cheshire
Update to APSL 2.0
Revision 1.13 2003/07/02 21:19:46 cheshire
<rdar://problem/3313413> Update copyright notices, etc., in source code comments
Revision 1.12 2003/05/26 03:01:27 cheshire
<rdar://problem/3268904> sprintf/vsprintf-style functions are unsafe; use snprintf/vsnprintf instead
Revision 1.11 2003/05/21 17:48:10 cheshire
Add macro to enable GCC's printf format string checking
Revision 1.10 2003/04/26 02:32:57 cheshire
Add extern void LogMsg(const char *format, ...);
Revision 1.9 2002/09/21 20:44:49 zarzycki
Added APSL info
Revision 1.8 2002/09/19 04:20:43 cheshire
Remove high-ascii characters that confuse some systems
Revision 1.7 2002/09/16 18:41:42 cheshire
Merge in license terms from Quinn's copy, in preparation for Darwin release
*/
#ifndef __mDNSDebug_h
#define __mDNSDebug_h
// Set MDNS_DEBUGMSGS to 0 to optimize debugf() calls out of the compiled code
// Set MDNS_DEBUGMSGS to 1 to generate normal debugging messages
// Set MDNS_DEBUGMSGS to 2 to generate verbose debugging messages
// MDNS_DEBUGMSGS is normally set in the project options (or makefile) but can also be set here if desired
// (If you edit the file here to turn on MDNS_DEBUGMSGS while you're debugging some code, be careful
// not to accidentally check-in that change by mistake when you check in your other changes.)
//#undef MDNS_DEBUGMSGS
//#define MDNS_DEBUGMSGS 2
// Set MDNS_CHECK_PRINTF_STYLE_FUNCTIONS to 1 to enable extra GCC compiler warnings
// Note: You don't normally want to do this, because it generates a bunch of
// spurious warnings for the following custom extensions implemented by mDNS_vsnprintf:
// warning: `#' flag used with `%s' printf format (for %#s -- pascal string format)
// warning: repeated `#' flag in format (for %##s -- DNS name string format)
// warning: double format, pointer arg (arg 2) (for %.4a, %.16a, %#a -- IP address formats)
#define MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 0
#if MDNS_CHECK_PRINTF_STYLE_FUNCTIONS
#define IS_A_PRINTF_STYLE_FUNCTION(F,A) __attribute__ ((format(printf,F,A)))
#else
#define IS_A_PRINTF_STYLE_FUNCTION(F,A)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if MDNS_DEBUGMSGS
#define debugf debugf_
extern void debugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
#else // If debug breaks are off, use a preprocessor trick to optimize those calls out of the code
#if (defined(__GNUC__))
#define debugf( ARGS... ) ((void)0)
#elif (defined(__MWERKS__))
#define debugf( ... )
#else
#define debugf 1 ? ((void)0) : (void)
#endif
#endif
#if MDNS_DEBUGMSGS > 1
#define verbosedebugf verbosedebugf_
extern void verbosedebugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
#else
#if (defined(__GNUC__))
#define verbosedebugf( ARGS... ) ((void)0)
#elif (defined(__MWERKS__))
#define verbosedebugf( ... )
#else
#define verbosedebugf 1 ? ((void)0) : (void)
#endif
#endif
// LogMsg is used even in shipping code, to write truly serious error messages to syslog (or equivalent)
extern int mDNS_DebugMode; // If non-zero, LogMsg() writes to stderr instead of syslog
extern void LogMsg(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
extern void LogMsgIdent(const char *ident, const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(2,3);
extern void LogMsgNoIdent(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
// Set this symbol to 1 to answer remote queries for our Address, reverse mapping PTR, and HINFO records
#define ANSWER_REMOTE_HOSTNAME_QUERIES 0
// Set this symbol to 1 to do extra debug checks on malloc() and free()
// Set this symbol to 2 to write a log message for every malloc() and free()
#define MACOSX_MDNS_MALLOC_DEBUGGING 0
#if MACOSX_MDNS_MALLOC_DEBUGGING >= 1
extern void *mallocL(char *msg, unsigned int size);
extern void freeL(char *msg, void *x);
extern void LogMemCorruption(const char *format, ...);
extern void uds_validatelists(void);
#else
#define mallocL(X,Y) malloc(Y)
#define freeL(X,Y) free(Y)
#endif
#if MACOSX_MDNS_MALLOC_DEBUGGING >= 2
#define LogMalloc LogMsg
#else
#if (defined( __GNUC__ ))
#define LogMalloc(ARGS...) ((void)0)
#elif (defined( __MWERKS__ ))
#define LogMalloc( ... )
#else
#define LogMalloc 1 ? ((void)0) : (void)
#endif
#endif
#define LogAllOperations 0
#if LogAllOperations
#define LogOperation LogMsg
#else
#define LogOperation debugf
#endif
#define ForceAlerts 0
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,145 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Change History (most recent first):
$Log: mDNSPosix.h,v $
Revision 1.18 2006/08/14 23:24:47 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.17 2005/02/04 00:39:59 cheshire
Move ParseDNSServers() from PosixDaemon.c to mDNSPosix.c so all Posix client layers can use it
Revision 1.16 2004/11/30 22:37:01 cheshire
Update copyright dates and add "Mode: C; tab-width: 4" headers
Revision 1.15 2004/02/06 01:19:51 cheshire
Conditionally exclude IPv6 code unless HAVE_IPV6 is set
Revision 1.14 2004/01/28 21:12:15 cheshire
Reconcile mDNSIPv6Support & HAVE_IPV6 into a single flag (HAVE_IPV6)
Revision 1.13 2004/01/24 05:12:03 cheshire
<rdar://problem/3534352>: Need separate socket for issuing unicast queries
Revision 1.12 2004/01/23 21:37:08 cheshire
For consistency, rename multicastSocket to multicastSocket4, and multicastSocketv6 to multicastSocket6
Revision 1.11 2003/12/11 03:03:51 rpantos
Clean up mDNSPosix so that it builds on OS X again.
Revision 1.10 2003/12/08 20:47:02 rpantos
Add support for mDNSResponder on Linux.
Revision 1.9 2003/10/30 19:25:19 cheshire
Fix warning on certain compilers
Revision 1.8 2003/08/12 19:56:26 cheshire
Update to APSL 2.0
Revision 1.7 2003/07/02 21:19:59 cheshire
<rdar://problem/3313413> Update copyright notices, etc., in source code comments
Revision 1.6 2003/03/13 03:46:21 cheshire
Fixes to make the code build on Linux
Revision 1.5 2003/03/08 00:35:56 cheshire
Switched to using new "mDNS_Execute" model (see "mDNSCore/Implementer Notes.txt")
Revision 1.4 2002/12/23 22:13:31 jgraessl
Reviewed by: Stuart Cheshire
Initial IPv6 support for mDNSResponder.
Revision 1.3 2002/09/21 20:44:53 zarzycki
Added APSL info
Revision 1.2 2002/09/19 04:20:44 cheshire
Remove high-ascii characters that confuse some systems
Revision 1.1 2002/09/17 06:24:34 cheshire
First checkin
*/
#ifndef __mDNSPlatformPosix_h
#define __mDNSPlatformPosix_h
#include <signal.h>
#include <sys/time.h>
#ifdef __cplusplus
extern "C" {
#endif
// PosixNetworkInterface is a record extension of the core NetworkInterfaceInfo
// type that supports extra fields needed by the Posix platform.
//
// IMPORTANT: coreIntf must be the first field in the structure because
// we cast between pointers to the two different types regularly.
typedef struct PosixNetworkInterface PosixNetworkInterface;
struct PosixNetworkInterface
{
NetworkInterfaceInfo coreIntf;
const char * intfName;
PosixNetworkInterface * aliasIntf;
int index;
int multicastSocket4;
#if HAVE_IPV6
int multicastSocket6;
#endif
};
// This is a global because debugf_() needs to be able to check its value
extern int gMDNSPlatformPosixVerboseLevel;
struct mDNS_PlatformSupport_struct
{
int unicastSocket4;
#if HAVE_IPV6
int unicastSocket6;
#endif
};
#define uDNS_SERVERS_FILE "/etc/resolv.conf"
extern int ParseDNSServers(mDNS *m, const char *filePath);
extern mStatus mDNSPlatformPosixRefreshInterfaceList(mDNS *const m);
// See comment in implementation.
// Call mDNSPosixGetFDSet before calling select(), to update the parameters
// as may be necessary to meet the needs of the mDNSCore code.
// The timeout pointer MUST NOT be NULL.
// Set timeout->tv_sec to 0x3FFFFFFF if you want to have effectively no timeout
// After calling mDNSPosixGetFDSet(), call select(nfds, &readfds, NULL, NULL, &timeout); as usual
// After select() returns, call mDNSPosixProcessFDSet() to let mDNSCore do its work
extern void mDNSPosixGetFDSet(mDNS *m, int *nfds, fd_set *readfds, struct timeval *timeout);
extern void mDNSPosixProcessFDSet(mDNS *const m, fd_set *readfds);
typedef void (*mDNSPosixEventCallback)( void *context);
extern mStatus mDNSPosixAddFDToEventLoop( int fd, mDNSPosixEventCallback callback, void *context);
extern mStatus mDNSPosixRemoveFDFromEventLoop( int fd);
extern mStatus mDNSPosixListenForSignalInEventLoop( int signum);
extern mStatus mDNSPosixIgnoreSignalInEventLoop( int signum);
extern mStatus mDNSPosixRunEventLoopOnce( mDNS *m, const struct timeval *pTimeout, sigset_t *pSignalsReceived, mDNSBool *pDataDispatched);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,766 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Change History (most recent first):
$Log: mDNSUNP.c,v $
Revision 1.34 2006/08/14 23:24:47 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.33 2006/03/13 23:14:21 cheshire
<rdar://problem/4427969> Compile problems on FreeBSD
Use <netinet/in_var.h> instead of <netinet6/in6_var.h>
Revision 1.32 2005/12/21 02:56:43 cheshire
<rdar://problem/4243433> get_ifi_info() should fake ifi_index when SIOCGIFINDEX undefined
Revision 1.31 2005/12/21 02:46:05 cheshire
<rdar://problem/4243514> mDNSUNP.c needs to include <sys/param.h> on 4.4BSD Lite
Revision 1.30 2005/11/29 20:03:02 mkrochma
Wrapped sin_len with #ifndef NOT_HAVE_SA_LEN
Revision 1.29 2005/11/12 02:23:10 cheshire
<rdar://problem/4317680> mDNSUNP.c needs to deal with lame results from SIOCGIFNETMASK, SIOCGIFBRDADDR and SIOCGIFDSTADDR
Revision 1.28 2005/10/31 22:09:45 cheshire
Buffer "char addr6[33]" was seven bytes too small
Revision 1.27 2005/06/29 15:54:21 cheshire
<rdar://problem/4113742> mDNSResponder-107.1 does not work on FreeBSD
Refine last checkin so that it (hopefully) doesn't break get_ifi_info() for every other OS
Revision 1.26 2005/04/08 21:43:59 ksekar
<rdar://problem/4083426> mDNSPosix (v98) retrieve interface list bug on AMD64 architecture
Submitted by Andrew de Quincey
Revision 1.25 2005/04/08 21:37:57 ksekar
<rdar://problem/3792767> get_ifi_info doesn't return IPv6 interfaces on Linux
Revision 1.24 2005/04/08 21:30:16 ksekar
<rdar://problem/4007457> Compiling problems with mDNSResponder-98 on Solaris/Sparc v9
Patch submitted by Bernd Kuhls
Revision 1.23 2004/12/01 04:25:05 cheshire
<rdar://problem/3872803> Darwin patches for Solaris and Suse
Provide daemon() for platforms that don't have it
Revision 1.22 2004/11/30 22:37:01 cheshire
Update copyright dates and add "Mode: C; tab-width: 4" headers
Revision 1.21 2004/11/08 22:13:59 rpantos
Create sockf6 lazily when v6 interface found.
Revision 1.20 2004/10/16 00:17:01 cheshire
<rdar://problem/3770558> Replace IP TTL 255 check with local subnet source address check
Revision 1.19 2004/07/20 01:47:36 rpantos
NOT_HAVE_SA_LEN applies to v6, too. And use more-portable s6_addr.
Revision 1.18 2004/07/08 21:30:21 rpantos
Revision 1.17 2004/06/25 00:26:27 rpantos
Changes to fix the Posix build on Solaris.
Revision 1.16 2004/03/20 05:37:09 cheshire
Fix contributed by Terry Lambert & Alfred Perlstein:
Don't use uint8_t -- it requires stdint.h, which doesn't exist on FreeBSD 4.x
Revision 1.15 2004/02/14 01:09:45 rpantos
Just use HAVE_IPV6 rather than defined(HAVE_IPV6).
Revision 1.14 2003/12/11 18:53:40 cheshire
Fix compiler warning reported by Paul Guyot
Revision 1.13 2003/12/08 20:47:02 rpantos
Add support for mDNSResponder on Linux.
Revision 1.12 2003/09/02 20:47:13 cheshire
Fix signed/unsigned warning
Revision 1.11 2003/08/12 19:56:26 cheshire
Update to APSL 2.0
Revision 1.10 2003/08/06 18:20:51 cheshire
Makefile cleanup
Revision 1.9 2003/07/14 18:11:54 cheshire
Fix stricter compiler warnings
Revision 1.8 2003/07/02 21:19:59 cheshire
<rdar://problem/3313413> Update copyright notices, etc., in source code comments
Revision 1.7 2003/03/20 21:10:31 cheshire
Fixes done at IETF 56 to make mDNSProxyResponderPosix run on Solaris
Revision 1.6 2003/03/13 03:46:21 cheshire
Fixes to make the code build on Linux
Revision 1.5 2003/02/07 03:02:02 cheshire
Submitted by: Mitsutaka Watanabe
The code saying "index += 1;" was effectively making up random interface index values.
The right way to find the correct interface index is if_nametoindex();
Revision 1.4 2002/12/23 22:13:31 jgraessl
Reviewed by: Stuart Cheshire
Initial IPv6 support for mDNSResponder.
Revision 1.3 2002/09/21 20:44:53 zarzycki
Added APSL info
Revision 1.2 2002/09/19 04:20:44 cheshire
Remove high-ascii characters that confuse some systems
Revision 1.1 2002/09/17 06:24:34 cheshire
First checkin
*/
#include "mDNSUNP.h"
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
/* Some weird platforms derived from 4.4BSD Lite (e.g. EFI) need the ALIGN(P)
macro, usually defined in <sys/param.h> or someplace like that, to make sure the
CMSG_NXTHDR macro is well-formed. On such platforms, the symbol NEED_ALIGN_MACRO
should be set to the name of the header to include to get the ALIGN(P) macro.
*/
#ifdef NEED_ALIGN_MACRO
#include NEED_ALIGN_MACRO
#endif
/* Solaris defined SIOCGIFCONF etc in <sys/sockio.h> but
other platforms don't even have that include file. So,
if we haven't yet got a definition, let's try to find
<sys/sockio.h>.
*/
#ifndef SIOCGIFCONF
#include <sys/sockio.h>
#endif
/* sockaddr_dl is only referenced if we're using IP_RECVIF,
so only include the header in that case.
*/
#ifdef IP_RECVIF
#include <net/if_dl.h>
#endif
#if defined(AF_INET6) && HAVE_IPV6 && !HAVE_LINUX
#include <net/if_var.h>
#include <netinet/in_var.h>
// NOTE: netinet/in_var.h implicitly includes netinet6/in6_var.h for us
#endif
#if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
#include <netdb.h>
#include <arpa/inet.h>
/* Converts a prefix length to IPv6 network mask */
void plen_to_mask(int plen, char *addr) {
int i;
int colons=7; /* Number of colons in IPv6 address */
int bits_in_block=16; /* Bits per IPv6 block */
for(i=0;i<=colons;i++) {
int block, ones=0xffff, ones_in_block;
if(plen>bits_in_block) ones_in_block=bits_in_block;
else ones_in_block=plen;
block = ones & (ones << (bits_in_block-ones_in_block));
i==0 ? sprintf(addr, "%x", block) : sprintf(addr, "%s:%x", addr, block);
plen -= ones_in_block;
}
}
/* Gets IPv6 interface information from the /proc filesystem in linux*/
struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases)
{
struct ifi_info *ifi, *ifihead, **ifipnext;
FILE *fp;
char addr[8][5];
int flags, myflags, index, plen, scope;
char ifname[8], lastname[IFNAMSIZ];
char addr6[32+7+1]; /* don't forget the seven ':' */
struct addrinfo hints, *res0;
struct sockaddr_in6 *sin6;
struct in6_addr *addrptr;
int err;
res0=NULL;
ifihead = NULL;
ifipnext = &ifihead;
lastname[0] = 0;
if ((fp = fopen(PROC_IFINET6_PATH, "r")) != NULL) {
while (fscanf(fp,
"%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %8s\n",
addr[0],addr[1],addr[2],addr[3],
addr[4],addr[5],addr[6],addr[7],
&index, &plen, &scope, &flags, ifname) != EOF) {
myflags = 0;
if (strncmp(lastname, ifname, IFNAMSIZ) == 0) {
if (doaliases == 0)
continue; /* already processed this interface */
myflags = IFI_ALIAS;
}
memcpy(lastname, ifname, IFNAMSIZ);
ifi = (struct ifi_info*)calloc(1, sizeof(struct ifi_info));
if (ifi == NULL) {
goto gotError;
}
*ifipnext = ifi; /* prev points to this new one */
ifipnext = &ifi->ifi_next; /* pointer to next one goes here */
sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
addr[0],addr[1],addr[2],addr[3],
addr[4],addr[5],addr[6],addr[7]);
/* Add address of the interface */
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET6;
hints.ai_flags = AI_NUMERICHOST;
err = getaddrinfo(addr6, NULL, &hints, &res0);
if (err) {
goto gotError;
}
ifi->ifi_addr = calloc(1, sizeof(struct sockaddr_in6));
if (ifi->ifi_addr == NULL) {
goto gotError;
}
memcpy(ifi->ifi_addr, res0->ai_addr, sizeof(struct sockaddr_in6));
/* Add netmask of the interface */
char ipv6addr[INET6_ADDRSTRLEN];
plen_to_mask(plen, ipv6addr);
ifi->ifi_netmask = calloc(1, sizeof(struct sockaddr_in6));
if (ifi->ifi_addr == NULL) {
goto gotError;
}
sin6=calloc(1, sizeof(struct sockaddr_in6));
addrptr=calloc(1, sizeof(struct in6_addr));
inet_pton(family, ipv6addr, addrptr);
sin6->sin6_family=family;
sin6->sin6_addr=*addrptr;
sin6->sin6_scope_id=scope;
memcpy(ifi->ifi_netmask, sin6, sizeof(struct sockaddr_in6));
free(sin6);
/* Add interface name */
memcpy(ifi->ifi_name, ifname, IFI_NAME);
/* Add interface index */
ifi->ifi_index = index;
/* If interface is in /proc then it is up*/
ifi->ifi_flags = IFF_UP;
freeaddrinfo(res0);
res0=NULL;
}
}
goto done;
gotError:
if (ifihead != NULL) {
free_ifi_info(ifihead);
ifihead = NULL;
}
if (res0 != NULL) {
freeaddrinfo(res0);
res0=NULL;
}
done:
return(ifihead); /* pointer to first structure in linked list */
}
#endif // defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
struct ifi_info *get_ifi_info(int family, int doaliases)
{
int junk;
struct ifi_info *ifi, *ifihead, **ifipnext;
int sockfd, sockf6, len, lastlen, flags, myflags;
#ifdef NOT_HAVE_IF_NAMETOINDEX
int index = 200;
#endif
char *ptr, *buf, lastname[IFNAMSIZ], *cptr;
struct ifconf ifc;
struct ifreq *ifr, ifrcopy;
struct sockaddr_in *sinptr;
#if defined(AF_INET6) && HAVE_IPV6
struct sockaddr_in6 *sinptr6;
#endif
#if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
if(family == AF_INET6) return get_ifi_info_linuxv6(family, doaliases);
#endif
sockfd = -1;
sockf6 = -1;
buf = NULL;
ifihead = NULL;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
goto gotError;
}
lastlen = 0;
len = 100 * sizeof(struct ifreq); /* initial buffer size guess */
for ( ; ; ) {
buf = (char*)malloc(len);
if (buf == NULL) {
goto gotError;
}
ifc.ifc_len = len;
ifc.ifc_buf = buf;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
if (errno != EINVAL || lastlen != 0) {
goto gotError;
}
} else {
if (ifc.ifc_len == lastlen)
break; /* success, len has not changed */
lastlen = ifc.ifc_len;
}
len += 10 * sizeof(struct ifreq); /* increment */
free(buf);
}
ifihead = NULL;
ifipnext = &ifihead;
lastname[0] = 0;
/* end get_ifi_info1 */
/* include get_ifi_info2 */
for (ptr = buf; ptr < buf + ifc.ifc_len; ) {
ifr = (struct ifreq *) ptr;
/* Advance to next one in buffer */
if (sizeof(struct ifreq) > sizeof(ifr->ifr_name) + GET_SA_LEN(ifr->ifr_addr))
ptr += sizeof(struct ifreq);
else
ptr += sizeof(ifr->ifr_name) + GET_SA_LEN(ifr->ifr_addr);
// fprintf(stderr, "intf %p name=%s AF=%d\n", index, ifr->ifr_name, ifr->ifr_addr.sa_family);
if (ifr->ifr_addr.sa_family != family)
continue; /* ignore if not desired address family */
myflags = 0;
if ( (cptr = strchr(ifr->ifr_name, ':')) != NULL)
*cptr = 0; /* replace colon will null */
if (strncmp(lastname, ifr->ifr_name, IFNAMSIZ) == 0) {
if (doaliases == 0)
continue; /* already processed this interface */
myflags = IFI_ALIAS;
}
memcpy(lastname, ifr->ifr_name, IFNAMSIZ);
ifrcopy = *ifr;
if (ioctl(sockfd, SIOCGIFFLAGS, &ifrcopy) < 0) {
goto gotError;
}
flags = ifrcopy.ifr_flags;
if ((flags & IFF_UP) == 0)
continue; /* ignore if interface not up */
ifi = (struct ifi_info*)calloc(1, sizeof(struct ifi_info));
if (ifi == NULL) {
goto gotError;
}
*ifipnext = ifi; /* prev points to this new one */
ifipnext = &ifi->ifi_next; /* pointer to next one goes here */
ifi->ifi_flags = flags; /* IFF_xxx values */
ifi->ifi_myflags = myflags; /* IFI_xxx values */
#ifndef NOT_HAVE_IF_NAMETOINDEX
ifi->ifi_index = if_nametoindex(ifr->ifr_name);
#else
ifrcopy = *ifr;
#ifdef SIOCGIFINDEX
if ( 0 >= ioctl(sockfd, SIOCGIFINDEX, &ifrcopy))
ifi->ifi_index = ifrcopy.ifr_index;
else
#endif
ifi->ifi_index = index++; /* SIOCGIFINDEX is broken on Solaris 2.5ish, so fake it */
#endif
memcpy(ifi->ifi_name, ifr->ifr_name, IFI_NAME);
ifi->ifi_name[IFI_NAME-1] = '\0';
/* end get_ifi_info2 */
/* include get_ifi_info3 */
switch (ifr->ifr_addr.sa_family) {
case AF_INET:
sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
if (ifi->ifi_addr == NULL) {
ifi->ifi_addr = (struct sockaddr*)calloc(1, sizeof(struct sockaddr_in));
if (ifi->ifi_addr == NULL) {
goto gotError;
}
memcpy(ifi->ifi_addr, sinptr, sizeof(struct sockaddr_in));
#ifdef SIOCGIFNETMASK
if (ioctl(sockfd, SIOCGIFNETMASK, &ifrcopy) < 0) goto gotError;
ifi->ifi_netmask = (struct sockaddr*)calloc(1, sizeof(struct sockaddr_in));
if (ifi->ifi_netmask == NULL) goto gotError;
sinptr = (struct sockaddr_in *) &ifrcopy.ifr_addr;
/* The BSD ioctls (including Mac OS X) stick some weird values in for sin_len and sin_family */
#ifndef NOT_HAVE_SA_LEN
sinptr->sin_len = sizeof(struct sockaddr_in);
#endif
sinptr->sin_family = AF_INET;
memcpy(ifi->ifi_netmask, sinptr, sizeof(struct sockaddr_in));
#endif
#ifdef SIOCGIFBRDADDR
if (flags & IFF_BROADCAST) {
if (ioctl(sockfd, SIOCGIFBRDADDR, &ifrcopy) < 0) {
goto gotError;
}
sinptr = (struct sockaddr_in *) &ifrcopy.ifr_broadaddr;
/* The BSD ioctls (including Mac OS X) stick some weird values in for sin_len and sin_family */
#ifndef NOT_HAVE_SA_LEN
sinptr->sin_len = sizeof( struct sockaddr_in );
#endif
sinptr->sin_family = AF_INET;
ifi->ifi_brdaddr = (struct sockaddr*)calloc(1, sizeof(struct sockaddr_in));
if (ifi->ifi_brdaddr == NULL) {
goto gotError;
}
memcpy(ifi->ifi_brdaddr, sinptr, sizeof(struct sockaddr_in));
}
#endif
#ifdef SIOCGIFDSTADDR
if (flags & IFF_POINTOPOINT) {
if (ioctl(sockfd, SIOCGIFDSTADDR, &ifrcopy) < 0) {
goto gotError;
}
sinptr = (struct sockaddr_in *) &ifrcopy.ifr_dstaddr;
/* The BSD ioctls (including Mac OS X) stick some weird values in for sin_len and sin_family */
#ifndef NOT_HAVE_SA_LEN
sinptr->sin_len = sizeof( struct sockaddr_in );
#endif
sinptr->sin_family = AF_INET;
ifi->ifi_dstaddr = (struct sockaddr*)calloc(1, sizeof(struct sockaddr_in));
if (ifi->ifi_dstaddr == NULL) {
goto gotError;
}
memcpy(ifi->ifi_dstaddr, sinptr, sizeof(struct sockaddr_in));
}
#endif
}
break;
#if defined(AF_INET6) && HAVE_IPV6
case AF_INET6:
sinptr6 = (struct sockaddr_in6 *) &ifr->ifr_addr;
if (ifi->ifi_addr == NULL) {
ifi->ifi_addr = calloc(1, sizeof(struct sockaddr_in6));
if (ifi->ifi_addr == NULL) {
goto gotError;
}
/* Some platforms (*BSD) inject the prefix in IPv6LL addresses */
/* We need to strip that out */
if (IN6_IS_ADDR_LINKLOCAL(&sinptr6->sin6_addr))
sinptr6->sin6_addr.s6_addr[2] = sinptr6->sin6_addr.s6_addr[3] = 0;
memcpy(ifi->ifi_addr, sinptr6, sizeof(struct sockaddr_in6));
#ifdef SIOCGIFNETMASK_IN6
{
struct in6_ifreq ifr6;
if (sockf6 == -1)
sockf6 = socket(AF_INET6, SOCK_DGRAM, 0);
bzero(&ifr6, sizeof(ifr6));
memcpy(&ifr6.ifr_name, &ifr->ifr_name, sizeof(ifr6.ifr_name ));
memcpy(&ifr6.ifr_ifru.ifru_addr, &ifr->ifr_addr, sizeof(ifr6.ifr_ifru.ifru_addr));
if (ioctl(sockf6, SIOCGIFNETMASK_IN6, &ifr6) < 0) goto gotError;
ifi->ifi_netmask = (struct sockaddr*)calloc(1, sizeof(struct sockaddr_in6));
if (ifi->ifi_netmask == NULL) goto gotError;
sinptr6 = (struct sockaddr_in6 *) &ifr6.ifr_ifru.ifru_addr;
memcpy(ifi->ifi_netmask, sinptr6, sizeof(struct sockaddr_in6));
}
#endif
}
break;
#endif
default:
break;
}
}
goto done;
gotError:
if (ifihead != NULL) {
free_ifi_info(ifihead);
ifihead = NULL;
}
done:
if (buf != NULL) {
free(buf);
}
if (sockfd != -1) {
junk = close(sockfd);
assert(junk == 0);
}
if (sockf6 != -1) {
junk = close(sockf6);
assert(junk == 0);
}
return(ifihead); /* pointer to first structure in linked list */
}
/* end get_ifi_info3 */
/* include free_ifi_info */
void
free_ifi_info(struct ifi_info *ifihead)
{
struct ifi_info *ifi, *ifinext;
for (ifi = ifihead; ifi != NULL; ifi = ifinext) {
if (ifi->ifi_addr != NULL)
free(ifi->ifi_addr);
if (ifi->ifi_brdaddr != NULL)
free(ifi->ifi_brdaddr);
if (ifi->ifi_dstaddr != NULL)
free(ifi->ifi_dstaddr);
ifinext = ifi->ifi_next; /* can't fetch ifi_next after free() */
free(ifi); /* the ifi_info{} itself */
}
}
/* end free_ifi_info */
ssize_t
recvfrom_flags(int fd, void *ptr, size_t nbytes, int *flagsp,
struct sockaddr *sa, socklen_t *salenptr, struct my_in_pktinfo *pktp, u_char *ttl)
{
struct msghdr msg;
struct iovec iov[1];
ssize_t n;
#ifdef CMSG_FIRSTHDR
struct cmsghdr *cmptr;
union {
struct cmsghdr cm;
char control[1024];
} control_un;
*ttl = 255; // If kernel fails to provide TTL data then assume the TTL was 255 as it should be
msg.msg_control = control_un.control;
msg.msg_controllen = sizeof(control_un.control);
msg.msg_flags = 0;
#else
memset(&msg, 0, sizeof(msg)); /* make certain msg_accrightslen = 0 */
#endif /* CMSG_FIRSTHDR */
msg.msg_name = (char *) sa;
msg.msg_namelen = *salenptr;
iov[0].iov_base = (char *)ptr;
iov[0].iov_len = nbytes;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
if ( (n = recvmsg(fd, &msg, *flagsp)) < 0)
return(n);
*salenptr = msg.msg_namelen; /* pass back results */
if (pktp) {
/* 0.0.0.0, i/f = -1 */
/* We set the interface to -1 so that the caller can
tell whether we returned a meaningful value or
just some default. Previously this code just
set the value to 0, but I'm concerned that 0
might be a valid interface value.
*/
memset(pktp, 0, sizeof(struct my_in_pktinfo));
pktp->ipi_ifindex = -1;
}
/* end recvfrom_flags1 */
/* include recvfrom_flags2 */
#ifndef CMSG_FIRSTHDR
#warning CMSG_FIRSTHDR not defined. Will not be able to determine destination address, received interface, etc.
*flagsp = 0; /* pass back results */
return(n);
#else
*flagsp = msg.msg_flags; /* pass back results */
if (msg.msg_controllen < (socklen_t)sizeof(struct cmsghdr) ||
(msg.msg_flags & MSG_CTRUNC) || pktp == NULL)
return(n);
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr != NULL;
cmptr = CMSG_NXTHDR(&msg, cmptr)) {
#ifdef IP_PKTINFO
#if in_pktinfo_definition_is_missing
struct in_pktinfo
{
int ipi_ifindex;
struct in_addr ipi_spec_dst;
struct in_addr ipi_addr;
};
#endif
if (cmptr->cmsg_level == IPPROTO_IP &&
cmptr->cmsg_type == IP_PKTINFO) {
struct in_pktinfo *tmp;
struct sockaddr_in *sin = (struct sockaddr_in*)&pktp->ipi_addr;
tmp = (struct in_pktinfo *) CMSG_DATA(cmptr);
sin->sin_family = AF_INET;
sin->sin_addr = tmp->ipi_addr;
sin->sin_port = 0;
pktp->ipi_ifindex = tmp->ipi_ifindex;
continue;
}
#endif
#ifdef IP_RECVDSTADDR
if (cmptr->cmsg_level == IPPROTO_IP &&
cmptr->cmsg_type == IP_RECVDSTADDR) {
struct sockaddr_in *sin = (struct sockaddr_in*)&pktp->ipi_addr;
sin->sin_family = AF_INET;
sin->sin_addr = *(struct in_addr*)CMSG_DATA(cmptr);
sin->sin_port = 0;
continue;
}
#endif
#ifdef IP_RECVIF
if (cmptr->cmsg_level == IPPROTO_IP &&
cmptr->cmsg_type == IP_RECVIF) {
struct sockaddr_dl *sdl = (struct sockaddr_dl *) CMSG_DATA(cmptr);
#ifndef HAVE_BROKEN_RECVIF_NAME
int nameLen = (sdl->sdl_nlen < IFI_NAME - 1) ? sdl->sdl_nlen : (IFI_NAME - 1);
strncpy(pktp->ipi_ifname, sdl->sdl_data, nameLen);
#endif
pktp->ipi_ifindex = sdl->sdl_index;
assert(pktp->ipi_ifname[IFI_NAME - 1] == 0);
// null terminated because of memset above
continue;
}
#endif
#ifdef IP_RECVTTL
if (cmptr->cmsg_level == IPPROTO_IP &&
cmptr->cmsg_type == IP_RECVTTL) {
*ttl = *(u_char*)CMSG_DATA(cmptr);
continue;
}
else if (cmptr->cmsg_level == IPPROTO_IP &&
cmptr->cmsg_type == IP_TTL) { // some implementations seem to send IP_TTL instead of IP_RECVTTL
*ttl = *(int*)CMSG_DATA(cmptr);
continue;
}
#endif
#if defined(IPV6_PKTINFO) && HAVE_IPV6
if (cmptr->cmsg_level == IPPROTO_IPV6 &&
cmptr->cmsg_type == IPV6_PKTINFO) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)&pktp->ipi_addr;
struct in6_pktinfo *ip6_info = (struct in6_pktinfo*)CMSG_DATA(cmptr);
sin6->sin6_family = AF_INET6;
#ifndef NOT_HAVE_SA_LEN
sin6->sin6_len = sizeof(*sin6);
#endif
sin6->sin6_addr = ip6_info->ipi6_addr;
sin6->sin6_flowinfo = 0;
sin6->sin6_scope_id = 0;
sin6->sin6_port = 0;
pktp->ipi_ifindex = ip6_info->ipi6_ifindex;
continue;
}
#endif
#if defined(IPV6_HOPLIMIT) && HAVE_IPV6
if (cmptr->cmsg_level == IPPROTO_IPV6 &&
cmptr->cmsg_type == IPV6_HOPLIMIT) {
*ttl = *(int*)CMSG_DATA(cmptr);
continue;
}
#endif
assert(0); // unknown ancillary data
}
return(n);
#endif /* CMSG_FIRSTHDR */
}
// **********************************************************************************************
// daemonize the process. Adapted from "Unix Network Programming" vol 1 by Stevens, section 12.4.
// Returns 0 on success, -1 on failure.
#ifdef NOT_HAVE_DAEMON
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/signal.h>
int daemon(int nochdir, int noclose)
{
switch (fork())
{
case -1: return (-1); // Fork failed
case 0: break; // Child -- continue
default: _exit(0); // Parent -- exit
}
if (setsid() == -1) return(-1);
signal(SIGHUP, SIG_IGN);
switch (fork()) // Fork again, primarily for reasons of Unix trivia
{
case -1: return (-1); // Fork failed
case 0: break; // Child -- continue
default: _exit(0); // Parent -- exit
}
if (!nochdir) (void)chdir("/");
umask(0);
if (!noclose)
{
int fd = open("/dev/null", O_RDWR, 0);
if (fd != -1)
{
// Avoid unnecessarily duplicating a file descriptor to itself
if (fd != STDIN_FILENO) (void)dup2(fd, STDIN_FILENO);
if (fd != STDOUT_FILENO) (void)dup2(fd, STDOUT_FILENO);
if (fd != STDERR_FILENO) (void)dup2(fd, STDERR_FILENO);
if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO)
(void)close (fd);
}
}
return (0);
}
#endif /* NOT_HAVE_DAEMON */

View File

@ -1,187 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Change History (most recent first):
$Log: mDNSUNP.h,v $
Revision 1.19 2006/08/14 23:24:47 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.18 2005/04/08 21:37:57 ksekar
<rdar://problem/3792767> get_ifi_info doesn't return IPv6 interfaces on Linux
Revision 1.17 2004/12/17 19:32:43 cheshire
Add missing semicolon
Revision 1.16 2004/12/01 04:25:05 cheshire
<rdar://problem/3872803> Darwin patches for Solaris and Suse
Provide daemon() for platforms that don't have it
Revision 1.15 2004/11/30 22:37:01 cheshire
Update copyright dates and add "Mode: C; tab-width: 4" headers
Revision 1.14 2004/10/16 00:17:01 cheshire
<rdar://problem/3770558> Replace IP TTL 255 check with local subnet source address check
Revision 1.13 2004/03/20 05:37:09 cheshire
Fix contributed by Terry Lambert & Alfred Perlstein:
Don't use uint8_t -- it requires stdint.h, which doesn't exist on FreeBSD 4.x
Revision 1.12 2004/01/28 21:12:15 cheshire
Reconcile mDNSIPv6Support & HAVE_IPV6 into a single flag (HAVE_IPV6)
Revision 1.11 2003/12/13 05:43:09 bradley
Fixed non-sa_len and non-IPv6 version of GET_SA_LEN macro to cast as sockaddr to access
sa_family so it works with any sockaddr-compatible address structure (e.g. sockaddr_storage).
Revision 1.10 2003/12/11 03:03:51 rpantos
Clean up mDNSPosix so that it builds on OS X again.
Revision 1.9 2003/12/08 20:47:02 rpantos
Add support for mDNSResponder on Linux.
Revision 1.8 2003/08/12 19:56:26 cheshire
Update to APSL 2.0
Revision 1.7 2003/08/06 18:20:51 cheshire
Makefile cleanup
Revision 1.6 2003/07/02 21:19:59 cheshire
<rdar://problem/3313413> Update copyright notices, etc., in source code comments
Revision 1.5 2003/03/13 03:46:21 cheshire
Fixes to make the code build on Linux
Revision 1.4 2002/12/23 22:13:32 jgraessl
Reviewed by: Stuart Cheshire
Initial IPv6 support for mDNSResponder.
Revision 1.3 2002/09/21 20:44:53 zarzycki
Added APSL info
Revision 1.2 2002/09/19 04:20:44 cheshire
Remove high-ascii characters that confuse some systems
Revision 1.1 2002/09/17 06:24:35 cheshire
First checkin
*/
#ifndef __mDNSUNP_h
#define __mDNSUNP_h
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#ifdef HAVE_LINUX
#include <linux/socket.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef NOT_HAVE_SOCKLEN_T
typedef unsigned int socklen_t;
#endif
#if !defined(_SS_MAXSIZE)
#if HAVE_IPV6
#define sockaddr_storage sockaddr_in6
#else
#define sockaddr_storage sockaddr
#endif // HAVE_IPV6
#endif // !defined(_SS_MAXSIZE)
#ifndef NOT_HAVE_SA_LEN
#define GET_SA_LEN(X) (sizeof(struct sockaddr) > ((struct sockaddr*)&(X))->sa_len ? \
sizeof(struct sockaddr) : ((struct sockaddr*)&(X))->sa_len )
#elif HAVE_IPV6
#define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
((struct sockaddr*)&(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
#else
#define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr))
#endif
#define IFI_NAME 16 /* same as IFNAMSIZ in <net/if.h> */
#define IFI_HADDR 8 /* allow for 64-bit EUI-64 in future */
// Renamed from my_in_pktinfo because in_pktinfo is used by Linux.
struct my_in_pktinfo {
struct sockaddr_storage ipi_addr;
int ipi_ifindex; /* received interface index */
char ipi_ifname[IFI_NAME]; /* received interface name */
};
/* From the text (Stevens, section 20.2): */
/* 'As an example of recvmsg we will write a function named recvfrom_flags that */
/* is similar to recvfrom but also returns: */
/* 1. the returned msg_flags value, */
/* 2. the destination addres of the received datagram (from the IP_RECVDSTADDR socket option, and */
/* 3. the index of the interface on which the datagram was received (the IP_RECVIF socket option).' */
extern ssize_t recvfrom_flags(int fd, void *ptr, size_t nbytes, int *flagsp,
struct sockaddr *sa, socklen_t *salenptr, struct my_in_pktinfo *pktp, u_char *ttl);
struct ifi_info {
char ifi_name[IFI_NAME]; /* interface name, null terminated */
u_char ifi_haddr[IFI_HADDR]; /* hardware address */
u_short ifi_hlen; /* #bytes in hardware address: 0, 6, 8 */
short ifi_flags; /* IFF_xxx constants from <net/if.h> */
short ifi_myflags; /* our own IFI_xxx flags */
int ifi_index; /* interface index */
struct sockaddr *ifi_addr; /* primary address */
struct sockaddr *ifi_netmask;
struct sockaddr *ifi_brdaddr;/* broadcast address */
struct sockaddr *ifi_dstaddr;/* destination address */
struct ifi_info *ifi_next; /* next of these structures */
};
#if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
#define PROC_IFINET6_PATH "/proc/net/if_inet6"
extern struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases);
#endif
#if defined(AF_INET6) && HAVE_IPV6
#define INET6_ADDRSTRLEN 46 /*Maximum length of IPv6 address */
#endif
#define IFI_ALIAS 1 /* ifi_addr is an alias */
/* From the text (Stevens, section 16.6): */
/* 'Since many programs need to know all the interfaces on a system, we will develop a */
/* function of our own named get_ifi_info that returns a linked list of structures, one */
/* for each interface that is currently "up."' */
extern struct ifi_info *get_ifi_info(int family, int doaliases);
/* 'The free_ifi_info function, which takes a pointer that was */
/* returned by get_ifi_info and frees all the dynamic memory.' */
extern void free_ifi_info(struct ifi_info *);
#ifdef NOT_HAVE_DAEMON
extern int daemon(int nochdir, int noclose);
#endif
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,190 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Change History (most recent first):
$Log: uDNS.h,v $
Revision 1.32.2.1 2006/08/29 06:24:23 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.32 2005/07/29 19:46:10 ksekar
<rdar://problem/4191860> reduce polling period on failed LLQs to 15 minutes
Revision 1.31 2005/03/31 02:19:56 cheshire
<rdar://problem/4021486> Fix build warnings
Reviewed by: Scott Herscher
Revision 1.30 2005/03/04 03:00:03 ksekar
<rdar://problem/4026546> Retransmissions happen too early, causing registrations to conflict with themselves
Revision 1.29 2005/01/11 22:50:53 ksekar
Fixed constant naming (was using kLLQ_DefLease for update leases)
Revision 1.28 2004/12/22 00:13:49 ksekar
<rdar://problem/3873993> Change version, port, and polling interval for LLQ
Revision 1.27 2004/11/23 04:06:50 cheshire
Get rid of floating point constant -- in a small embedded device, bringing in all
the floating point libraries just to halve an integer value is a bit too heavyweight.
Revision 1.26 2004/11/22 17:49:15 ksekar
Changed INIT_REFRESH from fraction to decimal
Revision 1.25 2004/11/22 17:16:20 ksekar
<rdar://problem/3854298> Unicast services don't disappear when you disable all networking
Revision 1.24 2004/11/19 04:24:08 ksekar
<rdar://problem/3682609> Security: Enforce a "window" on one-shot wide-area queries
Revision 1.23 2004/11/18 18:04:21 ksekar
Add INIT_REFRESH constant
Revision 1.22 2004/11/15 20:09:24 ksekar
<rdar://problem/3719050> Wide Area support for Add/Remove record
Revision 1.21 2004/11/11 20:14:55 ksekar
<rdar://problem/3719574> Wide-Area registrations not deregistered on sleep
Revision 1.20 2004/10/16 00:16:59 cheshire
<rdar://problem/3770558> Replace IP TTL 255 check with local subnet source address check
Revision 1.19 2004/09/17 01:08:49 cheshire
Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
declared in that file are ONLY appropriate to single-address-space embedded applications.
For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
Revision 1.18 2004/09/03 19:23:05 ksekar
<rdar://problem/3788460>: Need retransmission mechanism for wide-area service registrations
Revision 1.17 2004/09/01 03:59:29 ksekar
<rdar://problem/3783453>: Conditionally compile out uDNS code on Windows
Revision 1.16 2004/08/25 00:37:27 ksekar
<rdar://problem/3774635>: Cleanup DynDNS hostname registration code
Revision 1.15 2004/07/30 17:40:06 ksekar
<rdar://problem/3739115>: TXT Record updates not available for wide-area services
Revision 1.14 2004/07/29 19:27:15 ksekar
NATPMP Support - minor fixes and cleanup
Revision 1.13 2004/07/29 02:03:35 ksekar
Delete unused #define and structure field
Revision 1.12 2004/07/26 22:49:30 ksekar
<rdar://problem/3651409>: Feature #9516: Need support for NATPMP in client
Revision 1.11 2004/06/17 01:13:11 ksekar
<rdar://problem/3696616>: polling interval too short
Revision 1.10 2004/06/11 05:45:03 ksekar
<rdar://problem/3682397>: Change SRV names for LLQ/Update port lookups
Revision 1.9 2004/06/01 23:46:50 ksekar
<rdar://problem/3675149>: DynDNS: dynamically look up LLQ/Update ports
Revision 1.8 2004/05/28 23:42:37 ksekar
<rdar://problem/3258021>: Feature: DNS server->client notification on record changes (#7805)
Revision 1.7 2004/05/18 23:51:25 cheshire
Tidy up all checkin comments to use consistent "<rdar://problem/xxxxxxx>" format for bug numbers
Revision 1.6 2004/03/13 01:57:33 ksekar
<rdar://problem/3192546>: DynDNS: Dynamic update of service records
Revision 1.5 2004/02/21 08:56:58 bradley
Wrap prototypes with extern "C" for C++ builds.
Revision 1.4 2004/02/06 23:04:19 ksekar
Basic Dynamic Update support via mDNS_Register (dissabled via
UNICAST_REGISTRATION #define)
Revision 1.3 2004/01/24 03:38:27 cheshire
Fix minor syntactic error: Headers should use "extern" declarations, not "mDNSexport"
Revision 1.2 2004/01/23 23:23:15 ksekar
Added TCP support for truncated unicast messages.
Revision 1.1 2003/12/13 03:05:27 ksekar
<rdar://problem/3192548>: DynDNS: Unicast query of service records
*/
#ifndef __UDNS_H_
#define __UDNS_H_
#include "mDNSEmbeddedAPI.h"
#include "DNSCommon.h"
#ifdef __cplusplus
extern "C" {
#endif
#define RESTART_GOODBYE_DELAY (6 * mDNSPlatformOneSecond) // delay after restarting LLQ before nuking previous known answers (avoids flutter if we restart before we have networking up)
#define MIN_UCAST_PERIODIC_EXEC (5 * mDNSPlatformOneSecond)
#define INIT_UCAST_POLL_INTERVAL (3 * mDNSPlatformOneSecond) // this interval is used after send failures on network transitions
// which typically heal quickly, so we start agressively and exponentially back off
#define MAX_UCAST_POLL_INTERVAL (60 * 60 * mDNSPlatformOneSecond)
#define LLQ_POLL_INTERVAL (15 * 60 * mDNSPlatformOneSecond) // Polling interval for zones w/ an advertised LLQ port (ie not static zones) if LLQ fails due to NAT, etc.
#define RESPONSE_WINDOW (60 * mDNSPlatformOneSecond) // require server responses within one minute of request
#define UPDATE_PORT_NAME "_dns-update._udp."
#define LLQ_PORT_NAME "_dns-llq._udp"
#define DEFAULT_UPDATE_LEASE 7200
// Entry points into unicast-specific routines
extern mStatus uDNS_StartQuery(mDNS *const m, DNSQuestion *const question);
extern mDNSBool uDNS_IsActiveQuery(DNSQuestion *const question, uDNS_GlobalInfo *u); // returns true if OK to call StopQuery
extern mStatus uDNS_StopQuery(mDNS *const m, DNSQuestion *const question);
extern void uDNS_Init(mDNS *const m);
extern void uDNS_Sleep(mDNS *const m);
extern void uDNS_Wake(mDNS *const m);
#define uDNS_Close uDNS_Sleep
// uDNS_UpdateRecord
// following fields must be set, and the update validated, upon entry.
// rr->NewRData
// rr->newrdlength
// rr->UpdateCallback
extern mStatus uDNS_AddRecordToService(mDNS *const m, ServiceRecordSet *sr, ExtraResourceRecord *extra);
extern mStatus uDNS_UpdateRecord(mDNS *m, AuthRecord *rr);
extern mStatus uDNS_RegisterRecord(mDNS *const m, AuthRecord *const rr);
extern mStatus uDNS_DeregisterRecord(mDNS *const m, AuthRecord *const rr);
extern mStatus uDNS_RegisterService(mDNS *const m, ServiceRecordSet *srs);
extern mStatus uDNS_DeregisterService(mDNS *const m, ServiceRecordSet *srs);
// integer fields of msg header must be in HOST byte order before calling this routine
extern void uDNS_ReceiveMsg(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
const mDNSAddr *const srcaddr, const mDNSIPPort srcport, const mDNSAddr *const dstaddr,
const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID);
extern void uDNS_ReceiveNATMap(mDNS *m, mDNSu8 *pkt, mDNSu16 len);
// returns time of next scheduled event
extern void uDNS_Execute(mDNS *const m);
#ifdef __cplusplus
}
#endif
#endif // __UDNS_H_

View File

@ -1,523 +0,0 @@
/* -*- Mode: C; tab-width: 4 -*-
* $Id$
*
* Do the zeroconf/mdns/rendezvous (tm) thing. This is a hacked version
* of Apple's Responder.c from the Rendezvous (tm) POSIX implementation
*
* Copyright (C) 2003 Ron Pedde (ron@pedde.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
*
* Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Change History (most recent first):
$Log: Responder.c,v $
Revision 1.33 2007/04/16 20:49:39 cheshire
Fix compile errors for mDNSPosix build
Revision 1.32 2006/08/14 23:24:46 cheshire
Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
Revision 1.31 2006/06/12 18:22:42 cheshire
<4580067> mDNSResponder building warnings under Red Hat 64-bit (LP64) Linux
Revision 1.30 2005/10/26 22:21:16 cheshire
<4149841> Potential buffer overflow in mDNSResponderPosix
Revision 1.29 2005/03/04 21:35:33 cheshire
<4037201> Services.txt file not parsed properly when it contains more than one service
Revision 1.28 2005/01/11 01:55:26 ksekar
Fix compile errors in Posix debug build
Revision 1.27 2004/12/01 04:28:43 cheshire
<3872803> Darwin patches for Solaris and Suse
Use version of daemon() provided in mDNSUNP.c instead of local copy
Revision 1.26 2004/11/30 22:37:01 cheshire
Update copyright dates and add "Mode: C; tab-width: 4" headers
Revision 1.25 2004/11/11 02:00:51 cheshire
Minor fixes to getopt, error message
Revision 1.24 2004/11/09 19:32:10 rpantos
Suggestion from Ademar de Souza Reis Jr. to allow comments in services file
Revision 1.23 2004/09/17 01:08:54 cheshire
Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
declared in that file are ONLY appropriate to single-address-space embedded applications.
For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
Revision 1.22 2004/09/16 01:58:22 cheshire
Fix compiler warnings
Revision 1.21 2004/06/15 03:48:07 cheshire
Update mDNSResponderPosix to take multiple name=val arguments in a sane way
Revision 1.20 2004/05/18 23:51:26 cheshire
Tidy up all checkin comments to use consistent "<xxxxxxx>" format for bug numbers
Revision 1.19 2004/03/12 08:03:14 cheshire
Update comments
Revision 1.18 2004/01/25 00:00:55 cheshire
Change to use mDNSOpaque16fromIntVal() instead of shifting and masking
Revision 1.17 2003/12/11 19:11:55 cheshire
Fix compiler warning
Revision 1.16 2003/08/14 02:19:55 cheshire
<3375491> Split generic ResourceRecord type into two separate types: AuthRecord and CacheRecord
Revision 1.15 2003/08/12 19:56:26 cheshire
Update to APSL 2.0
Revision 1.14 2003/08/06 18:20:51 cheshire
Makefile cleanup
Revision 1.13 2003/07/23 00:00:04 cheshire
Add comments
Revision 1.12 2003/07/15 01:55:16 cheshire
<3315777> Need to implement service registration with subtypes
Revision 1.11 2003/07/14 18:11:54 cheshire
Fix stricter compiler warnings
Revision 1.10 2003/07/10 20:27:31 cheshire
<3318717> mDNSResponder Posix version is missing a 'b' in the getopt option string
Revision 1.9 2003/07/02 21:19:59 cheshire
<3313413> Update copyright notices, etc., in source code comments
Revision 1.8 2003/06/18 05:48:41 cheshire
Fix warnings
Revision 1.7 2003/05/06 00:00:50 cheshire
<3248914> Rationalize naming of domainname manipulation functions
Revision 1.6 2003/03/08 00:35:56 cheshire
Switched to using new "mDNS_Execute" model (see "mDNSCore/Implementer Notes.txt")
Revision 1.5 2003/02/20 06:48:36 cheshire
<3169535> Xserve RAID needs to do interface-specific registrations
Reviewed by: Josh Graessley, Bob Bradley
Revision 1.4 2003/01/28 03:07:46 cheshire
Add extra parameter to mDNS_RenameAndReregisterService(),
and add support for specifying a domain other than dot-local.
Revision 1.3 2002/09/21 20:44:53 zarzycki
Added APSL info
Revision 1.2 2002/09/19 04:20:44 cheshire
Remove high-ascii characters that confuse some systems
Revision 1.1 2002/09/17 06:24:35 cheshire
First checkin
*/
#include "mDNSEmbeddedAPI.h"// Defines the interface to the client layer above
#include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
#include <assert.h>
#include <stdio.h> // For printf()
#include <stdlib.h> // For exit() etc.
#include <string.h> // For strlen() etc.
#include <unistd.h> // For select()
#include <errno.h> // For errno, EINTR
#include <signal.h>
#include <fcntl.h>
#include "daapd.h"
#include "err.h"
#include "os-unix.h"
#include "rend.h"
#include "rend-unix.h"
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark ***** Globals
#endif
static mDNS mDNSStorage; // mDNS core uses this to store its globals
static mDNS_PlatformSupport PlatformStorage; // Stores this platform's globals
mDNSexport const char ProgramName[] = "mDNSResponderPosix";
static volatile mDNSBool gStopNow;
// We support 4 signals. (2, now -- rp)
//
// o SIGINT causes an orderly shutdown of the program.
// o SIGQUIT causes a somewhat orderly shutdown (direct but dangerous)
//
// There are fatal race conditions in our signal handling, but there's not much
// we can do about them while remaining within the Posix space. Specifically,
// if a signal arrives after we test the globals its sets but before we call
// select, the signal will be dropped. The user will have to send the signal
// again. Unfortunately, Posix does not have a "sigselect" to atomically
// modify the signal mask and start a select.
static void HandleSigInt(int sigraised)
// A handler for SIGINT that causes us to break out of the
// main event loop when the user types ^C. This has the
// effect of quitting the program.
{
assert(sigraised == SIGINT);
if (gMDNSPlatformPosixVerboseLevel > 0) {
fprintf(stderr, "\nSIGINT\n");
}
gStopNow = mDNStrue;
}
static void HandleSigQuit(int sigraised)
// If we get a SIGQUIT the user is desperate and we
// just call mDNS_Close directly. This is definitely
// not safe (because it could reenter mDNS), but
// we presume that the user has already tried the safe
// alternatives.
{
assert(sigraised == SIGQUIT);
if (gMDNSPlatformPosixVerboseLevel > 0) {
fprintf(stderr, "\nSIGQUIT\n");
}
mDNS_Close(&mDNSStorage);
exit(0);
}
static const char kDefaultServiceType[] = "_http._tcp.";
static const char kDefaultServiceDomain[] = "local.";
enum {
kDefaultPortNumber = 80
};
typedef struct PosixService PosixService;
struct PosixService {
ServiceRecordSet coreServ;
PosixService *next;
int serviceID;
};
static PosixService *gServiceList = NULL;
static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegistration, mStatus status)
// mDNS core calls this routine to tell us about the status of
// our registration. The appropriate action to take depends
// entirely on the value of status.
{
switch (status) {
case mStatus_NoError:
DPRINTF(E_DBG,L_REND,"Callback: %##s Name Registered\n", thisRegistration->RR_SRV.resrec.name->c);
// Do nothing; our name was successfully registered. We may
// get more call backs in the future.
break;
case mStatus_NameConflict:
DPRINTF(E_DBG,L_REND,"Callback: %##s Name Conflict\n", thisRegistration->RR_SRV.resrec.name->c);
// In the event of a conflict, this sample RegistrationCallback
// just calls mDNS_RenameAndReregisterService to automatically
// pick a new unique name for the service. For a device such as a
// printer, this may be appropriate. For a device with a user
// interface, and a screen, and a keyboard, the appropriate response
// may be to prompt the user and ask them to choose a new name for
// the service.
//
// Also, what do we do if mDNS_RenameAndReregisterService returns an
// error. Right now I have no place to send that error to.
status = mDNS_RenameAndReregisterService(m, thisRegistration, mDNSNULL);
assert(status == mStatus_NoError);
break;
case mStatus_MemFree:
DPRINTF(E_DBG,L_REND,"Callback: %##s Memory Free\n", thisRegistration->RR_SRV.resrec.name->c);
// When debugging is enabled, make sure that thisRegistration
// is not on our gServiceList.
#if !defined(NDEBUG)
{
PosixService *cursor;
cursor = gServiceList;
while (cursor != NULL) {
assert(&cursor->coreServ != thisRegistration);
cursor = cursor->next;
}
}
#endif
free(thisRegistration);
break;
default:
DPRINTF(E_DBG,L_REND,"Callback: %##s Unknown Status %ld\n", thisRegistration->RR_SRV.resrec.name->c, status);
break;
}
}
static int gServiceID = 0;
static mStatus RegisterOneService(const char * richTextName,
const char * serviceType,
const char * serviceDomain,
const mDNSu8 text[],
mDNSu16 textLen,
long portNumber,
mDNSInterfaceID id)
{
mStatus status;
PosixService * thisServ;
domainlabel name;
domainname type;
domainname domain;
status = mStatus_NoError;
thisServ = (PosixService *) malloc(sizeof(*thisServ));
if (thisServ == NULL) {
status = mStatus_NoMemoryErr;
}
if (status == mStatus_NoError) {
MakeDomainLabelFromLiteralString(&name, richTextName);
MakeDomainNameFromDNSNameString(&type, serviceType);
MakeDomainNameFromDNSNameString(&domain, serviceDomain);
status = mDNS_RegisterService(&mDNSStorage, &thisServ->coreServ,
&name, &type, &domain, // Name, type, domain
NULL, mDNSOpaque16fromIntVal(portNumber),
text, textLen, // TXT data, length
NULL, 0, // Subtypes
id, // Interface ID
RegistrationCallback, thisServ); // Callback and context
}
if (status == mStatus_NoError) {
thisServ->serviceID = gServiceID;
gServiceID += 1;
thisServ->next = gServiceList;
gServiceList = thisServ;
DPRINTF(E_DBG,L_REND,
"Registered service %d, name '%s', type '%s', port %ld\n",
thisServ->serviceID,
richTextName,
serviceType,
portNumber);
} else {
if (thisServ != NULL) {
free(thisServ);
}
}
return status;
}
static void DeregisterOurServices(void)
{
PosixService *thisServ;
int thisServID;
while (gServiceList != NULL) {
thisServ = gServiceList;
gServiceList = thisServ->next;
thisServID = thisServ->serviceID;
mDNS_DeregisterService(&mDNSStorage, &thisServ->coreServ);
DPRINTF(E_DBG,L_REND,
"Deregistered service %d\n",
thisServ->serviceID);
}
}
mDNSInterfaceID rend_get_interface_id(char *iface) {
PosixNetworkInterface *pni;
if(!iface)
return mDNSInterface_Any;
if(!strlen(iface))
return mDNSInterface_Any;
DPRINTF(E_LOG,L_REND,"Searching for interface %s\n",iface);
pni=(PosixNetworkInterface*)mDNSStorage.HostInterfaces;
while(pni) {
DPRINTF(E_INF,L_REND,"Found interface %s, index %d\n",pni->intfName,
pni->index);
if(strcasecmp(pni->intfName,iface) == 0) {
DPRINTF(E_INF,L_REND,"Found interface id: %d\n",pni->coreIntf.InterfaceID);
return pni->coreIntf.InterfaceID;
}
pni=(PosixNetworkInterface*)(pni->coreIntf.next);
}
DPRINTF(E_INF,L_REND,"Could not find interface.\n");
return mDNSInterface_Any;
}
/*
* rend_callback
*
* This is borrowed from the OSX rend client
*/
void rend_callback(void) {
REND_MESSAGE msg;
int result;
int err;
mDNSInterfaceID id;
DPRINTF(E_DBG,L_REND,"Processing rendezvous message\n");
/* here, we've seen the message, now we have to process it */
if((result=rend_read_message(&msg)) != sizeof(msg)) {
err=errno;
DPRINTF(E_FATAL,L_REND,"Rendezvous socket closed (daap server crashed?) Aborting.\n");
gStopNow=mDNStrue;
return;
}
switch(msg.cmd) {
case REND_MSG_TYPE_REGISTER:
id=rend_get_interface_id(msg.iface);
DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.name,msg.type,msg.port);
RegisterOneService(msg.name,msg.type,"local.",msg.txt,strlen(msg.txt),
msg.port,id);
rend_send_response(0); /* success */
break;
case REND_MSG_TYPE_UNREGISTER:
rend_send_response(1); /* error */
break;
case REND_MSG_TYPE_STOP:
DPRINTF(E_INF,L_REND,"Stopping mDNS\n");
gStopNow = mDNStrue;
rend_send_response(0);
break;
case REND_MSG_TYPE_STATUS:
rend_send_response(1);
break;
default:
break;
}
}
int rend_private_init(char *user) {
mStatus status;
mDNSBool result;
status = mDNS_Init(&mDNSStorage, &PlatformStorage,
mDNS_Init_NoCache, mDNS_Init_ZeroCacheSize,
mDNS_Init_AdvertiseLocalAddresses,
mDNS_Init_NoInitCallback, mDNS_Init_NoInitCallbackContext);
if (status != mStatus_NoError) {
DPRINTF(E_FATAL,L_REND,"mDNS Error %d\n",status);
return(-1);
}
if(os_drop_privs(user))
return -1;
signal(SIGINT, HandleSigInt); // SIGINT is what you get for a Ctrl-C
signal(SIGQUIT, HandleSigQuit); // SIGQUIT is what you get for a Ctrl-\ (indeed)
signal(SIGHUP, SIG_IGN); // SIGHUP might happen from a request to reload the daap server
while (!gStopNow) {
int nfds = 1;
fd_set readfds;
struct timeval timeout;
int result;
// 1. Set up the fd_set as usual here.
// This example client has no file descriptors of its own,
// but a real application would call FD_SET to add them to the set here
FD_ZERO(&readfds);
FD_SET(rend_pipe_to[RD_SIDE],&readfds);
// 2. Set up the timeout.
// This example client has no other work it needs to be doing,
// so we set an effectively infinite timeout
timeout.tv_sec = 0x3FFFFFFF;
timeout.tv_usec = 0;
// 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
mDNSPosixGetFDSet(&mDNSStorage, &nfds, &readfds, &timeout);
// 4. Call select as normal
DPRINTF(E_SPAM,L_REND,"select(%d, %d.%06d)\n", nfds,
timeout.tv_sec, timeout.tv_usec);
result = select(nfds, &readfds, NULL, NULL, &timeout);
if (result < 0) {
if (errno != EINTR) gStopNow = mDNStrue;
DPRINTF(E_WARN,L_REND,"select() returned %d errno %d\n", result, errno);
} else {
// 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
mDNSPosixProcessFDSet(&mDNSStorage, &readfds);
// 6. This example client has no other work it needs to be doing,
// but a real client would do its work here
// ... (do work) ...
if(FD_ISSET(rend_pipe_to[RD_SIDE],&readfds)) {
rend_callback();
}
}
}
DPRINTF(E_DBG,L_REND,"Exiting\n");
DeregisterOurServices();
mDNS_Close(&mDNSStorage);
if (status == mStatus_NoError) {
result = 0;
} else {
result = 2;
}
DPRINTF(E_DBG,L_REND, "Finished with status %ld, result %d\n",
status, result);
exit(result);
}