mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-24 22:25:56 -05:00
Update Apple's mDNS to 107.6, the Apache/BSD licenced version, to remove aspl taint. This is high in autoconf hackery, though
This commit is contained in:
parent
751afbf285
commit
363210ebcc
11
configure.in
11
configure.in
@ -2,7 +2,6 @@ dnl $Id$
|
||||
dnl
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(config.h.in)
|
||||
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AM_INIT_AUTOMAKE(mt-daapd,0.2.1.1)
|
||||
|
||||
@ -160,14 +159,16 @@ dnl
|
||||
|
||||
case $host in
|
||||
*solaris*)
|
||||
CPPFLAGS="$CPPFLAGS -DNOT_HAVE_SA_LEN -D_XPG4_2"
|
||||
CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__ -DHAVE_BROKEN_RECVIF_NAME"
|
||||
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";;
|
||||
*freebsd*)
|
||||
CPPFLAGS="$CPPFLAGS -DFREEBSD";;
|
||||
*linux*)
|
||||
CPPFLAGS="$CPPFLAGS -DNOT_HAVE_SA_LEN";;
|
||||
CPPFLAGS="$CPPFLAGS -DNOT_HAVE_SA_LEN -DUSES_NETLINK -DHAVE_LINUX";;
|
||||
*openbsd*)
|
||||
CPPFLAGS="$CPPFLAGS -DHAVE_BROKEN_RECVDSTADDR";;
|
||||
*darwin*)
|
||||
@ -436,4 +437,4 @@ AC_CHECK_LIB(socket,socket,V_NETLIBS="-lsocket $V_NETLIBS",,)
|
||||
|
||||
AC_SUBST(V_NETLIBS)
|
||||
|
||||
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)
|
||||
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)
|
||||
|
@ -3,7 +3,7 @@ rm -f config.cache
|
||||
rm -f config.status
|
||||
#rm -f acconfig.h
|
||||
libtoolize --force
|
||||
aclocal
|
||||
aclocal -I m4
|
||||
autoconf
|
||||
autoheader
|
||||
automake -a
|
||||
|
@ -1,13 +1,17 @@
|
||||
# $Id$
|
||||
#
|
||||
SUBDIRS=plugins
|
||||
SUBDIRS = plugins
|
||||
|
||||
sbin_PROGRAMS = mt-daapd
|
||||
bin_PROGRAMS = wavstreamer
|
||||
|
||||
LDADD=
|
||||
|
||||
if COND_REND_POSIX
|
||||
PRENDSRC=mDNS.c mDNSClientAPI.h mDNSDebug.h mDNSPosix.c mDNSUNP.c \
|
||||
rend-posix.c mDNSPlatformFunctions.h rend-unix.c
|
||||
SUBDIRS += mdns
|
||||
AM_CPPFLAGS = -I./mdns
|
||||
LDADD+=mdns/libmdns.la
|
||||
PRENDSRC=rend-unix.c rend-posix.c
|
||||
endif
|
||||
|
||||
if COND_REND_HOWL
|
||||
@ -66,9 +70,7 @@ mt_daapd_SOURCES = main.c daapd.h rend.h uici.c uici.h webserver.c \
|
||||
$(PRENDSRC) $(ORENDSRC) $(HRENDSRC) $(ARENDSRC) $(OGGVORBISSRC) \
|
||||
$(FLACSRC) $(MUSEPACKSRC) $(SQLITEDB) $(SQLITE3DB) $(SQLDB) $(GDBM)
|
||||
|
||||
EXTRA_DIST = mDNS.c mDNSClientAPI.h mDNSDebug.h mDNSPosix.c \
|
||||
mDNSUNP.c mDNSPlatformFunctions.h mDNSPosix.h mDNSUNP.h \
|
||||
rend-howl.c rend-posix.c rend-osx.c scan-mpc.c \
|
||||
EXTRA_DIST = rend-howl.c rend-posix.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 \
|
||||
|
7073
src/mDNS.c
7073
src/mDNS.c
File diff suppressed because it is too large
Load Diff
1478
src/mDNSClientAPI.h
1478
src/mDNSClientAPI.h
File diff suppressed because it is too large
Load Diff
124
src/mDNSDebug.h
124
src/mDNSDebug.h
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
|
||||
Change History (most recent first):
|
||||
|
||||
$Log$
|
||||
Revision 1.4 2006/02/26 08:46:24 rpedde
|
||||
Merged win32-branch
|
||||
|
||||
Revision 1.3.2.1 2006/02/26 08:28:35 rpedde
|
||||
unix fixes from win32 port
|
||||
|
||||
Revision 1.3 2005/07/21 03:40:07 rpedde
|
||||
Crank up mdns debug messages
|
||||
|
||||
Revision 1.2 2005/01/10 01:07:01 rpedde
|
||||
Synchronize mDNS to Apples 58.8 drop
|
||||
|
||||
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
|
||||
|
||||
#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 void LogMsg(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
|
||||
Change History (most recent first):
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2005/01/10 01:07:01 rpedde
|
||||
Synchronize mDNS to Apples 58.8 drop
|
||||
|
||||
Revision 1.22.2.1 2003/12/05 00:03:34 cheshire
|
||||
<rdar://problem/3487869> Use buffer size MAX_ESCAPED_DOMAIN_NAME instead of 256
|
||||
|
||||
Revision 1.22 2003/08/18 22:53:37 cheshire
|
||||
<rdar://problem/3382647> mDNSResponder divide by zero in mDNSPlatformTimeNow()
|
||||
|
||||
Revision 1.21 2003/08/15 20:16:57 cheshire
|
||||
Update comment for <rdar://problem/3366590> mDNSResponder takes too much RPRVT
|
||||
|
||||
Revision 1.20 2003/08/12 19:56:24 cheshire
|
||||
Update to APSL 2.0
|
||||
|
||||
Revision 1.19 2003/08/05 22:20:15 cheshire
|
||||
<rdar://problem/3330324> Need to check IP TTL on responses
|
||||
|
||||
Revision 1.18 2003/07/22 23:57:20 cheshire
|
||||
Move platform-layer function prototypes from mDNSClientAPI.h to mDNSPlatformFunctions.h where they belong
|
||||
|
||||
Revision 1.17 2003/07/19 03:15:15 cheshire
|
||||
Add generic MemAllocate/MemFree prototypes to mDNSPlatformFunctions.h,
|
||||
and add the obvious trivial implementations to each platform support layer
|
||||
|
||||
Revision 1.16 2003/07/02 21:19:46 cheshire
|
||||
<rdar://problem/3313413> Update copyright notices, etc., in source code comments
|
||||
|
||||
Revision 1.15 2003/05/23 22:39:45 cheshire
|
||||
<rdar://problem/3268151> Need to adjust maximum packet size for IPv6
|
||||
|
||||
Revision 1.14 2003/04/28 21:54:57 cheshire
|
||||
Fix compiler warning
|
||||
|
||||
Revision 1.13 2003/03/15 04:40:36 cheshire
|
||||
Change type called "mDNSOpaqueID" to the more descriptive name "mDNSInterfaceID"
|
||||
|
||||
Revision 1.12 2003/02/21 01:54:08 cheshire
|
||||
Bug #: 3099194 mDNSResponder needs performance improvements
|
||||
Switched to using new "mDNS_Execute" model (see "Implementer Notes.txt")
|
||||
|
||||
Revision 1.11 2002/12/23 22:13:29 jgraessl
|
||||
|
||||
Reviewed by: Stuart Cheshire
|
||||
Initial IPv6 support for mDNSResponder.
|
||||
|
||||
Revision 1.10 2002/09/21 20:44:49 zarzycki
|
||||
Added APSL info
|
||||
|
||||
Revision 1.9 2002/09/19 04:20:43 cheshire
|
||||
Remove high-ascii characters that confuse some systems
|
||||
|
||||
Revision 1.8 2002/09/16 23:12:14 cheshire
|
||||
Minor code tidying
|
||||
|
||||
Revision 1.7 2002/09/16 18:41:42 cheshire
|
||||
Merge in license terms from Quinn's copy, in preparation for Darwin release
|
||||
|
||||
*/
|
||||
|
||||
// Note: All moved to mDNSClientAPI.h
|
1016
src/mDNSPosix.c
1016
src/mDNSPosix.c
File diff suppressed because it is too large
Load Diff
104
src/mDNSPosix.h
104
src/mDNSPosix.h
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
|
||||
Change History (most recent first):
|
||||
|
||||
$Log$
|
||||
Revision 1.3 2006/02/26 08:46:24 rpedde
|
||||
Merged win32-branch
|
||||
|
||||
Revision 1.2.4.1 2006/02/26 08:28:35 rpedde
|
||||
unix fixes from win32 port
|
||||
|
||||
Revision 1.2 2005/01/10 01:07:01 rpedde
|
||||
Synchronize mDNS to Apples 58.8 drop
|
||||
|
||||
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 <sys/time.h>
|
||||
|
||||
#if HAVE_IPV6
|
||||
#define mDNSIPv6Support 1
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// This is a global because debugf_() needs to be able to check its value
|
||||
extern int gMDNSPlatformPosixVerboseLevel;
|
||||
|
||||
struct mDNS_PlatformSupport_struct
|
||||
{
|
||||
// No additional data required for Posix at this time
|
||||
long dummy[1]; // Some compilers don't like empty structures
|
||||
};
|
||||
|
||||
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 *const m, int *nfds, fd_set *readfds, struct timeval *timeout);
|
||||
extern void mDNSPosixProcessFDSet(mDNS *const m, fd_set *readfds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
458
src/mDNSUNP.c
458
src/mDNSUNP.c
@ -1,458 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
|
||||
Change History (most recent first):
|
||||
|
||||
$Log$
|
||||
Revision 1.6 2006/02/26 08:46:24 rpedde
|
||||
Merged win32-branch
|
||||
|
||||
Revision 1.5.2.1 2006/02/26 08:28:35 rpedde
|
||||
unix fixes from win32 port
|
||||
|
||||
Revision 1.5 2005/09/23 05:26:52 rpedde
|
||||
commit the iTunes 5 fixes
|
||||
|
||||
Revision 1.4 2005/03/05 06:37:37 rpedde
|
||||
Roll back patch - breaks fbsd
|
||||
|
||||
Revision 1.2 2005/01/10 01:07:01 rpedde
|
||||
Synchronize mDNS to Apples 58.8 drop
|
||||
|
||||
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>
|
||||
|
||||
#include "daapd.h"
|
||||
#include "err.h"
|
||||
|
||||
/* 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
|
||||
|
||||
|
||||
struct ifi_info *get_ifi_info(int family, int doaliases)
|
||||
{
|
||||
int junk;
|
||||
struct ifi_info *ifi, *ifihead, **ifipnext;
|
||||
int sockfd, len, lastlen, flags, myflags;
|
||||
char *ptr, *buf, lastname[IFNAMSIZ], *cptr;
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr, ifrcopy;
|
||||
struct sockaddr_in *sinptr;
|
||||
// int index;
|
||||
|
||||
#if defined(AF_INET6) && defined(HAVE_IPV6)
|
||||
struct sockaddr_in6 *sinptr6;
|
||||
#endif
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"get_ifi_info\n");
|
||||
|
||||
sockfd = -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 = 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;
|
||||
|
||||
len = GET_SA_LEN(ifr->ifr_addr);
|
||||
|
||||
/* This is completely whacked, and I really need to
|
||||
* find out why this is the case, but I need to
|
||||
* release a 0.2.2, and as the next stable won't
|
||||
* have the apple mDNS included, I guess it's a
|
||||
* small price to pay.
|
||||
*/
|
||||
#ifdef FREEBSD
|
||||
ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
|
||||
// ptr += sizeof(*ifr);
|
||||
#else
|
||||
|
||||
ptr += sizeof(struct ifreq); /* for next one in buffer */
|
||||
#endif
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"intf name=%s AF=%d, flags=%08x\n", ifr->ifr_name, ifr->ifr_addr.sa_family,ifr->ifr_flags);
|
||||
|
||||
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 = 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 */
|
||||
ifi->ifi_index = if_nametoindex(ifr->ifr_name);
|
||||
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 = calloc(1, sizeof(struct sockaddr_in));
|
||||
if (ifi->ifi_addr == NULL) {
|
||||
goto gotError;
|
||||
}
|
||||
memcpy(ifi->ifi_addr, sinptr, sizeof(struct sockaddr_in));
|
||||
|
||||
#ifdef SIOCGIFBRDADDR
|
||||
if (flags & IFF_BROADCAST) {
|
||||
if (ioctl(sockfd, SIOCGIFBRDADDR, &ifrcopy) < 0) {
|
||||
goto gotError;
|
||||
}
|
||||
sinptr = (struct sockaddr_in *) &ifrcopy.ifr_broadaddr;
|
||||
ifi->ifi_brdaddr = 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;
|
||||
ifi->ifi_dstaddr = 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) && defined(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.__u6_addr.__u6_addr16[1] = 0;
|
||||
memcpy(ifi->ifi_addr, sinptr6, sizeof(struct sockaddr_in6));
|
||||
}
|
||||
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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
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 = (void *) sa;
|
||||
msg.msg_namelen = *salenptr;
|
||||
iov[0].iov_base = 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);
|
||||
int nameLen = (sdl->sdl_nlen < IFI_NAME - 1) ? sdl->sdl_nlen : (IFI_NAME - 1);
|
||||
pktp->ipi_ifindex = sdl->sdl_index;
|
||||
#ifndef HAVE_BROKEN_RECVIF_NAME
|
||||
strncpy(pktp->ipi_ifname, sdl->sdl_data, nameLen);
|
||||
#endif
|
||||
assert(pktp->ipi_ifname[IFI_NAME - 1] == 0);
|
||||
// null terminated because of memset above
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(IPV6_PKTINFO) && defined(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;
|
||||
sin6->sin6_len = sizeof(*sin6);
|
||||
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
|
||||
assert(0); // unknown ancillary data
|
||||
}
|
||||
return(n);
|
||||
#endif /* CMSG_FIRSTHDR */
|
||||
}
|
126
src/mDNSUNP.h
126
src/mDNSUNP.h
@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
|
||||
Change History (most recent first):
|
||||
|
||||
$Log$
|
||||
Revision 1.3 2005/01/10 18:11:29 rpedde
|
||||
Fix compile error on solaris
|
||||
|
||||
Revision 1.2 2005/01/10 01:07:01 rpedde
|
||||
Synchronize mDNS to Apples 58.8 drop
|
||||
|
||||
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 __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef NOT_HAVE_SOCKLEN_T
|
||||
typedef unsigned int socklen_t;
|
||||
#endif
|
||||
|
||||
#if !defined(_SS_MAXSIZE)
|
||||
#define sockaddr_storage sockaddr
|
||||
#endif
|
||||
|
||||
#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 mDNSIPv6Support
|
||||
#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 */
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
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_brdaddr;/* broadcast address */
|
||||
struct sockaddr *ifi_dstaddr;/* destination address */
|
||||
struct ifi_info *ifi_next; /* next of these structures */
|
||||
};
|
||||
|
||||
#define IFI_ALIAS 1 /* ifi_addr is an alias */
|
||||
|
||||
extern struct ifi_info *get_ifi_info(int family, int doaliases);
|
||||
extern void free_ifi_info(struct ifi_info *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
2179
src/mdns/DNSCommon.c
Normal file
2179
src/mdns/DNSCommon.c
Normal file
File diff suppressed because it is too large
Load Diff
366
src/mdns/DNSCommon.h
Normal file
366
src/mdns/DNSCommon.h
Normal file
@ -0,0 +1,366 @@
|
||||
/* -*- 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_
|
1464
src/mdns/DNSDigest.c
Normal file
1464
src/mdns/DNSDigest.c
Normal file
File diff suppressed because it is too large
Load Diff
332
src/mdns/GenLinkedList.c
Executable file
332
src/mdns/GenLinkedList.c
Executable file
@ -0,0 +1,332 @@
|
||||
/* -*- 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;
|
||||
}
|
||||
|
||||
|
107
src/mdns/GenLinkedList.h
Executable file
107
src/mdns/GenLinkedList.h
Executable file
@ -0,0 +1,107 @@
|
||||
/* -*- 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__
|
11
src/mdns/Makefile.am
Normal file
11
src/mdns/Makefile.am
Normal file
@ -0,0 +1,11 @@
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
1722
src/mdns/dns_sd.h
Executable file
1722
src/mdns/dns_sd.h
Executable file
File diff suppressed because it is too large
Load Diff
7360
src/mdns/mDNS.c
Executable file
7360
src/mdns/mDNS.c
Executable file
File diff suppressed because it is too large
Load Diff
22
src/mdns/mDNSDebug.c
Normal file
22
src/mdns/mDNSDebug.c
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
190
src/mdns/mDNSDebug.h
Executable file
190
src/mdns/mDNSDebug.h
Executable file
@ -0,0 +1,190 @@
|
||||
/* -*- 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
|
2848
src/mdns/mDNSEmbeddedAPI.h
Executable file
2848
src/mdns/mDNSEmbeddedAPI.h
Executable file
File diff suppressed because it is too large
Load Diff
1755
src/mdns/mDNSPosix.c
Executable file
1755
src/mdns/mDNSPosix.c
Executable file
File diff suppressed because it is too large
Load Diff
145
src/mdns/mDNSPosix.h
Executable file
145
src/mdns/mDNSPosix.h
Executable file
@ -0,0 +1,145 @@
|
||||
/* -*- 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
|
766
src/mdns/mDNSUNP.c
Executable file
766
src/mdns/mDNSUNP.c
Executable file
@ -0,0 +1,766 @@
|
||||
/* -*- 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 */
|
187
src/mdns/mDNSUNP.h
Executable file
187
src/mdns/mDNSUNP.h
Executable file
@ -0,0 +1,187 @@
|
||||
/* -*- 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
|
5242
src/mdns/uDNS.c
Executable file
5242
src/mdns/uDNS.c
Executable file
File diff suppressed because it is too large
Load Diff
190
src/mdns/uDNS.h
Executable file
190
src/mdns/uDNS.h
Executable file
@ -0,0 +1,190 @@
|
||||
/* -*- 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_
|
@ -196,7 +196,7 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "mDNSClientAPI.h"// Defines the interface to the client layer above
|
||||
#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>
|
||||
@ -217,22 +217,6 @@
|
||||
#include "rend.h"
|
||||
#include "rend-unix.h"
|
||||
|
||||
|
||||
/*
|
||||
* I'll take some extra hackishness, please...
|
||||
*/
|
||||
typedef struct PosixNetworkInterface PosixNetworkInterface;
|
||||
|
||||
struct PosixNetworkInterface {
|
||||
NetworkInterfaceInfo coreIntf;
|
||||
const char * intfName;
|
||||
PosixNetworkInterface * aliasIntf;
|
||||
int index;
|
||||
int multicastSocket;
|
||||
int multicastSocketv6;
|
||||
};
|
||||
|
||||
|
||||
static mDNS mDNSStorage; // mDNS core uses this to store its globals
|
||||
static mDNS_PlatformSupport PlatformStorage; // Stores this platform's globals
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user