]>
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.
18 #include <stdio.h> // For printf()
19 #include <stdlib.h> // For exit() etc.
20 #include <string.h> // For strlen() etc.
21 #include <unistd.h> // For select()
22 #include <errno.h> // For errno, EINTR
23 #include <netinet/in.h> // For INADDR_NONE
24 #include <arpa/inet.h> // For inet_addr()
25 #include <netdb.h> // For gethostbyname()
26 #include <signal.h> // For SIGINT, etc.
28 #include "mDNSEmbeddedAPI.h" // Defines the interface to the client layer above
29 #include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
31 //*******************************************************************************************
34 static volatile mDNSBool StopNow
;
36 mDNSlocal
void HandleSIG(int signal
)
38 (void)signal
; // Unused
44 mDNSexport
void ExampleClientEventLoop(mDNS
*const m
)
46 signal(SIGINT
, HandleSIG
); // SIGINT is what you get for a Ctrl-C
47 signal(SIGTERM
, HandleSIG
);
54 struct timeval timeout
;
57 // 1. Set up the fd_set as usual here.
58 // This example client has no file descriptors of its own,
59 // but a real application would call FD_SET to add them to the set here
63 // 2. Set up the timeout.
64 // This example client has no other work it needs to be doing,
65 // so we set an effectively infinite timeout
66 timeout
.tv_sec
= FutureTime
;
69 // 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
70 mDNSPosixGetFDSet(m
, &nfds
, &readfds
, &writefds
, &timeout
);
72 // 4. Call select as normal
73 verbosedebugf("select(%d, %d.%06d)", nfds
, timeout
.tv_sec
, timeout
.tv_usec
);
74 result
= select(nfds
, &readfds
, &writefds
, NULL
, &timeout
);
78 verbosedebugf("select() returned %d errno %d", result
, errno
);
79 if (errno
!= EINTR
) StopNow
= mDNStrue
;
83 // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
84 mDNSPosixProcessFDSet(m
, &readfds
, &writefds
);
86 // 6. This example client has no other work it needs to be doing,
87 // but a real client would do its work here