Merge new rendezvous code

This commit is contained in:
Ron Pedde 2004-03-02 00:03:37 +00:00
parent c28a956379
commit 8ddc247d7b
10 changed files with 7421 additions and 3817 deletions

View File

@ -1,73 +1,71 @@
/*
* Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.2 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
* 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.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* 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 OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
* 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@
*/
/*
File: responder.c
Contains: Code to implement an mDNS responder on the Posix platform.
Written by: Quinn
Copyright: Copyright (c) 2002 by Apple Computer, Inc., All Rights Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first):
$Log$
Revision 1.1 2003/10/23 21:43:01 ron
Add Apple mDNS reponder
Revision 1.2 2004/03/02 00:03:37 rpedde
Merge new rendezvous code
Revision 1.16 2003/08/14 02:19:55 cheshire
<rdar://problem/3375491> Split generic ResourceRecord type into two separate types: AuthRecord and CacheRecord
Revision 1.15 2003/08/12 19:56:26 cheshire
Update to APSL 2.0
Revision 1.14 2003/08/06 18:20:51 cheshire
Makefile cleanup
Revision 1.13 2003/07/23 00:00:04 cheshire
Add comments
Revision 1.12 2003/07/15 01:55:16 cheshire
<rdar://problem/3315777> Need to implement service registration with subtypes
Revision 1.11 2003/07/14 18:11:54 cheshire
Fix stricter compiler warnings
Revision 1.10 2003/07/10 20:27:31 cheshire
<rdar://problem/3318717> mDNSResponder Posix version is missing a 'b' in the getopt option string
Revision 1.9 2003/07/02 21:19:59 cheshire
<rdar://problem/3313413> Update copyright notices, etc., in source code comments
Revision 1.8 2003/06/18 05:48:41 cheshire
Fix warnings
Revision 1.7 2003/05/06 00:00:50 cheshire
<rdar://problem/3248914> Rationalize naming of domainname manipulation functions
Revision 1.6 2003/03/08 00:35:56 cheshire
Switched to using new "mDNS_Execute" model (see "mDNSCore/Implementer Notes.txt")
Revision 1.5 2003/02/20 06:48:36 cheshire
Bug #: 3169535 Xserve RAID needs to do interface-specific registrations
Reviewed by: Josh Graessley, Bob Bradley
Revision 1.4 2003/01/28 03:07:46 cheshire
Add extra parameter to mDNS_RenameAndReregisterService(),
and add support for specifying a domain other than dot-local.
Revision 1.3 2002/09/21 20:44:53 zarzycki
Added APSL info
@ -92,14 +90,18 @@ First checkin
#include <signal.h>
#include <fcntl.h>
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark ***** Globals
#endif
static mDNS mDNSStorage; // mDNS core uses this to store its globals
static mDNS_PlatformSupport PlatformStorage; // Stores this platform's globals
static const char *gProgramName = "mDNSResponderPosix";
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark ***** Signals
#endif
static volatile mDNSBool gReceivedSigUsr1;
static volatile mDNSBool gReceivedSigHup;
@ -167,7 +169,9 @@ static void HandleSigQuit(int sigraised)
exit(0);
}
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark ***** Parameter Checking
#endif
static mDNSBool CheckThatRichTextHostNameIsUsable(const char *richTextHostName, mDNSBool printExplanation)
// Checks that richTextHostName is a reasonable host name
@ -194,7 +198,7 @@ static mDNSBool CheckThatRichTextHostNameIsUsable(const char *richTextHostName,
result = mDNSfalse;
}
if (result) {
ConvertCStringToDomainLabel(richTextHostName, &richLabel);
MakeDomainLabelFromLiteralString(&richLabel, richTextHostName);
ConvertUTF8PstringToRFC1034HostLabel(richLabel.c, &poorLabel);
if (poorLabel.c[0] == 0) {
if (printExplanation) {
@ -339,18 +343,21 @@ static mDNSBool CheckThatPortNumberIsUsable(long portNumber, mDNSBool printExpla
return result;
}
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark ***** Command Line Arguments
#endif
static const char kDefaultPIDFile[] = "/var/run/mDNSResponder.pid";
static const char kDefaultServiceType[] = "_afpovertcp._tcp.";
static const char kDefaultServiceDomain[] = "local.";
enum {
kDefaultPortNumber = 548
};
static void PrintUsage(char **argv)
static void PrintUsage()
{
fprintf(stderr,
"Usage: %s [-v level ] [-r] [-n name] [-t type] [-x TXT] [-p port] [-f file] [-d] [-P pidfile]\n",
"Usage: %s [-v level ] [-r] [-n name] [-t type] [-d domain] [-x TXT] [-p port] [-f file] [-b] [-P pidfile]\n",
gProgramName);
fprintf(stderr, " -v verbose mode, level is a number from 0 to 2\n");
fprintf(stderr, " 0 = no debugging info (default)\n");
@ -360,18 +367,20 @@ static void PrintUsage(char **argv)
fprintf(stderr, " -r also bind to port 53 (port 5353 is always bound)\n");
fprintf(stderr, " -n uses 'name' as the host name (default is none)\n");
fprintf(stderr, " -t uses 'type' as the service type (default is '%s')\n", kDefaultServiceType);
fprintf(stderr, " -d uses 'domain' as the service domain (default is '%s')\n", kDefaultServiceDomain);
fprintf(stderr, " -x uses 'TXT' as the service TXT record (default is empty)\n");
fprintf(stderr, " -p uses 'port' as the port number (default is '%d')\n", kDefaultPortNumber);
fprintf(stderr, " -f reads a service list from 'file'\n");
fprintf(stderr, " -d forces daemon mode\n");
fprintf(stderr, " -b forces daemon (background) mode\n");
fprintf(stderr, " -P uses 'pidfile' as the PID file\n");
fprintf(stderr, " (default is '%s')\n", kDefaultPIDFile);
fprintf(stderr, " only meaningful if -d also specified\n");
fprintf(stderr, " only meaningful if -b also specified\n");
}
static mDNSBool gAvoidPort53 = mDNStrue;
static const char *gRichTextHostName = "";
static const char *gServiceType = kDefaultServiceType;
static const char *gServiceDomain = kDefaultServiceDomain;
static mDNSu8 gServiceText[sizeof(RDataBody)];
static mDNSu16 gServiceTextLen = 0;
static int gPortNumber = kDefaultPortNumber;
@ -397,7 +406,7 @@ static void ParseArguments(int argc, char **argv)
// Parse command line options using getopt.
do {
ch = getopt(argc, argv, "v:rn:x:t:p:f:dP");
ch = getopt(argc, argv, "v:rn:t:d:x:p:f:dPb");
if (ch != -1) {
switch (ch) {
case 'v':
@ -424,6 +433,9 @@ static void ParseArguments(int argc, char **argv)
exit(1);
}
break;
case 'd':
gServiceDomain = optarg;
break;
case 'x':
if ( ! CheckThatServiceTextIsUsable(optarg, mDNStrue, gServiceText, &gServiceTextLen) ) {
exit(1);
@ -438,7 +450,7 @@ static void ParseArguments(int argc, char **argv)
case 'f':
gServiceFile = optarg;
break;
case 'd':
case 'b':
gDaemon = mDNStrue;
break;
case 'P':
@ -446,7 +458,7 @@ static void ParseArguments(int argc, char **argv)
break;
case '?':
default:
PrintUsage(argv);
PrintUsage();
exit(1);
break;
}
@ -456,6 +468,7 @@ static void ParseArguments(int argc, char **argv)
// Check for any left over command line arguments.
if (optind != argc) {
PrintUsage();
fprintf(stderr, "%s: Unexpected argument '%s'\n", gProgramName, argv[optind]);
exit(1);
}
@ -463,12 +476,15 @@ static void ParseArguments(int argc, char **argv)
// Check for inconsistency between the arguments.
if ( (gRichTextHostName[0] == 0) && (gServiceFile[0] == 0) ) {
PrintUsage();
fprintf(stderr, "%s: You must specify a service to register (-n) or a service file (-f).\n", gProgramName);
exit(1);
}
}
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark ***** Registration
#endif
typedef struct PosixService PosixService;
@ -488,13 +504,13 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi
switch (status) {
case mStatus_NoError:
debugf("Callback: %##s Name Registered", thisRegistration->RR_SRV.name.c);
debugf("Callback: %##s Name Registered", thisRegistration->RR_SRV.resrec.name.c);
// Do nothing; our name was successfully registered. We may
// get more call backs in the future.
break;
case mStatus_NameConflict:
debugf("Callback: %##s Name Conflict", thisRegistration->RR_SRV.name.c);
debugf("Callback: %##s Name Conflict", thisRegistration->RR_SRV.resrec.name.c);
// In the event of a conflict, this sample RegistrationCallback
// just calls mDNS_RenameAndReregisterService to automatically
@ -507,12 +523,12 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi
// Also, what do we do if mDNS_RenameAndReregisterService returns an
// error. Right now I have no place to send that error to.
status = mDNS_RenameAndReregisterService(m, thisRegistration);
status = mDNS_RenameAndReregisterService(m, thisRegistration, mDNSNULL);
assert(status == mStatus_NoError);
break;
case mStatus_MemFree:
debugf("Callback: %##s Memory Free", thisRegistration->RR_SRV.name.c);
debugf("Callback: %##s Memory Free", thisRegistration->RR_SRV.resrec.name.c);
// When debugging is enabled, make sure that thisRegistration
// is not on our gServiceList.
@ -532,7 +548,7 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi
break;
default:
debugf("Callback: %##s Unknown Status %d", thisRegistration->RR_SRV.name.c, status);
debugf("Callback: %##s Unknown Status %d", thisRegistration->RR_SRV.resrec.name.c, status);
break;
}
}
@ -541,6 +557,7 @@ static int gServiceID = 0;
static mStatus RegisterOneService(const char * richTextHostName,
const char * serviceType,
const char * serviceDomain,
const mDNSu8 text[],
mDNSu16 textLen,
long portNumber)
@ -558,17 +575,18 @@ static mStatus RegisterOneService(const char * richTextHostName,
status = mStatus_NoMemoryErr;
}
if (status == mStatus_NoError) {
ConvertCStringToDomainLabel(richTextHostName, &name);
ConvertCStringToDomainName(serviceType, &type);
ConvertCStringToDomainName("local.", &domain);
MakeDomainLabelFromLiteralString(&name, richTextHostName);
MakeDomainNameFromDNSNameString(&type, serviceType);
MakeDomainNameFromDNSNameString(&domain, serviceDomain);
port.b[0] = (portNumber >> 8) & 0x0FF;
port.b[1] = (portNumber >> 0) & 0x0FF;;
status = mDNS_RegisterService(&mDNSStorage, &thisServ->coreServ,
&name, &type, &domain,
NULL,
port,
text, textLen,
RegistrationCallback, thisServ);
&name, &type, &domain, // Name, type, domain
NULL, port, // Host and port
text, textLen, // TXT data, length
NULL, 0, // Subtypes
mDNSInterface_Any, // Interace ID
RegistrationCallback, thisServ); // Callback and context
}
if (status == mStatus_NoError) {
thisServ->serviceID = gServiceID;
@ -619,6 +637,7 @@ static mStatus RegisterServicesInFile(const char *filePath)
int ch;
char name[256];
char type[256];
const char *dom = kDefaultServiceDomain;
char rawText[1024];
mDNSu8 text[sizeof(RDataBody)];
mDNSu16 textLen;
@ -646,6 +665,14 @@ static mStatus RegisterServicesInFile(const char *filePath)
if (good) {
good = ReadALine(type, sizeof(type), fp);
}
if (good) {
char *p = type;
while (*p && *p != ' ') p++;
if (*p) {
*p = 0;
dom = p+1;
}
}
if (good) {
good = ReadALine(rawText, sizeof(rawText), fp);
}
@ -659,7 +686,7 @@ static mStatus RegisterServicesInFile(const char *filePath)
&& CheckThatPortNumberIsUsable(atol(port), mDNSfalse);
}
if (good) {
status = RegisterOneService(name, type, text, textLen, atol(port));
status = RegisterOneService(name, type, dom, text, textLen, atol(port));
if (status != mStatus_NoError) {
fprintf(stderr,
"%s: Failed to register service, name = %s, type = %s, port = %s\n",
@ -694,6 +721,7 @@ static mStatus RegisterOurServices(void)
if (gRichTextHostName[0] != 0) {
status = RegisterOneService(gRichTextHostName,
gServiceType,
gServiceDomain,
gServiceText, gServiceTextLen,
gPortNumber);
}
@ -725,9 +753,11 @@ static void DeregisterOurServices(void)
}
}
#if COMPILER_LIKES_PRAGMA_MARK
#pragma mark **** Main
#endif
#if !defined(HAVE_DAEMON)
#ifdef NOT_HAVE_DAEMON
// The version of Solaris that I tested on didn't have the daemon
// call. This implementation was basically stolen from the
@ -762,7 +792,7 @@ static void DeregisterOurServices(void)
return (0);
}
#endif
#endif /* NOT_HAVE_DAEMON */
int main(int argc, char **argv)
{
@ -870,7 +900,7 @@ int main(int argc, char **argv)
else
{
// 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
mDNSPosixProcessFDSet(&mDNSStorage, result, &readfds);
mDNSPosixProcessFDSet(&mDNSStorage, &readfds);
// 6. This example client has no other work it needs to be doing,
// but a real client would do its work here

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,75 +1,45 @@
/*
* Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.2 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
* 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.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* 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 OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
* 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@
*/
/*
File: mDNSDebug.h
Contains: mDNS debugging interface.
Written by: Stuart Cheshire
Version: mDNS Core, September 2002
Copyright: Copyright (c) 2002 by Apple Computer, Inc., All Rights Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first):
$Log$
Revision 1.1 2003/10/23 21:43:01 ron
Add Apple mDNS reponder
Revision 1.2 2004/03/02 00:03:37 rpedde
Merge new rendezvous code
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
@ -92,13 +62,26 @@ Merge in license terms from Quinn's copy, in preparation for Darwin release
//#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 /* __cplusplus */
#endif
#ifdef DEBUG
#if MDNS_DEBUGMSGS
#define debugf debugf_
extern void debugf_(const char *format, ...);
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)
@ -107,11 +90,11 @@ extern void debugf_(const char *format, ...);
#else
#define debugf 1 ? ((void)0) : (void)
#endif
#endif /* DEBUG */
#endif
#ifdef EXTRADEBUG
#if MDNS_DEBUGMSGS > 1
#define verbosedebugf verbosedebugf_
extern void verbosedebugf_(const char *format, ...);
extern void verbosedebugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
#else
#if( defined( __GNUC__ ) )
#define verbosedebugf( ARGS... ) ((void)0)
@ -120,7 +103,10 @@ extern void verbosedebugf_(const char *format, ...);
#else
#define verbosedebugf 1 ? ((void)0) : (void)
#endif
#endif /* DEBUG */
#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
}

View File

@ -1,75 +1,73 @@
/*
* Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.2 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
* 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.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* 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 OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
* 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@
*/
/*
File: mDNSPlatformFunctions.h
Contains: Prototype for functions implemented and callable by the platform.
Written by: Stuart Cheshire
Version: mDNS Core, September 2002
Copyright: Copyright (c) 2002 by Apple Computer, Inc., All Rights Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first):
$Log$
Revision 1.1 2003/10/23 21:43:01 ron
Add Apple mDNS reponder
Revision 1.2 2004/03/02 00:03:37 rpedde
Merge new rendezvous code
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
@ -85,78 +83,4 @@ Merge in license terms from Quinn's copy, in preparation for Darwin release
*/
#ifndef __mDNSPlatformFunctions_h
#define __mDNSPlatformFunctions_h
// ***************************************************************************
// Support functions which must be provided by each set of specific PlatformSupport files
// mDNSPlatformInit() typically opens a communication endpoint, and starts listening for mDNS packets.
// When Setup is complete, the callback is called.
// mDNSPlatformSendUDP() sends one UDP packet
// When a packet is received, the PlatformSupport code calls mDNSCoreReceive()
// mDNSPlatformScheduleTask() indicates that a timer should be set,
// and mDNSCoreTask() should be called when the timer expires
// mDNSPlatformClose() tidies up on exit
#ifdef __cplusplus
extern "C" {
#endif
// ***************************************************************************
// DNS protocol message format
typedef struct
{
mDNSOpaque16 id;
mDNSOpaque16 flags;
mDNSu16 numQuestions;
mDNSu16 numAnswers;
mDNSu16 numAuthorities;
mDNSu16 numAdditionals;
} DNSMessageHeader;
// We can send and receive packets up to 9000 bytes (Ethernet Jumbo Frame size, if that ever becomes widely used)
// However, in the normal case we try to limit packets to 1500 bytes so that we don't get IP fragmentation on standard Ethernet
#define AbsoluteMaxDNSMessageData 8960
#define NormalMaxDNSMessageData 1460
typedef struct
{
DNSMessageHeader h; // Note: Size 12 bytes
mDNSu8 data[AbsoluteMaxDNSMessageData]; // 20 (IP) + 8 (UDP) + 12 (header) + 8960 (data) = 9000
} DNSMessage;
// ***************************************************************************
// Functions
// Every platform support module must provide the following functions
extern mStatus mDNSPlatformInit (mDNS *const m);
extern void mDNSPlatformClose (mDNS *const m);
extern mStatus mDNSPlatformSendUDP(const mDNS *const m, const DNSMessage *const msg, const mDNSu8 *const end,
mDNSIPAddr src, mDNSIPPort srcport, mDNSIPAddr dst, mDNSIPPort dstport);
extern mDNSs32 mDNSPlatformOneSecond;
extern mDNSs32 mDNSPlatformTimeNow();
extern void mDNSPlatformScheduleTask(const mDNS *const m, mDNSs32 NextTaskTime);
extern void mDNSPlatformLock (const mDNS *const m);
extern void mDNSPlatformUnlock (const mDNS *const m);
extern void mDNSPlatformStrCopy(const void *src, void *dst);
extern mDNSu32 mDNSPlatformStrLen (const void *src);
extern void mDNSPlatformMemCopy(const void *src, void *dst, mDNSu32 len);
extern mDNSBool mDNSPlatformMemSame(const void *src, const void *dst, mDNSu32 len);
extern void mDNSPlatformMemZero( void *dst, mDNSu32 len);
// The core mDNS code provides these functions, for the platform support code to call at appropriate times
extern void mDNSCoreInitComplete(mDNS *const m, mStatus result);
extern void mDNSCoreReceive(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
mDNSIPAddr srcaddr, mDNSIPPort srcport, mDNSIPAddr dstaddr, mDNSIPPort dstport, mDNSIPAddr InterfaceAddr);
extern void mDNSCoreTask (mDNS *const m);
extern void mDNSCoreSleep (mDNS *const m, mDNSBool wake);
#ifdef __cplusplus
}
#endif
#endif
// Note: All moved to mDNSClientAPI.h

File diff suppressed because it is too large Load Diff

View File

@ -1,73 +1,50 @@
/*
* Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.2 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
* 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.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* 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 OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
* 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@
*/
/*
File: mDNSPlatformPosix.h
Contains: Interface to the Posix platform code.
Written by: Quinn
Copyright: Copyright (c) 2002 by Apple Computer, Inc., All Rights Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first):
$Log$
Revision 1.1 2003/10/23 21:43:01 ron
Add Apple mDNS reponder
Revision 1.2 2004/03/02 00:03:37 rpedde
Merge new rendezvous code
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
@ -85,6 +62,10 @@ First checkin
#include <sys/time.h>
#if HAVE_IPV6
#define mDNSIPv6Support 1
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -94,7 +75,8 @@ extern int gMDNSPlatformPosixVerboseLevel;
struct mDNS_PlatformSupport_struct
{
struct timeval NextEvent;
// 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);
@ -106,8 +88,8 @@ extern mStatus mDNSPlatformPosixRefreshInterfaceList(mDNS *const m);
// 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(const mDNS *const m, int *nfds, fd_set *readfds, struct timeval *timeout);
extern void mDNSPosixProcessFDSet(mDNS *const m, int selectresult, fd_set *readfds);
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
}

View File

@ -1,76 +1,61 @@
/*
* Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.2 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
* 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.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* 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 OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
* 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@
*/
/*
File: mDNSUNP.c
Contains: Code derived from "UNIX Network Programming".
Written by: Quinn
Copyright: Copyright (c) 2002 by Apple Computer, Inc., All Rights Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first):
$Log$
Revision 1.2 2003/11/26 06:12:53 ron
Exclude from memory checks
Revision 1.3 2004/03/02 00:03:37 rpedde
Merge new rendezvous code
Revision 1.1 2003/10/23 21:43:01 ron
Add Apple mDNS reponder
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
@ -94,9 +79,6 @@ First checkin
#include <unistd.h>
#include <stdio.h>
#define __IN_ERR__
#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
@ -116,8 +98,6 @@ First checkin
#endif
#define max(a,b) ((a) > (b) ? (a) : (b))
struct ifi_info *get_ifi_info(int family, int doaliases)
{
int junk;
@ -127,9 +107,11 @@ struct ifi_info *get_ifi_info(int family, int doaliases)
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
index = 0;
sockfd = -1;
buf = NULL;
ifihead = NULL;
@ -169,25 +151,10 @@ struct ifi_info *get_ifi_info(int family, int doaliases)
for (ptr = buf; ptr < buf + ifc.ifc_len; ) {
ifr = (struct ifreq *) ptr;
#ifdef HAVE_SOCKADDR_SA_LEN
len = max(sizeof(struct sockaddr), ifr->ifr_addr.sa_len);
#else
switch (ifr->ifr_addr.sa_family) {
#ifdef IPV6
case AF_INET6:
len = sizeof(struct sockaddr_in6);
break;
#endif
case AF_INET:
default:
len = sizeof(struct sockaddr);
break;
}
#endif /* HAVE_SOCKADDR_SA_LEN */
len = GET_SA_LEN(ifr->ifr_addr);
ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
DPRINTF(ERR_DEBUG,"intf %d name=%s AF=%d", index, ifr->ifr_name,
ifr->ifr_addr.sa_family);
// fprintf(stderr, "intf %d 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 */
@ -220,8 +187,7 @@ struct ifi_info *get_ifi_info(int family, int doaliases)
ifi->ifi_flags = flags; /* IFF_xxx values */
ifi->ifi_myflags = myflags; /* IFI_xxx values */
index += 1;
ifi->ifi_index = index;
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 */
@ -266,6 +232,24 @@ struct ifi_info *get_ifi_info(int family, int doaliases)
}
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;
}
@ -317,7 +301,7 @@ recvfrom_flags(int fd, void *ptr, size_t nbytes, int *flagsp,
struct iovec iov[1];
ssize_t n;
#ifdef HAVE_MSGHDR_MSG_CONTROL
#ifdef CMSG_FIRSTHDR
struct cmsghdr *cmptr;
union {
struct cmsghdr cm;
@ -329,7 +313,7 @@ recvfrom_flags(int fd, void *ptr, size_t nbytes, int *flagsp,
msg.msg_flags = 0;
#else
memset(&msg, 0, sizeof(msg)); /* make certain msg_accrightslen = 0 */
#endif
#endif /* CMSG_FIRSTHDR */
msg.msg_name = (void *) sa;
msg.msg_namelen = *salenptr;
@ -356,13 +340,14 @@ recvfrom_flags(int fd, void *ptr, size_t nbytes, int *flagsp,
/* end recvfrom_flags1 */
/* include recvfrom_flags2 */
#ifndef HAVE_MSGHDR_MSG_CONTROL
#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 < sizeof(struct cmsghdr) ||
if (msg.msg_controllen < (socklen_t)sizeof(struct cmsghdr) ||
(msg.msg_flags & MSG_CTRUNC) || pktp == NULL)
return(n);
@ -381,9 +366,12 @@ struct in_pktinfo
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);
memcpy(&pktp->ipi_addr, &tmp->ipi_addr, sizeof(struct in_addr));
sin->sin_family = AF_INET;
sin->sin_addr = tmp->ipi_addr;
sin->sin_port = 0;
pktp->ipi_ifindex = tmp->ipi_ifindex;
continue;
}
@ -392,9 +380,11 @@ struct in_pktinfo
#ifdef IP_RECVDSTADDR
if (cmptr->cmsg_level == IPPROTO_IP &&
cmptr->cmsg_type == IP_RECVDSTADDR) {
memcpy(&pktp->ipi_addr, CMSG_DATA(cmptr),
sizeof(struct in_addr));
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
@ -402,23 +392,36 @@ struct in_pktinfo
#ifdef IP_RECVIF
if (cmptr->cmsg_level == IPPROTO_IP &&
cmptr->cmsg_type == IP_RECVIF) {
struct sockaddr_dl *sdl;
int nameLen;
sdl = (struct sockaddr_dl *) CMSG_DATA(cmptr);
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;
nameLen = sdl->sdl_nlen;
if (nameLen > (IFI_NAME - 1)) {
nameLen = IFI_NAME - 1;
}
#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 /* HAVE_MSGHDR_MSG_CONTROL */
#endif /* CMSG_FIRSTHDR */
}

View File

@ -1,73 +1,47 @@
/*
* Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
* Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.2 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
* 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.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* 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 OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
* 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@
*/
/*
File: mDNSUNP.h
Contains: Interface to code derived from "UNIX Network Programming".
Written by: Quinn
Copyright: Copyright (c) 2002 by Apple Computer, Inc., All Rights Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first):
$Log$
Revision 1.1 2003/10/23 21:43:01 ron
Add Apple mDNS reponder
Revision 1.2 2004/03/02 00:03:37 rpedde
Merge new rendezvous code
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
@ -92,19 +66,33 @@ First checkin
extern "C" {
#endif
#if !defined(HAVE_SOCKLEN_T)
#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) ((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 in_addr ipi_addr; /* dst IPv4 address */
int ipi_ifindex; /* received interface index */
char ipi_ifname[IFI_NAME]; /* received interface name */
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,

View File

@ -89,6 +89,9 @@
Change History (most recent first):
$Log$
Revision 1.14 2004/03/02 00:03:37 rpedde
Merge new rendezvous code
Revision 1.13 2004/03/01 16:29:42 rpedde
Fix logging
@ -235,14 +238,14 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi
case mStatus_NoError:
DPRINTF(ERR_DEBUG,"Callback: %##s Name Registered\n",
thisRegistration->RR_SRV.name.c);
thisRegistration->RR_SRV.resrec.name.c);
// Do nothing; our name was successfully registered. We may
// get more call backs in the future.
break;
case mStatus_NameConflict:
DPRINTF(ERR_WARN,"Callback: %##s Name Conflict\n",
thisRegistration->RR_SRV.name.c);
thisRegistration->RR_SRV.resrec.name.c);
// In the event of a conflict, this sample RegistrationCallback
// just calls mDNS_RenameAndReregisterService to automatically
@ -255,13 +258,13 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi
// Also, what do we do if mDNS_RenameAndReregisterService returns an
// error. Right now I have no place to send that error to.
status = mDNS_RenameAndReregisterService(m, thisRegistration);
status = mDNS_RenameAndReregisterService(m, thisRegistration, mDNSNULL);
assert(status == mStatus_NoError);
break;
case mStatus_MemFree:
DPRINTF(ERR_WARN,"Callback: %##s Memory Free\n",
thisRegistration->RR_SRV.name.c);
thisRegistration->RR_SRV.resrec.name.c);
// When debugging is enabled, make sure that thisRegistration
// is not on our gServiceList.
@ -282,7 +285,7 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi
default:
DPRINTF(ERR_WARN,"Callback: %##s Unknown Status %d\n",
thisRegistration->RR_SRV.name.c, status);
thisRegistration->RR_SRV.resrec.name.c, status);
break;
}
}
@ -291,6 +294,7 @@ static int gServiceID = 0;
static mStatus RegisterOneService(const char * richTextHostName,
const char * serviceType,
const char * serviceDomain,
const mDNSu8 text[],
mDNSu16 textLen,
long portNumber)
@ -308,9 +312,10 @@ static mStatus RegisterOneService(const char * richTextHostName,
status = mStatus_NoMemoryErr;
}
if (status == mStatus_NoError) {
ConvertCStringToDomainLabel(richTextHostName, &name);
ConvertCStringToDomainName(serviceType, &type);
ConvertCStringToDomainName("local.", &domain);
MakeDomainLabelFromLiteralString(&name, richTextHostName);
MakeDomainNameFromDNSNameString(&type, serviceType);
MakeDomainNameFromDNSNameString(&domain, serviceDomain);
port.b[0] = (portNumber >> 8) & 0x0FF;
port.b[1] = (portNumber >> 0) & 0x0FF;;
status = mDNS_RegisterService(&mDNSStorage, &thisServ->coreServ,
@ -318,6 +323,8 @@ static mStatus RegisterOneService(const char * richTextHostName,
NULL,
port,
text, textLen,
NULL, 0,
mDNSInterface_Any,
RegistrationCallback, thisServ);
}
if (status == mStatus_NoError) {
@ -384,7 +391,7 @@ void rend_callback(void) {
switch(msg.cmd) {
case REND_MSG_TYPE_REGISTER:
DPRINTF(ERR_DEBUG,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port);
RegisterOneService(msg.name,msg.type,NULL,0,msg.port);
RegisterOneService(msg.name,msg.type,".local",NULL,0,msg.port);
rend_send_response(0); /* success */
break;
case REND_MSG_TYPE_UNREGISTER:
@ -457,7 +464,7 @@ int rend_private_init(char *user) {
if (errno != EINTR) gStopNow = mDNStrue;
} else {
// 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
mDNSPosixProcessFDSet(&mDNSStorage, result, &readfds);
mDNSPosixProcessFDSet(&mDNSStorage, &readfds);
// 6. This example client has no other work it needs to be doing,
// but a real client would do its work here