]>
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
);
53 struct timeval timeout
;
56 // 1. Set up the fd_set as usual here.
57 // This example client has no file descriptors of its own,
58 // but a real application would call FD_SET to add them to the set here
61 // 2. Set up the timeout.
62 // This example client has no other work it needs to be doing,
63 // so we set an effectively infinite timeout
64 timeout
.tv_sec
= 0x3FFFFFFF;
67 // 3. Give the mDNSPosix layer a chance to add its information to the fd_set and timeout
68 mDNSPosixGetFDSet(m
, &nfds
, &readfds
, &timeout
);
70 // 4. Call select as normal
71 verbosedebugf("select(%d, %d.%06d)", nfds
, timeout
.tv_sec
, timeout
.tv_usec
);
72 result
= select(nfds
, &readfds
, NULL
, NULL
, &timeout
);
76 verbosedebugf("select() returned %d errno %d", result
, errno
);
77 if (errno
!= EINTR
) StopNow
= mDNStrue
;
81 // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
82 mDNSPosixProcessFDSet(m
, &readfds
);
84 // 6. This example client has no other work it needs to be doing,
85 // but a real client would do its work here