*
* @APPLE_LICENSE_HEADER_START@
*
+ * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ *
* 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
Change History (most recent first):
$Log: ProxyResponder.c,v $
+Revision 1.27 2004/03/12 08:03:14 cheshire
+Update comments
+
+Revision 1.26 2004/01/25 00:00:39 cheshire
+Change to use mDNSOpaque16fromIntVal() instead of shifting and masking
+
+Revision 1.25 2003/12/08 20:47:02 rpantos
+Add support for mDNSResponder on Linux.
+
Revision 1.24 2003/11/14 21:27:09 cheshire
<rdar://problem/3484766>: Security: Crashing bug in mDNSResponder
Fix code that should use buffer size MAX_ESCAPED_DOMAIN_NAME (1005) instead of 256-byte buffers.
Fix mistake in 1.8 -- INADDR_NONE is 0xFFFFFFFF, not 0
Revision 1.12 2003/04/16 02:11:07 cheshire
-Fixed mDNS_RegisterNoSuchService non-existence function so that it works again
+Fixed mDNS_RegisterNoSuchService non-existance function so that it works again
Revision 1.11 2003/03/31 22:49:35 cheshire
Add "$Log" header
#include <stdlib.h> // For exit() etc.
#include <string.h> // For strlen() etc.
#include <unistd.h> // For select()
+#include <signal.h> // For SIGINT, SIGTERM
#include <errno.h> // For errno, EINTR
#include <arpa/inet.h> // For inet_addr()
#include <netinet/in.h> // For INADDR_NONE
{
domainlabel n;
domainname t, d;
- mDNSIPPort port;
unsigned char txtbuffer[1024], *bptr = txtbuffer;
char buffer[MAX_ESCAPED_DOMAIN_NAME];
MakeDomainLabelFromLiteralString(&n, name);
MakeDomainNameFromDNSNameString(&t, type);
MakeDomainNameFromDNSNameString(&d, domain);
- port.b[0] = (mDNSu8)(PortAsNumber >> 8);
- port.b[1] = (mDNSu8)(PortAsNumber );
while (argc)
{
int len = strlen(argv[0]);
mDNS_RegisterService(m, recordset,
&n, &t, &d, // Name, type, domain
- host, port, // Host and port
+ host, mDNSOpaque16fromIntVal(PortAsNumber),
txtbuffer, bptr-txtbuffer, // TXT data, length
mDNSNULL, 0, // Subtypes
- mDNSInterface_Any, // Interace ID
+ mDNSInterface_Any, // Interface ID
ServiceCallback, mDNSNULL); // Callback and context
ConvertDomainNameToCString(&recordset->RR_SRV.resrec.name, buffer);
mDNSexport int main(int argc, char **argv)
{
- mStatus status;
+ mStatus status;
+ sigset_t signals;
if (argc < 3) goto usage;
mDNS_Init_NoInitCallback, mDNS_Init_NoInitCallbackContext);
if (status) { fprintf(stderr, "Daemon start: mDNS_Init failed %ld\n", status); return(status); }
+ mDNSPosixListenForSignalInEventLoop(SIGINT);
+ mDNSPosixListenForSignalInEventLoop(SIGTERM);
+
if (!strcmp(argv[1], "-"))
{
domainname proxyhostname;
AppendLiteralLabelString(&proxyhostname, argv[2]);
AppendLiteralLabelString(&proxyhostname, "local");
RegisterNoSuchService(&mDNSStorage, &proxyrecord, &proxyhostname, argv[3], argv[4], "local.");
- ExampleClientEventLoop(&mDNSStorage);
- mDNS_Close(&mDNSStorage);
}
else
{
if (argc >=6)
RegisterService(&mDNSStorage, &proxyservice, argv[3], argv[4], "local.",
&proxyhost.RR_A.resrec.name, atoi(argv[5]), argc-6, &argv[6]);
+ }
- ExampleClientEventLoop(&mDNSStorage);
- mDNS_Close(&mDNSStorage);
+ do
+ {
+ struct timeval timeout = { 0x3FFFFFFF, 0 }; // wait until SIGINT or SIGTERM
+ mDNSBool gotSomething;
+ mDNSPosixRunEventLoopOnce(&mDNSStorage, &timeout, &signals, &gotSomething);
}
+ while ( !( sigismember( &signals, SIGINT) || sigismember( &signals, SIGTERM)));
+
+ mDNS_Close(&mDNSStorage);
return(0);