]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSPosix/ExampleClientApp.c
1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
24 Change History (most recent first):
26 $Log: ExampleClientApp.c,v $
27 Revision 1.12 2004/11/30 22:37:00 cheshire
28 Update copyright dates and add "Mode: C; tab-width: 4" headers
30 Revision 1.11 2004/09/17 01:08:53 cheshire
31 Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
32 The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
33 declared in that file are ONLY appropriate to single-address-space embedded applications.
34 For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
36 Revision 1.10 2004/09/16 01:58:22 cheshire
39 Revision 1.9 2003/08/12 19:56:26 cheshire
42 Revision 1.8 2003/07/02 21:19:58 cheshire
43 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
45 Revision 1.7 2003/06/18 05:48:41 cheshire
48 Revision 1.6 2003/03/31 22:44:36 cheshire
53 #include <stdio.h> // For printf()
54 #include <stdlib.h> // For exit() etc.
55 #include <string.h> // For strlen() etc.
56 #include <unistd.h> // For select()
57 #include <errno.h> // For errno, EINTR
58 #include <arpa/inet.h> // For inet_addr()
59 #include <netinet/in.h> // For INADDR_NONE
60 #include <netdb.h> // For gethostbyname()
61 #include <signal.h> // For SIGINT, etc.
63 #include "mDNSEmbeddedAPI.h" // Defines the interface to the client layer above
64 #include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
66 //*******************************************************************************************
69 static volatile mDNSBool StopNow
;
71 mDNSlocal
void HandleSIG(int signal
)
73 (void)signal
; // Unused
79 mDNSexport
void ExampleClientEventLoop(mDNS
*const m
)
81 signal(SIGINT
, HandleSIG
); // SIGINT is what you get for a Ctrl-C
82 signal(SIGTERM
, HandleSIG
);
88 struct timeval timeout
;
91 // 1. Set up the fd_set as usual here.
92 // This example client has no file descriptors of its own,
93 // but a real application would call FD_SET to add them to the set here
96 // 2. Set up the timeout.
97 // This example client has no other work it needs to be doing,
98 // so we set an effectively infinite timeout
99 timeout
.tv_sec
= 0x3FFFFFFF;
102 // 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
103 mDNSPosixGetFDSet(m
, &nfds
, &readfds
, &timeout
);
105 // 4. Call select as normal
106 verbosedebugf("select(%d, %d.%06d)", nfds
, timeout
.tv_sec
, timeout
.tv_usec
);
107 result
= select(nfds
, &readfds
, NULL
, NULL
, &timeout
);
111 verbosedebugf("select() returned %d errno %d", result
, errno
);
112 if (errno
!= EINTR
) StopNow
= mDNStrue
;
116 // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
117 mDNSPosixProcessFDSet(m
, &readfds
);
119 // 6. This example client has no other work it needs to be doing,
120 // but a real client would do its work here