]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSPosix/ExampleClientApp.c
85613882e1d850979e8664c4f72a3ab43c0edf88
2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 Change History (most recent first):
27 $Log: ExampleClientApp.c,v $
28 Revision 1.9 2003/08/12 19:56:26 cheshire
31 Revision 1.8 2003/07/02 21:19:58 cheshire
32 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
34 Revision 1.7 2003/06/18 05:48:41 cheshire
37 Revision 1.6 2003/03/31 22:44:36 cheshire
42 #include <stdio.h> // For printf()
43 #include <stdlib.h> // For exit() etc.
44 #include <string.h> // For strlen() etc.
45 #include <unistd.h> // For select()
46 #include <errno.h> // For errno, EINTR
47 #include <arpa/inet.h> // For inet_addr()
48 #include <netinet/in.h> // For INADDR_NONE
49 #include <netdb.h> // For gethostbyname()
50 #include <signal.h> // For SIGINT, etc.
52 #include "mDNSClientAPI.h" // Defines the interface to the client layer above
53 #include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
55 //*******************************************************************************************
58 static volatile mDNSBool StopNow
;
60 mDNSlocal
void HandleSIG(int signal
)
62 (void)signal
; // Unused
68 mDNSexport
void ExampleClientEventLoop(mDNS
*const m
)
70 signal(SIGINT
, HandleSIG
); // SIGINT is what you get for a Ctrl-C
71 signal(SIGTERM
, HandleSIG
);
77 struct timeval timeout
;
80 // 1. Set up the fd_set as usual here.
81 // This example client has no file descriptors of its own,
82 // but a real application would call FD_SET to add them to the set here
85 // 2. Set up the timeout.
86 // This example client has no other work it needs to be doing,
87 // so we set an effectively infinite timeout
88 timeout
.tv_sec
= 0x3FFFFFFF;
91 // 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
92 mDNSPosixGetFDSet(m
, &nfds
, &readfds
, &timeout
);
94 // 4. Call select as normal
95 verbosedebugf("select(%d, %d.%06d)", nfds
, timeout
.tv_sec
, timeout
.tv_usec
);
96 result
= select(nfds
, &readfds
, NULL
, NULL
, &timeout
);
100 verbosedebugf("select() returned %d errno %d", result
, errno
);
101 if (errno
!= EINTR
) StopNow
= mDNStrue
;
105 // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
106 mDNSPosixProcessFDSet(m
, &readfds
);
108 // 6. This example client has no other work it needs to be doing,
109 // but a real client would do its work here