]>
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 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 Change History (most recent first):
19 $Log: ExampleClientApp.c,v $
20 Revision 1.14 2006/08/14 23:24:46 cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
23 Revision 1.13 2006/02/23 23:38:43 cheshire
24 <rdar://problem/4427969> On FreeBSD 4 "arpa/inet.h" requires "netinet/in.h" be included first
26 Revision 1.12 2004/11/30 22:37:00 cheshire
27 Update copyright dates and add "Mode: C; tab-width: 4" headers
29 Revision 1.11 2004/09/17 01:08:53 cheshire
30 Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
31 The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
32 declared in that file are ONLY appropriate to single-address-space embedded applications.
33 For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
35 Revision 1.10 2004/09/16 01:58:22 cheshire
38 Revision 1.9 2003/08/12 19:56:26 cheshire
41 Revision 1.8 2003/07/02 21:19:58 cheshire
42 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
44 Revision 1.7 2003/06/18 05:48:41 cheshire
47 Revision 1.6 2003/03/31 22:44:36 cheshire
52 #include <stdio.h> // For printf()
53 #include <stdlib.h> // For exit() etc.
54 #include <string.h> // For strlen() etc.
55 #include <unistd.h> // For select()
56 #include <errno.h> // For errno, EINTR
57 #include <netinet/in.h> // For INADDR_NONE
58 #include <arpa/inet.h> // For inet_addr()
59 #include <netdb.h> // For gethostbyname()
60 #include <signal.h> // For SIGINT, etc.
62 #include "mDNSEmbeddedAPI.h" // Defines the interface to the client layer above
63 #include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
65 //*******************************************************************************************
68 static volatile mDNSBool StopNow
;
70 mDNSlocal
void HandleSIG(int signal
)
72 (void)signal
; // Unused
78 mDNSexport
void ExampleClientEventLoop(mDNS
*const m
)
80 signal(SIGINT
, HandleSIG
); // SIGINT is what you get for a Ctrl-C
81 signal(SIGTERM
, HandleSIG
);
87 struct timeval timeout
;
90 // 1. Set up the fd_set as usual here.
91 // This example client has no file descriptors of its own,
92 // but a real application would call FD_SET to add them to the set here
95 // 2. Set up the timeout.
96 // This example client has no other work it needs to be doing,
97 // so we set an effectively infinite timeout
98 timeout
.tv_sec
= 0x3FFFFFFF;
101 // 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
102 mDNSPosixGetFDSet(m
, &nfds
, &readfds
, &timeout
);
104 // 4. Call select as normal
105 verbosedebugf("select(%d, %d.%06d)", nfds
, timeout
.tv_sec
, timeout
.tv_usec
);
106 result
= select(nfds
, &readfds
, NULL
, NULL
, &timeout
);
110 verbosedebugf("select() returned %d errno %d", result
, errno
);
111 if (errno
!= EINTR
) StopNow
= mDNStrue
;
115 // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
116 mDNSPosixProcessFDSet(m
, &readfds
);
118 // 6. This example client has no other work it needs to be doing,
119 // but a real client would do its work here