2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
26 Revision 1.16 2003/08/14 02:19:55 cheshire
27 <rdar://problem/3375491> Split generic ResourceRecord type into two separate types: AuthRecord and CacheRecord
29 Revision 1.15 2003/08/12 19:56:26 cheshire
32 Revision 1.14 2003/08/06 18:20:51 cheshire
35 Revision 1.13 2003/07/23 00:00:04 cheshire
38 Revision 1.12 2003/07/15 01:55:16 cheshire
39 <rdar://problem/3315777> Need to implement service registration with subtypes
41 Revision 1.11 2003/07/14 18:11:54 cheshire
42 Fix stricter compiler warnings
44 Revision 1.10 2003/07/10 20:27:31 cheshire
45 <rdar://problem/3318717> mDNSResponder Posix version is missing a 'b' in the getopt option string
47 Revision 1.9 2003/07/02 21:19:59 cheshire
48 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
50 Revision 1.8 2003/06/18 05:48:41 cheshire
53 Revision 1.7 2003/05/06 00:00:50 cheshire
54 <rdar://problem/3248914> Rationalize naming of domainname manipulation functions
56 Revision 1.6 2003/03/08 00:35:56 cheshire
57 Switched to using new "mDNS_Execute" model (see "mDNSCore/Implementer Notes.txt")
59 Revision 1.5 2003/02/20 06:48:36 cheshire
60 Bug #: 3169535 Xserve RAID needs to do interface-specific registrations
61 Reviewed by: Josh Graessley, Bob Bradley
63 Revision 1.4 2003/01/28 03:07:46 cheshire
64 Add extra parameter to mDNS_RenameAndReregisterService(),
65 and add support for specifying a domain other than dot-local.
67 Revision 1.3 2002/09/21 20:44:53 zarzycki
70 Revision 1.2 2002/09/19 04:20:44 cheshire
71 Remove high-ascii characters that confuse some systems
73 Revision 1.1 2002/09/17 06:24:35 cheshire
78 #include "mDNSClientAPI.h"// Defines the interface to the client layer above
79 #include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
82 #include <stdio.h> // For printf()
83 #include <stdlib.h> // For exit() etc.
84 #include <string.h> // For strlen() etc.
85 #include <unistd.h> // For select()
86 #include <errno.h> // For errno, EINTR
90 #if COMPILER_LIKES_PRAGMA_MARK
91 #pragma mark ***** Globals
94 static mDNS mDNSStorage
; // mDNS core uses this to store its globals
95 static mDNS_PlatformSupport PlatformStorage
; // Stores this platform's globals
97 static const char *gProgramName
= "mDNSResponderPosix";
99 #if COMPILER_LIKES_PRAGMA_MARK
100 #pragma mark ***** Signals
103 static volatile mDNSBool gReceivedSigUsr1
;
104 static volatile mDNSBool gReceivedSigHup
;
105 static volatile mDNSBool gStopNow
;
107 // We support 4 signals.
109 // o SIGUSR1 toggles verbose mode on and off in debug builds
110 // o SIGHUP triggers the program to re-read its preferences.
111 // o SIGINT causes an orderly shutdown of the program.
112 // o SIGQUIT causes a somewhat orderly shutdown (direct but dangerous)
113 // o SIGKILL kills us dead (easy to implement :-)
115 // There are fatal race conditions in our signal handling, but there's not much
116 // we can do about them while remaining within the Posix space. Specifically,
117 // if a signal arrives after we test the globals its sets but before we call
118 // select, the signal will be dropped. The user will have to send the signal
119 // again. Unfortunately, Posix does not have a "sigselect" to atomically
120 // modify the signal mask and start a select.
122 static void HandleSigUsr1(int sigraised
)
123 // If we get a SIGUSR1 we toggle the state of the
126 assert(sigraised
== SIGUSR1
);
127 gReceivedSigUsr1
= mDNStrue
;
130 static void HandleSigHup(int sigraised
)
131 // A handler for SIGHUP that causes us to break out of the
132 // main event loop when the user kill 1's us. This has the
133 // effect of triggered the main loop to deregister the
134 // current services and re-read the preferences.
136 assert(sigraised
== SIGHUP
);
137 gReceivedSigHup
= mDNStrue
;
140 static void HandleSigInt(int sigraised
)
141 // A handler for SIGINT that causes us to break out of the
142 // main event loop when the user types ^C. This has the
143 // effect of quitting the program.
145 assert(sigraised
== SIGINT
);
147 if (gMDNSPlatformPosixVerboseLevel
> 0) {
148 fprintf(stderr
, "\nSIGINT\n");
153 static void HandleSigQuit(int sigraised
)
154 // If we get a SIGQUIT the user is desperate and we
155 // just call mDNS_Close directly. This is definitely
156 // not safe (because it could reenter mDNS), but
157 // we presume that the user has already tried the safe
160 assert(sigraised
== SIGQUIT
);
162 if (gMDNSPlatformPosixVerboseLevel
> 0) {
163 fprintf(stderr
, "\nSIGQUIT\n");
165 mDNS_Close(&mDNSStorage
);
169 #if COMPILER_LIKES_PRAGMA_MARK
170 #pragma mark ***** Parameter Checking
173 static mDNSBool
CheckThatRichTextHostNameIsUsable(const char *richTextHostName
, mDNSBool printExplanation
)
174 // Checks that richTextHostName is a reasonable host name
175 // label and, if it isn't and printExplanation is true, prints
176 // an explanation of why not.
179 domainlabel richLabel
;
180 domainlabel poorLabel
;
183 if (result
&& strlen(richTextHostName
) > 63) {
184 if (printExplanation
) {
186 "%s: Host name is too long (must be 63 characters or less)\n",
191 if (result
&& richTextHostName
[0] == 0) {
192 if (printExplanation
) {
193 fprintf(stderr
, "%s: Host name can't be empty\n", gProgramName
);
198 MakeDomainLabelFromLiteralString(&richLabel
, richTextHostName
);
199 ConvertUTF8PstringToRFC1034HostLabel(richLabel
.c
, &poorLabel
);
200 if (poorLabel
.c
[0] == 0) {
201 if (printExplanation
) {
203 "%s: Host name doesn't produce a usable RFC-1034 name\n",
212 static mDNSBool
CheckThatServiceTypeIsUsable(const char *serviceType
, mDNSBool printExplanation
)
213 // Checks that serviceType is a reasonable service type
214 // label and, if it isn't and printExplanation is true, prints
215 // an explanation of why not.
220 if (result
&& strlen(serviceType
) > 63) {
221 if (printExplanation
) {
223 "%s: Service type is too long (must be 63 characters or less)\n",
228 if (result
&& serviceType
[0] == 0) {
229 if (printExplanation
) {
231 "%s: Service type can't be empty\n",
239 static mDNSBool
CheckThatServiceTextIsUsable(const char *serviceText
, mDNSBool printExplanation
,
240 mDNSu8
*pStringList
, mDNSu16
*pStringListLen
)
241 // Checks that serviceText is a reasonable service text record
242 // and, if it isn't and printExplanation is true, prints
243 // an explanation of why not. Also parse the text into
244 // the packed PString buffer denoted by pStringList and
245 // return the length of that buffer in *pStringListLen.
246 // Note that this routine assumes that the buffer is
247 // sizeof(RDataBody) bytes long.
250 size_t serviceTextLen
;
252 // Note that parsing a C string into a PString list always
253 // expands the data by one character, so the following
254 // compare is ">=", not ">". Here's the logic:
256 // #1 For a string with not ^A's, the PString length is one
257 // greater than the C string length because we add a length
259 // #2 For every regular (not ^A) character you add to the C
260 // string, you add a regular character to the PString list.
261 // This does not affect the equivalence stated in #1.
262 // #3 For every ^A you add to the C string, you add a length
263 // byte to the PString list but you also eliminate the ^A,
264 // which again does not affect the equivalence stated in #1.
267 serviceTextLen
= strlen(serviceText
);
268 if (result
&& strlen(serviceText
) >= sizeof(RDataBody
)) {
269 if (printExplanation
) {
271 "%s: Service text record is too long (must be less than %d characters)\n",
273 (int) sizeof(RDataBody
) );
278 // Now break the string up into PStrings delimited by ^A.
279 // We know the data will fit so we can ignore buffer overrun concerns.
280 // However, we still have to treat runs long than 255 characters as
284 int lastPStringOffset
;
288 // This algorithm is a little tricky. We start by copying
289 // the string directly into the output buffer, shifted up by
290 // one byte. We then fill in the first byte with a ^A.
291 // We then walk backwards through the buffer and, for each
292 // ^A that we find, we replace it with the difference between
293 // its offset and the offset of the last ^A that we found
294 // (ie lastPStringOffset).
296 memcpy(&pStringList
[1], serviceText
, serviceTextLen
);
298 lastPStringOffset
= serviceTextLen
+ 1;
299 for (i
= serviceTextLen
; i
>= 0; i
--) {
300 if ( pStringList
[i
] == 1 ) {
301 thisPStringLen
= (lastPStringOffset
- i
- 1);
302 assert(thisPStringLen
>= 0);
303 if (thisPStringLen
> 255) {
305 if (printExplanation
) {
307 "%s: Each component of the service text record must be 255 characters or less\n",
312 pStringList
[i
] = thisPStringLen
;
313 lastPStringOffset
= i
;
318 *pStringListLen
= serviceTextLen
+ 1;
324 static mDNSBool
CheckThatPortNumberIsUsable(long portNumber
, mDNSBool printExplanation
)
325 // Checks that portNumber is a reasonable port number
326 // and, if it isn't and printExplanation is true, prints
327 // an explanation of why not.
332 if (result
&& (portNumber
<= 0 || portNumber
> 65535)) {
333 if (printExplanation
) {
335 "%s: Port number specified by -p must be in range 1..65535\n",
343 #if COMPILER_LIKES_PRAGMA_MARK
344 #pragma mark ***** Command Line Arguments
347 static const char kDefaultPIDFile
[] = "/var/run/mDNSResponder.pid";
348 static const char kDefaultServiceType
[] = "_afpovertcp._tcp.";
349 static const char kDefaultServiceDomain
[] = "local.";
351 kDefaultPortNumber
= 548
354 static void PrintUsage()
357 "Usage: %s [-v level ] [-r] [-n name] [-t type] [-d domain] [-x TXT] [-p port] [-f file] [-b] [-P pidfile]\n",
359 fprintf(stderr
, " -v verbose mode, level is a number from 0 to 2\n");
360 fprintf(stderr
, " 0 = no debugging info (default)\n");
361 fprintf(stderr
, " 1 = standard debugging info\n");
362 fprintf(stderr
, " 2 = intense debugging info\n");
363 fprintf(stderr
, " can be cycled kill -USR1\n");
364 fprintf(stderr
, " -r also bind to port 53 (port 5353 is always bound)\n");
365 fprintf(stderr
, " -n uses 'name' as the host name (default is none)\n");
366 fprintf(stderr
, " -t uses 'type' as the service type (default is '%s')\n", kDefaultServiceType
);
367 fprintf(stderr
, " -d uses 'domain' as the service domain (default is '%s')\n", kDefaultServiceDomain
);
368 fprintf(stderr
, " -x uses 'TXT' as the service TXT record (default is empty)\n");
369 fprintf(stderr
, " -p uses 'port' as the port number (default is '%d')\n", kDefaultPortNumber
);
370 fprintf(stderr
, " -f reads a service list from 'file'\n");
371 fprintf(stderr
, " -b forces daemon (background) mode\n");
372 fprintf(stderr
, " -P uses 'pidfile' as the PID file\n");
373 fprintf(stderr
, " (default is '%s')\n", kDefaultPIDFile
);
374 fprintf(stderr
, " only meaningful if -b also specified\n");
377 static mDNSBool gAvoidPort53
= mDNStrue
;
378 static const char *gRichTextHostName
= "";
379 static const char *gServiceType
= kDefaultServiceType
;
380 static const char *gServiceDomain
= kDefaultServiceDomain
;
381 static mDNSu8 gServiceText
[sizeof(RDataBody
)];
382 static mDNSu16 gServiceTextLen
= 0;
383 static int gPortNumber
= kDefaultPortNumber
;
384 static const char *gServiceFile
= "";
385 static mDNSBool gDaemon
= mDNSfalse
;
386 static const char *gPIDFile
= kDefaultPIDFile
;
388 static void ParseArguments(int argc
, char **argv
)
389 // Parses our command line arguments into the global variables
394 // Set gProgramName to the last path component of argv[0]
396 gProgramName
= strrchr(argv
[0], '/');
397 if (gProgramName
== NULL
) {
398 gProgramName
= argv
[0];
403 // Parse command line options using getopt.
406 ch
= getopt(argc
, argv
, "v:rn:t:d:x:p:f:dPb");
410 gMDNSPlatformPosixVerboseLevel
= atoi(optarg
);
411 if (gMDNSPlatformPosixVerboseLevel
< 0 || gMDNSPlatformPosixVerboseLevel
> 2) {
413 "%s: Verbose mode must be in the range 0..2\n",
419 gAvoidPort53
= mDNSfalse
;
422 gRichTextHostName
= optarg
;
423 if ( ! CheckThatRichTextHostNameIsUsable(gRichTextHostName
, mDNStrue
) ) {
428 gServiceType
= optarg
;
429 if ( ! CheckThatServiceTypeIsUsable(gServiceType
, mDNStrue
) ) {
434 gServiceDomain
= optarg
;
437 if ( ! CheckThatServiceTextIsUsable(optarg
, mDNStrue
, gServiceText
, &gServiceTextLen
) ) {
442 gPortNumber
= atol(optarg
);
443 if ( ! CheckThatPortNumberIsUsable(gPortNumber
, mDNStrue
) ) {
448 gServiceFile
= optarg
;
465 // Check for any left over command line arguments.
467 if (optind
!= argc
) {
469 fprintf(stderr
, "%s: Unexpected argument '%s'\n", gProgramName
, argv
[optind
]);
473 // Check for inconsistency between the arguments.
475 if ( (gRichTextHostName
[0] == 0) && (gServiceFile
[0] == 0) ) {
477 fprintf(stderr
, "%s: You must specify a service to register (-n) or a service file (-f).\n", gProgramName
);
482 #if COMPILER_LIKES_PRAGMA_MARK
483 #pragma mark ***** Registration
486 typedef struct PosixService PosixService
;
488 struct PosixService
{
489 ServiceRecordSet coreServ
;
494 static PosixService
*gServiceList
= NULL
;
496 static void RegistrationCallback(mDNS
*const m
, ServiceRecordSet
*const thisRegistration
, mStatus status
)
497 // mDNS core calls this routine to tell us about the status of
498 // our registration. The appropriate action to take depends
499 // entirely on the value of status.
503 case mStatus_NoError
:
504 debugf("Callback: %##s Name Registered", thisRegistration
->RR_SRV
.resrec
.name
.c
);
505 // Do nothing; our name was successfully registered. We may
506 // get more call backs in the future.
509 case mStatus_NameConflict
:
510 debugf("Callback: %##s Name Conflict", thisRegistration
->RR_SRV
.resrec
.name
.c
);
512 // In the event of a conflict, this sample RegistrationCallback
513 // just calls mDNS_RenameAndReregisterService to automatically
514 // pick a new unique name for the service. For a device such as a
515 // printer, this may be appropriate. For a device with a user
516 // interface, and a screen, and a keyboard, the appropriate response
517 // may be to prompt the user and ask them to choose a new name for
520 // Also, what do we do if mDNS_RenameAndReregisterService returns an
521 // error. Right now I have no place to send that error to.
523 status
= mDNS_RenameAndReregisterService(m
, thisRegistration
, mDNSNULL
);
524 assert(status
== mStatus_NoError
);
527 case mStatus_MemFree
:
528 debugf("Callback: %##s Memory Free", thisRegistration
->RR_SRV
.resrec
.name
.c
);
530 // When debugging is enabled, make sure that thisRegistration
531 // is not on our gServiceList.
535 PosixService
*cursor
;
537 cursor
= gServiceList
;
538 while (cursor
!= NULL
) {
539 assert(&cursor
->coreServ
!= thisRegistration
);
540 cursor
= cursor
->next
;
544 free(thisRegistration
);
548 debugf("Callback: %##s Unknown Status %d", thisRegistration
->RR_SRV
.resrec
.name
.c
, status
);
553 static int gServiceID
= 0;
555 static mStatus
RegisterOneService(const char * richTextHostName
,
556 const char * serviceType
,
557 const char * serviceDomain
,
563 PosixService
* thisServ
;
569 status
= mStatus_NoError
;
570 thisServ
= (PosixService
*) malloc(sizeof(*thisServ
));
571 if (thisServ
== NULL
) {
572 status
= mStatus_NoMemoryErr
;
574 if (status
== mStatus_NoError
) {
575 MakeDomainLabelFromLiteralString(&name
, richTextHostName
);
576 MakeDomainNameFromDNSNameString(&type
, serviceType
);
577 MakeDomainNameFromDNSNameString(&domain
, serviceDomain
);
578 port
.b
[0] = (portNumber
>> 8) & 0x0FF;
579 port
.b
[1] = (portNumber
>> 0) & 0x0FF;;
580 status
= mDNS_RegisterService(&mDNSStorage
, &thisServ
->coreServ
,
581 &name
, &type
, &domain
, // Name, type, domain
582 NULL
, port
, // Host and port
583 text
, textLen
, // TXT data, length
585 mDNSInterface_Any
, // Interace ID
586 RegistrationCallback
, thisServ
); // Callback and context
588 if (status
== mStatus_NoError
) {
589 thisServ
->serviceID
= gServiceID
;
592 thisServ
->next
= gServiceList
;
593 gServiceList
= thisServ
;
595 if (gMDNSPlatformPosixVerboseLevel
> 0) {
597 "%s: Registered service %d, name '%s', type '%s', port %ld\n",
605 if (thisServ
!= NULL
) {
612 static mDNSBool
ReadALine(char *buf
, size_t bufSize
, FILE *fp
)
617 good
= (fgets(buf
, bufSize
, fp
) != NULL
);
620 good
= (len
> 0 && buf
[len
- 1] == '\n');
628 static mStatus
RegisterServicesInFile(const char *filePath
)
637 const char *dom
= kDefaultServiceDomain
;
639 mDNSu8 text
[sizeof(RDataBody
)];
643 status
= mStatus_NoError
;
644 fp
= fopen(filePath
, "r");
646 status
= mStatus_UnknownErr
;
648 if (status
== mStatus_NoError
) {
651 // Skip over any blank lines.
654 } while ( ch
== '\n' || ch
== '\r' );
656 good
= (ungetc(ch
, fp
) == ch
);
659 // Read three lines, check them for validity, and register the service.
660 if ( good
&& ! feof(fp
) ) {
661 good
= ReadALine(name
, sizeof(name
), fp
);
663 good
= ReadALine(type
, sizeof(type
), fp
);
667 while (*p
&& *p
!= ' ') p
++;
674 good
= ReadALine(rawText
, sizeof(rawText
), fp
);
677 good
= ReadALine(port
, sizeof(port
), fp
);
680 good
= CheckThatRichTextHostNameIsUsable(name
, mDNSfalse
)
681 && CheckThatServiceTypeIsUsable(type
, mDNSfalse
)
682 && CheckThatServiceTextIsUsable(rawText
, mDNSfalse
, text
, &textLen
)
683 && CheckThatPortNumberIsUsable(atol(port
), mDNSfalse
);
686 status
= RegisterOneService(name
, type
, dom
, text
, textLen
, atol(port
));
687 if (status
!= mStatus_NoError
) {
689 "%s: Failed to register service, name = %s, type = %s, port = %s\n",
694 status
= mStatus_NoError
; // keep reading
698 } while (good
&& !feof(fp
));
701 fprintf(stderr
, "%s: Error reading service file %s\n", gProgramName
, gServiceFile
);
713 static mStatus
RegisterOurServices(void)
717 status
= mStatus_NoError
;
718 if (gRichTextHostName
[0] != 0) {
719 status
= RegisterOneService(gRichTextHostName
,
722 gServiceText
, gServiceTextLen
,
725 if (status
== mStatus_NoError
&& gServiceFile
[0] != 0) {
726 status
= RegisterServicesInFile(gServiceFile
);
731 static void DeregisterOurServices(void)
733 PosixService
*thisServ
;
736 while (gServiceList
!= NULL
) {
737 thisServ
= gServiceList
;
738 gServiceList
= thisServ
->next
;
740 thisServID
= thisServ
->serviceID
;
742 mDNS_DeregisterService(&mDNSStorage
, &thisServ
->coreServ
);
744 if (gMDNSPlatformPosixVerboseLevel
> 0) {
746 "%s: Deregistered service %d\n",
748 thisServ
->serviceID
);
753 #if COMPILER_LIKES_PRAGMA_MARK
754 #pragma mark **** Main
757 #ifdef NOT_HAVE_DAEMON
759 // The version of Solaris that I tested on didn't have the daemon
760 // call. This implementation was basically stolen from the
761 // Mac OS X standard C library.
763 static int daemon(int nochdir
, int noclose
)
782 if (!noclose
&& (fd
= _open("/dev/null", O_RDWR
, 0)) != -1) {
783 (void)dup2(fd
, STDIN_FILENO
);
784 (void)dup2(fd
, STDOUT_FILENO
);
785 (void)dup2(fd
, STDERR_FILENO
);
792 #endif /* NOT_HAVE_DAEMON */
794 int main(int argc
, char **argv
)
799 // Parse our command line arguments. This won't come back if there's an error.
801 ParseArguments(argc
, argv
);
803 // If we're told to run as a daemon, then do that straight away.
804 // Note that we don't treat the inability to create our PID
805 // file as an error. Also note that we assign getpid to a long
806 // because printf has no format specified for pid_t.
809 if (gMDNSPlatformPosixVerboseLevel
> 0) {
810 fprintf(stderr
, "%s: Starting in daemon mode\n", gProgramName
);
817 fp
= fopen(gPIDFile
, "w");
819 fprintf(fp
, "%ld\n", (long) getpid());
825 if (gMDNSPlatformPosixVerboseLevel
> 0) {
826 fprintf(stderr
, "%s: Starting in foreground mode, PID %ld\n", gProgramName
, (long) getpid());
830 status
= mDNS_Init(&mDNSStorage
, &PlatformStorage
,
831 mDNS_Init_NoCache
, mDNS_Init_ZeroCacheSize
,
832 mDNS_Init_AdvertiseLocalAddresses
,
833 mDNS_Init_NoInitCallback
, mDNS_Init_NoInitCallbackContext
);
834 if (status
!= mStatus_NoError
) return(2);
836 status
= RegisterOurServices();
837 if (status
!= mStatus_NoError
) return(2);
839 signal(SIGHUP
, HandleSigHup
); // SIGHUP has to be sent by kill -HUP <pid>
840 signal(SIGINT
, HandleSigInt
); // SIGINT is what you get for a Ctrl-C
841 signal(SIGQUIT
, HandleSigQuit
); // SIGQUIT is what you get for a Ctrl-\ (indeed)
842 signal(SIGUSR1
, HandleSigUsr1
); // SIGUSR1 has to be sent by kill -USR1 <pid>
848 struct timeval timeout
;
851 // 1. Set up the fd_set as usual here.
852 // This example client has no file descriptors of its own,
853 // but a real application would call FD_SET to add them to the set here
856 // 2. Set up the timeout.
857 // This example client has no other work it needs to be doing,
858 // so we set an effectively infinite timeout
859 timeout
.tv_sec
= 0x3FFFFFFF;
862 // 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
863 mDNSPosixGetFDSet(&mDNSStorage
, &nfds
, &readfds
, &timeout
);
865 // 4. Call select as normal
866 verbosedebugf("select(%d, %d.%06d)", nfds
, timeout
.tv_sec
, timeout
.tv_usec
);
867 result
= select(nfds
, &readfds
, NULL
, NULL
, &timeout
);
871 verbosedebugf("select() returned %d errno %d", result
, errno
);
872 if (errno
!= EINTR
) gStopNow
= mDNStrue
;
875 if (gReceivedSigUsr1
)
877 gReceivedSigUsr1
= mDNSfalse
;
878 gMDNSPlatformPosixVerboseLevel
+= 1;
879 if (gMDNSPlatformPosixVerboseLevel
> 2)
880 gMDNSPlatformPosixVerboseLevel
= 0;
881 if ( gMDNSPlatformPosixVerboseLevel
> 0 )
882 fprintf(stderr
, "\nVerbose level %d\n", gMDNSPlatformPosixVerboseLevel
);
886 if (gMDNSPlatformPosixVerboseLevel
> 0)
887 fprintf(stderr
, "\nSIGHUP\n");
888 gReceivedSigHup
= mDNSfalse
;
889 DeregisterOurServices();
890 status
= mDNSPlatformPosixRefreshInterfaceList(&mDNSStorage
);
891 if (status
!= mStatus_NoError
) break;
892 status
= RegisterOurServices();
893 if (status
!= mStatus_NoError
) break;
899 // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
900 mDNSPosixProcessFDSet(&mDNSStorage
, &readfds
);
902 // 6. This example client has no other work it needs to be doing,
903 // but a real client would do its work here
910 DeregisterOurServices();
911 mDNS_Close(&mDNSStorage
);
913 if (status
== mStatus_NoError
) {
918 if ( (result
!= 0) || (gMDNSPlatformPosixVerboseLevel
> 0) ) {
919 fprintf(stderr
, "%s: Finished with status %ld, result %d\n", gProgramName
, status
, result
);