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.2.1 2004/04/07 23:51:09 cheshire
27 Remove obsolete comments referring to doing mDNS on port 53
29 Revision 1.16 2003/08/14 02:19:55 cheshire
30 <rdar://problem/3375491> Split generic ResourceRecord type into two separate types: AuthRecord and CacheRecord
32 Revision 1.15 2003/08/12 19:56:26 cheshire
35 Revision 1.14 2003/08/06 18:20:51 cheshire
38 Revision 1.13 2003/07/23 00:00:04 cheshire
41 Revision 1.12 2003/07/15 01:55:16 cheshire
42 <rdar://problem/3315777> Need to implement service registration with subtypes
44 Revision 1.11 2003/07/14 18:11:54 cheshire
45 Fix stricter compiler warnings
47 Revision 1.10 2003/07/10 20:27:31 cheshire
48 <rdar://problem/3318717> mDNSResponder Posix version is missing a 'b' in the getopt option string
50 Revision 1.9 2003/07/02 21:19:59 cheshire
51 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
53 Revision 1.8 2003/06/18 05:48:41 cheshire
56 Revision 1.7 2003/05/06 00:00:50 cheshire
57 <rdar://problem/3248914> Rationalize naming of domainname manipulation functions
59 Revision 1.6 2003/03/08 00:35:56 cheshire
60 Switched to using new "mDNS_Execute" model (see "mDNSCore/Implementer Notes.txt")
62 Revision 1.5 2003/02/20 06:48:36 cheshire
63 Bug #: 3169535 Xserve RAID needs to do interface-specific registrations
64 Reviewed by: Josh Graessley, Bob Bradley
66 Revision 1.4 2003/01/28 03:07:46 cheshire
67 Add extra parameter to mDNS_RenameAndReregisterService(),
68 and add support for specifying a domain other than dot-local.
70 Revision 1.3 2002/09/21 20:44:53 zarzycki
73 Revision 1.2 2002/09/19 04:20:44 cheshire
74 Remove high-ascii characters that confuse some systems
76 Revision 1.1 2002/09/17 06:24:35 cheshire
81 #include "mDNSClientAPI.h"// Defines the interface to the client layer above
82 #include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
85 #include <stdio.h> // For printf()
86 #include <stdlib.h> // For exit() etc.
87 #include <string.h> // For strlen() etc.
88 #include <unistd.h> // For select()
89 #include <errno.h> // For errno, EINTR
93 #if COMPILER_LIKES_PRAGMA_MARK
94 #pragma mark ***** Globals
97 static mDNS mDNSStorage
; // mDNS core uses this to store its globals
98 static mDNS_PlatformSupport PlatformStorage
; // Stores this platform's globals
100 static const char *gProgramName
= "mDNSResponderPosix";
102 #if COMPILER_LIKES_PRAGMA_MARK
103 #pragma mark ***** Signals
106 static volatile mDNSBool gReceivedSigUsr1
;
107 static volatile mDNSBool gReceivedSigHup
;
108 static volatile mDNSBool gStopNow
;
110 // We support 4 signals.
112 // o SIGUSR1 toggles verbose mode on and off in debug builds
113 // o SIGHUP triggers the program to re-read its preferences.
114 // o SIGINT causes an orderly shutdown of the program.
115 // o SIGQUIT causes a somewhat orderly shutdown (direct but dangerous)
116 // o SIGKILL kills us dead (easy to implement :-)
118 // There are fatal race conditions in our signal handling, but there's not much
119 // we can do about them while remaining within the Posix space. Specifically,
120 // if a signal arrives after we test the globals its sets but before we call
121 // select, the signal will be dropped. The user will have to send the signal
122 // again. Unfortunately, Posix does not have a "sigselect" to atomically
123 // modify the signal mask and start a select.
125 static void HandleSigUsr1(int sigraised
)
126 // If we get a SIGUSR1 we toggle the state of the
129 assert(sigraised
== SIGUSR1
);
130 gReceivedSigUsr1
= mDNStrue
;
133 static void HandleSigHup(int sigraised
)
134 // A handler for SIGHUP that causes us to break out of the
135 // main event loop when the user kill 1's us. This has the
136 // effect of triggered the main loop to deregister the
137 // current services and re-read the preferences.
139 assert(sigraised
== SIGHUP
);
140 gReceivedSigHup
= mDNStrue
;
143 static void HandleSigInt(int sigraised
)
144 // A handler for SIGINT that causes us to break out of the
145 // main event loop when the user types ^C. This has the
146 // effect of quitting the program.
148 assert(sigraised
== SIGINT
);
150 if (gMDNSPlatformPosixVerboseLevel
> 0) {
151 fprintf(stderr
, "\nSIGINT\n");
156 static void HandleSigQuit(int sigraised
)
157 // If we get a SIGQUIT the user is desperate and we
158 // just call mDNS_Close directly. This is definitely
159 // not safe (because it could reenter mDNS), but
160 // we presume that the user has already tried the safe
163 assert(sigraised
== SIGQUIT
);
165 if (gMDNSPlatformPosixVerboseLevel
> 0) {
166 fprintf(stderr
, "\nSIGQUIT\n");
168 mDNS_Close(&mDNSStorage
);
172 #if COMPILER_LIKES_PRAGMA_MARK
173 #pragma mark ***** Parameter Checking
176 static mDNSBool
CheckThatRichTextHostNameIsUsable(const char *richTextHostName
, mDNSBool printExplanation
)
177 // Checks that richTextHostName is a reasonable host name
178 // label and, if it isn't and printExplanation is true, prints
179 // an explanation of why not.
182 domainlabel richLabel
;
183 domainlabel poorLabel
;
186 if (result
&& strlen(richTextHostName
) > 63) {
187 if (printExplanation
) {
189 "%s: Host name is too long (must be 63 characters or less)\n",
194 if (result
&& richTextHostName
[0] == 0) {
195 if (printExplanation
) {
196 fprintf(stderr
, "%s: Host name can't be empty\n", gProgramName
);
201 MakeDomainLabelFromLiteralString(&richLabel
, richTextHostName
);
202 ConvertUTF8PstringToRFC1034HostLabel(richLabel
.c
, &poorLabel
);
203 if (poorLabel
.c
[0] == 0) {
204 if (printExplanation
) {
206 "%s: Host name doesn't produce a usable RFC-1034 name\n",
215 static mDNSBool
CheckThatServiceTypeIsUsable(const char *serviceType
, mDNSBool printExplanation
)
216 // Checks that serviceType is a reasonable service type
217 // label and, if it isn't and printExplanation is true, prints
218 // an explanation of why not.
223 if (result
&& strlen(serviceType
) > 63) {
224 if (printExplanation
) {
226 "%s: Service type is too long (must be 63 characters or less)\n",
231 if (result
&& serviceType
[0] == 0) {
232 if (printExplanation
) {
234 "%s: Service type can't be empty\n",
242 static mDNSBool
CheckThatServiceTextIsUsable(const char *serviceText
, mDNSBool printExplanation
,
243 mDNSu8
*pStringList
, mDNSu16
*pStringListLen
)
244 // Checks that serviceText is a reasonable service text record
245 // and, if it isn't and printExplanation is true, prints
246 // an explanation of why not. Also parse the text into
247 // the packed PString buffer denoted by pStringList and
248 // return the length of that buffer in *pStringListLen.
249 // Note that this routine assumes that the buffer is
250 // sizeof(RDataBody) bytes long.
253 size_t serviceTextLen
;
255 // Note that parsing a C string into a PString list always
256 // expands the data by one character, so the following
257 // compare is ">=", not ">". Here's the logic:
259 // #1 For a string with not ^A's, the PString length is one
260 // greater than the C string length because we add a length
262 // #2 For every regular (not ^A) character you add to the C
263 // string, you add a regular character to the PString list.
264 // This does not affect the equivalence stated in #1.
265 // #3 For every ^A you add to the C string, you add a length
266 // byte to the PString list but you also eliminate the ^A,
267 // which again does not affect the equivalence stated in #1.
270 serviceTextLen
= strlen(serviceText
);
271 if (result
&& strlen(serviceText
) >= sizeof(RDataBody
)) {
272 if (printExplanation
) {
274 "%s: Service text record is too long (must be less than %d characters)\n",
276 (int) sizeof(RDataBody
) );
281 // Now break the string up into PStrings delimited by ^A.
282 // We know the data will fit so we can ignore buffer overrun concerns.
283 // However, we still have to treat runs long than 255 characters as
287 int lastPStringOffset
;
291 // This algorithm is a little tricky. We start by copying
292 // the string directly into the output buffer, shifted up by
293 // one byte. We then fill in the first byte with a ^A.
294 // We then walk backwards through the buffer and, for each
295 // ^A that we find, we replace it with the difference between
296 // its offset and the offset of the last ^A that we found
297 // (ie lastPStringOffset).
299 memcpy(&pStringList
[1], serviceText
, serviceTextLen
);
301 lastPStringOffset
= serviceTextLen
+ 1;
302 for (i
= serviceTextLen
; i
>= 0; i
--) {
303 if ( pStringList
[i
] == 1 ) {
304 thisPStringLen
= (lastPStringOffset
- i
- 1);
305 assert(thisPStringLen
>= 0);
306 if (thisPStringLen
> 255) {
308 if (printExplanation
) {
310 "%s: Each component of the service text record must be 255 characters or less\n",
315 pStringList
[i
] = thisPStringLen
;
316 lastPStringOffset
= i
;
321 *pStringListLen
= serviceTextLen
+ 1;
327 static mDNSBool
CheckThatPortNumberIsUsable(long portNumber
, mDNSBool printExplanation
)
328 // Checks that portNumber is a reasonable port number
329 // and, if it isn't and printExplanation is true, prints
330 // an explanation of why not.
335 if (result
&& (portNumber
<= 0 || portNumber
> 65535)) {
336 if (printExplanation
) {
338 "%s: Port number specified by -p must be in range 1..65535\n",
346 #if COMPILER_LIKES_PRAGMA_MARK
347 #pragma mark ***** Command Line Arguments
350 static const char kDefaultPIDFile
[] = "/var/run/mDNSResponder.pid";
351 static const char kDefaultServiceType
[] = "_afpovertcp._tcp.";
352 static const char kDefaultServiceDomain
[] = "local.";
354 kDefaultPortNumber
= 548
357 static void PrintUsage()
360 "Usage: %s [-v level ] [-n name] [-t type] [-d domain] [-x TXT] [-p port] [-f file] [-b] [-P pidfile]\n",
362 fprintf(stderr
, " -v verbose mode, level is a number from 0 to 2\n");
363 fprintf(stderr
, " 0 = no debugging info (default)\n");
364 fprintf(stderr
, " 1 = standard debugging info\n");
365 fprintf(stderr
, " 2 = intense debugging info\n");
366 fprintf(stderr
, " can be cycled kill -USR1\n");
367 fprintf(stderr
, " -n uses 'name' as the host name (default is none)\n");
368 fprintf(stderr
, " -t uses 'type' as the service type (default is '%s')\n", kDefaultServiceType
);
369 fprintf(stderr
, " -d uses 'domain' as the service domain (default is '%s')\n", kDefaultServiceDomain
);
370 fprintf(stderr
, " -x uses 'TXT' as the service TXT record (default is empty)\n");
371 fprintf(stderr
, " -p uses 'port' as the port number (default is '%d')\n", kDefaultPortNumber
);
372 fprintf(stderr
, " -f reads a service list from 'file'\n");
373 fprintf(stderr
, " -b forces daemon (background) mode\n");
374 fprintf(stderr
, " -P uses 'pidfile' as the PID file\n");
375 fprintf(stderr
, " (default is '%s')\n", kDefaultPIDFile
);
376 fprintf(stderr
, " only meaningful if -b also specified\n");
379 static const char *gRichTextHostName
= "";
380 static const char *gServiceType
= kDefaultServiceType
;
381 static const char *gServiceDomain
= kDefaultServiceDomain
;
382 static mDNSu8 gServiceText
[sizeof(RDataBody
)];
383 static mDNSu16 gServiceTextLen
= 0;
384 static int gPortNumber
= kDefaultPortNumber
;
385 static const char *gServiceFile
= "";
386 static mDNSBool gDaemon
= mDNSfalse
;
387 static const char *gPIDFile
= kDefaultPIDFile
;
389 static void ParseArguments(int argc
, char **argv
)
390 // Parses our command line arguments into the global variables
395 // Set gProgramName to the last path component of argv[0]
397 gProgramName
= strrchr(argv
[0], '/');
398 if (gProgramName
== NULL
) {
399 gProgramName
= argv
[0];
404 // Parse command line options using getopt.
407 ch
= getopt(argc
, argv
, "v:rn:t:d:x:p:f:dPb");
411 gMDNSPlatformPosixVerboseLevel
= atoi(optarg
);
412 if (gMDNSPlatformPosixVerboseLevel
< 0 || gMDNSPlatformPosixVerboseLevel
> 2) {
414 "%s: Verbose mode must be in the range 0..2\n",
420 gRichTextHostName
= optarg
;
421 if ( ! CheckThatRichTextHostNameIsUsable(gRichTextHostName
, mDNStrue
) ) {
426 gServiceType
= optarg
;
427 if ( ! CheckThatServiceTypeIsUsable(gServiceType
, mDNStrue
) ) {
432 gServiceDomain
= optarg
;
435 if ( ! CheckThatServiceTextIsUsable(optarg
, mDNStrue
, gServiceText
, &gServiceTextLen
) ) {
440 gPortNumber
= atol(optarg
);
441 if ( ! CheckThatPortNumberIsUsable(gPortNumber
, mDNStrue
) ) {
446 gServiceFile
= optarg
;
463 // Check for any left over command line arguments.
465 if (optind
!= argc
) {
467 fprintf(stderr
, "%s: Unexpected argument '%s'\n", gProgramName
, argv
[optind
]);
471 // Check for inconsistency between the arguments.
473 if ( (gRichTextHostName
[0] == 0) && (gServiceFile
[0] == 0) ) {
475 fprintf(stderr
, "%s: You must specify a service to register (-n) or a service file (-f).\n", gProgramName
);
480 #if COMPILER_LIKES_PRAGMA_MARK
481 #pragma mark ***** Registration
484 typedef struct PosixService PosixService
;
486 struct PosixService
{
487 ServiceRecordSet coreServ
;
492 static PosixService
*gServiceList
= NULL
;
494 static void RegistrationCallback(mDNS
*const m
, ServiceRecordSet
*const thisRegistration
, mStatus status
)
495 // mDNS core calls this routine to tell us about the status of
496 // our registration. The appropriate action to take depends
497 // entirely on the value of status.
501 case mStatus_NoError
:
502 debugf("Callback: %##s Name Registered", thisRegistration
->RR_SRV
.resrec
.name
.c
);
503 // Do nothing; our name was successfully registered. We may
504 // get more call backs in the future.
507 case mStatus_NameConflict
:
508 debugf("Callback: %##s Name Conflict", thisRegistration
->RR_SRV
.resrec
.name
.c
);
510 // In the event of a conflict, this sample RegistrationCallback
511 // just calls mDNS_RenameAndReregisterService to automatically
512 // pick a new unique name for the service. For a device such as a
513 // printer, this may be appropriate. For a device with a user
514 // interface, and a screen, and a keyboard, the appropriate response
515 // may be to prompt the user and ask them to choose a new name for
518 // Also, what do we do if mDNS_RenameAndReregisterService returns an
519 // error. Right now I have no place to send that error to.
521 status
= mDNS_RenameAndReregisterService(m
, thisRegistration
, mDNSNULL
);
522 assert(status
== mStatus_NoError
);
525 case mStatus_MemFree
:
526 debugf("Callback: %##s Memory Free", thisRegistration
->RR_SRV
.resrec
.name
.c
);
528 // When debugging is enabled, make sure that thisRegistration
529 // is not on our gServiceList.
533 PosixService
*cursor
;
535 cursor
= gServiceList
;
536 while (cursor
!= NULL
) {
537 assert(&cursor
->coreServ
!= thisRegistration
);
538 cursor
= cursor
->next
;
542 free(thisRegistration
);
546 debugf("Callback: %##s Unknown Status %d", thisRegistration
->RR_SRV
.resrec
.name
.c
, status
);
551 static int gServiceID
= 0;
553 static mStatus
RegisterOneService(const char * richTextHostName
,
554 const char * serviceType
,
555 const char * serviceDomain
,
561 PosixService
* thisServ
;
567 status
= mStatus_NoError
;
568 thisServ
= (PosixService
*) malloc(sizeof(*thisServ
));
569 if (thisServ
== NULL
) {
570 status
= mStatus_NoMemoryErr
;
572 if (status
== mStatus_NoError
) {
573 MakeDomainLabelFromLiteralString(&name
, richTextHostName
);
574 MakeDomainNameFromDNSNameString(&type
, serviceType
);
575 MakeDomainNameFromDNSNameString(&domain
, serviceDomain
);
576 port
.b
[0] = (portNumber
>> 8) & 0x0FF;
577 port
.b
[1] = (portNumber
>> 0) & 0x0FF;;
578 status
= mDNS_RegisterService(&mDNSStorage
, &thisServ
->coreServ
,
579 &name
, &type
, &domain
, // Name, type, domain
580 NULL
, port
, // Host and port
581 text
, textLen
, // TXT data, length
583 mDNSInterface_Any
, // Interace ID
584 RegistrationCallback
, thisServ
); // Callback and context
586 if (status
== mStatus_NoError
) {
587 thisServ
->serviceID
= gServiceID
;
590 thisServ
->next
= gServiceList
;
591 gServiceList
= thisServ
;
593 if (gMDNSPlatformPosixVerboseLevel
> 0) {
595 "%s: Registered service %d, name '%s', type '%s', port %ld\n",
603 if (thisServ
!= NULL
) {
610 static mDNSBool
ReadALine(char *buf
, size_t bufSize
, FILE *fp
)
615 good
= (fgets(buf
, bufSize
, fp
) != NULL
);
618 good
= (len
> 0 && buf
[len
- 1] == '\n');
626 static mStatus
RegisterServicesInFile(const char *filePath
)
635 const char *dom
= kDefaultServiceDomain
;
637 mDNSu8 text
[sizeof(RDataBody
)];
641 status
= mStatus_NoError
;
642 fp
= fopen(filePath
, "r");
644 status
= mStatus_UnknownErr
;
646 if (status
== mStatus_NoError
) {
649 // Skip over any blank lines.
652 } while ( ch
== '\n' || ch
== '\r' );
654 good
= (ungetc(ch
, fp
) == ch
);
657 // Read three lines, check them for validity, and register the service.
658 if ( good
&& ! feof(fp
) ) {
659 good
= ReadALine(name
, sizeof(name
), fp
);
661 good
= ReadALine(type
, sizeof(type
), fp
);
665 while (*p
&& *p
!= ' ') p
++;
672 good
= ReadALine(rawText
, sizeof(rawText
), fp
);
675 good
= ReadALine(port
, sizeof(port
), fp
);
678 good
= CheckThatRichTextHostNameIsUsable(name
, mDNSfalse
)
679 && CheckThatServiceTypeIsUsable(type
, mDNSfalse
)
680 && CheckThatServiceTextIsUsable(rawText
, mDNSfalse
, text
, &textLen
)
681 && CheckThatPortNumberIsUsable(atol(port
), mDNSfalse
);
684 status
= RegisterOneService(name
, type
, dom
, text
, textLen
, atol(port
));
685 if (status
!= mStatus_NoError
) {
687 "%s: Failed to register service, name = %s, type = %s, port = %s\n",
692 status
= mStatus_NoError
; // keep reading
696 } while (good
&& !feof(fp
));
699 fprintf(stderr
, "%s: Error reading service file %s\n", gProgramName
, gServiceFile
);
711 static mStatus
RegisterOurServices(void)
715 status
= mStatus_NoError
;
716 if (gRichTextHostName
[0] != 0) {
717 status
= RegisterOneService(gRichTextHostName
,
720 gServiceText
, gServiceTextLen
,
723 if (status
== mStatus_NoError
&& gServiceFile
[0] != 0) {
724 status
= RegisterServicesInFile(gServiceFile
);
729 static void DeregisterOurServices(void)
731 PosixService
*thisServ
;
734 while (gServiceList
!= NULL
) {
735 thisServ
= gServiceList
;
736 gServiceList
= thisServ
->next
;
738 thisServID
= thisServ
->serviceID
;
740 mDNS_DeregisterService(&mDNSStorage
, &thisServ
->coreServ
);
742 if (gMDNSPlatformPosixVerboseLevel
> 0) {
744 "%s: Deregistered service %d\n",
746 thisServ
->serviceID
);
751 #if COMPILER_LIKES_PRAGMA_MARK
752 #pragma mark **** Main
755 #ifdef NOT_HAVE_DAEMON
757 // The version of Solaris that I tested on didn't have the daemon
758 // call. This implementation was basically stolen from the
759 // Mac OS X standard C library.
761 static int daemon(int nochdir
, int noclose
)
780 if (!noclose
&& (fd
= _open("/dev/null", O_RDWR
, 0)) != -1) {
781 (void)dup2(fd
, STDIN_FILENO
);
782 (void)dup2(fd
, STDOUT_FILENO
);
783 (void)dup2(fd
, STDERR_FILENO
);
790 #endif /* NOT_HAVE_DAEMON */
792 int main(int argc
, char **argv
)
797 // Parse our command line arguments. This won't come back if there's an error.
799 ParseArguments(argc
, argv
);
801 // If we're told to run as a daemon, then do that straight away.
802 // Note that we don't treat the inability to create our PID
803 // file as an error. Also note that we assign getpid to a long
804 // because printf has no format specified for pid_t.
807 if (gMDNSPlatformPosixVerboseLevel
> 0) {
808 fprintf(stderr
, "%s: Starting in daemon mode\n", gProgramName
);
815 fp
= fopen(gPIDFile
, "w");
817 fprintf(fp
, "%ld\n", (long) getpid());
823 if (gMDNSPlatformPosixVerboseLevel
> 0) {
824 fprintf(stderr
, "%s: Starting in foreground mode, PID %ld\n", gProgramName
, (long) getpid());
828 status
= mDNS_Init(&mDNSStorage
, &PlatformStorage
,
829 mDNS_Init_NoCache
, mDNS_Init_ZeroCacheSize
,
830 mDNS_Init_AdvertiseLocalAddresses
,
831 mDNS_Init_NoInitCallback
, mDNS_Init_NoInitCallbackContext
);
832 if (status
!= mStatus_NoError
) return(2);
834 status
= RegisterOurServices();
835 if (status
!= mStatus_NoError
) return(2);
837 signal(SIGHUP
, HandleSigHup
); // SIGHUP has to be sent by kill -HUP <pid>
838 signal(SIGINT
, HandleSigInt
); // SIGINT is what you get for a Ctrl-C
839 signal(SIGQUIT
, HandleSigQuit
); // SIGQUIT is what you get for a Ctrl-\ (indeed)
840 signal(SIGUSR1
, HandleSigUsr1
); // SIGUSR1 has to be sent by kill -USR1 <pid>
846 struct timeval timeout
;
849 // 1. Set up the fd_set as usual here.
850 // This example client has no file descriptors of its own,
851 // but a real application would call FD_SET to add them to the set here
854 // 2. Set up the timeout.
855 // This example client has no other work it needs to be doing,
856 // so we set an effectively infinite timeout
857 timeout
.tv_sec
= 0x3FFFFFFF;
860 // 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
861 mDNSPosixGetFDSet(&mDNSStorage
, &nfds
, &readfds
, &timeout
);
863 // 4. Call select as normal
864 verbosedebugf("select(%d, %d.%06d)", nfds
, timeout
.tv_sec
, timeout
.tv_usec
);
865 result
= select(nfds
, &readfds
, NULL
, NULL
, &timeout
);
869 verbosedebugf("select() returned %d errno %d", result
, errno
);
870 if (errno
!= EINTR
) gStopNow
= mDNStrue
;
873 if (gReceivedSigUsr1
)
875 gReceivedSigUsr1
= mDNSfalse
;
876 gMDNSPlatformPosixVerboseLevel
+= 1;
877 if (gMDNSPlatformPosixVerboseLevel
> 2)
878 gMDNSPlatformPosixVerboseLevel
= 0;
879 if ( gMDNSPlatformPosixVerboseLevel
> 0 )
880 fprintf(stderr
, "\nVerbose level %d\n", gMDNSPlatformPosixVerboseLevel
);
884 if (gMDNSPlatformPosixVerboseLevel
> 0)
885 fprintf(stderr
, "\nSIGHUP\n");
886 gReceivedSigHup
= mDNSfalse
;
887 DeregisterOurServices();
888 status
= mDNSPlatformPosixRefreshInterfaceList(&mDNSStorage
);
889 if (status
!= mStatus_NoError
) break;
890 status
= RegisterOurServices();
891 if (status
!= mStatus_NoError
) break;
897 // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
898 mDNSPosixProcessFDSet(&mDNSStorage
, &readfds
);
900 // 6. This example client has no other work it needs to be doing,
901 // but a real client would do its work here
908 DeregisterOurServices();
909 mDNS_Close(&mDNSStorage
);
911 if (status
== mStatus_NoError
) {
916 if ( (result
!= 0) || (gMDNSPlatformPosixVerboseLevel
> 0) ) {
917 fprintf(stderr
, "%s: Finished with status %ld, result %d\n", gProgramName
, status
, result
);