]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSPosix/ExampleClientApp.c
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):
25 $Log: ExampleClientApp.c,v $
26 Revision 1.9 2003/08/12 19:56:26 cheshire
29 Revision 1.8 2003/07/02 21:19:58 cheshire
30 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
32 Revision 1.7 2003/06/18 05:48:41 cheshire
35 Revision 1.6 2003/03/31 22:44:36 cheshire
40 #include <stdio.h> // For printf()
41 #include <stdlib.h> // For exit() etc.
42 #include <string.h> // For strlen() etc.
43 #include <unistd.h> // For select()
44 #include <errno.h> // For errno, EINTR
45 #include <arpa/inet.h> // For inet_addr()
46 #include <netinet/in.h> // For INADDR_NONE
47 #include <netdb.h> // For gethostbyname()
48 #include <signal.h> // For SIGINT, etc.
50 #include "mDNSClientAPI.h" // Defines the interface to the client layer above
51 #include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
53 //*******************************************************************************************
56 static volatile mDNSBool StopNow
;
58 mDNSlocal
void HandleSIG(int signal
)
60 (void)signal
; // Unused
66 mDNSexport
void ExampleClientEventLoop(mDNS
*const m
)
68 signal(SIGINT
, HandleSIG
); // SIGINT is what you get for a Ctrl-C
69 signal(SIGTERM
, HandleSIG
);
75 struct timeval timeout
;
78 // 1. Set up the fd_set as usual here.
79 // This example client has no file descriptors of its own,
80 // but a real application would call FD_SET to add them to the set here
83 // 2. Set up the timeout.
84 // This example client has no other work it needs to be doing,
85 // so we set an effectively infinite timeout
86 timeout
.tv_sec
= 0x3FFFFFFF;
89 // 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
90 mDNSPosixGetFDSet(m
, &nfds
, &readfds
, &timeout
);
92 // 4. Call select as normal
93 verbosedebugf("select(%d, %d.%06d)", nfds
, timeout
.tv_sec
, timeout
.tv_usec
);
94 result
= select(nfds
, &readfds
, NULL
, NULL
, &timeout
);
98 verbosedebugf("select() returned %d errno %d", result
, errno
);
99 if (errno
!= EINTR
) StopNow
= mDNStrue
;
103 // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
104 mDNSPosixProcessFDSet(m
, &readfds
);
106 // 6. This example client has no other work it needs to be doing,
107 // but a real client would do its work here