]> git.saurik.com Git - apple/mdnsresponder.git/blame - mDNSPosix/mDNSPosix.h
mDNSResponder-1310.80.1.tar.gz
[apple/mdnsresponder.git] / mDNSPosix / mDNSPosix.h
CommitLineData
f0cc3e7b 1/* -*- Mode: C; tab-width: 4; c-file-style: "bsd"; c-basic-offset: 4; fill-column: 108; indent-tabs-mode: nil; -*-
7f0064bd
A
2 *
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
c9b9ae52 4 *
67c8f8a1
A
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
83fb1e36 8 *
67c8f8a1 9 * http://www.apache.org/licenses/LICENSE-2.0
83fb1e36 10 *
67c8f8a1
A
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
c9b9ae52 15 * limitations under the License.
263eeeab 16 */
c9b9ae52
A
17
18#ifndef __mDNSPlatformPosix_h
19#define __mDNSPlatformPosix_h
20
8e92c31c 21#include <signal.h>
c9b9ae52
A
22#include <sys/time.h>
23
c9b9ae52 24#ifdef __cplusplus
83fb1e36 25extern "C" {
c9b9ae52
A
26#endif
27
8e92c31c
A
28// PosixNetworkInterface is a record extension of the core NetworkInterfaceInfo
29// type that supports extra fields needed by the Posix platform.
30//
31// IMPORTANT: coreIntf must be the first field in the structure because
32// we cast between pointers to the two different types regularly.
33
34typedef struct PosixNetworkInterface PosixNetworkInterface;
35
36struct PosixNetworkInterface
83fb1e36 37{
f0cc3e7b 38 NetworkInterfaceInfo coreIntf; // MUST be the first element in this structure
95d7a4a3 39 mDNSs32 LastSeen;
83fb1e36
A
40 const char * intfName;
41 PosixNetworkInterface * aliasIntf;
42 int index;
43 int multicastSocket4;
8e92c31c 44#if HAVE_IPV6
83fb1e36 45 int multicastSocket6;
8e92c31c 46#endif
83fb1e36 47};
8e92c31c 48
c9b9ae52
A
49// This is a global because debugf_() needs to be able to check its value
50extern int gMDNSPlatformPosixVerboseLevel;
51
52struct mDNS_PlatformSupport_struct
83fb1e36
A
53{
54 int unicastSocket4;
8e92c31c 55#if HAVE_IPV6
83fb1e36 56 int unicastSocket6;
8e92c31c 57#endif
83fb1e36 58};
c9b9ae52 59
f0cc3e7b
A
60// We keep a list of client-supplied event sources in PosixEventSource records
61// Add a file descriptor to the set that mDNSPosixRunEventLoopOnce() listens to.
62#define PosixEventFlag_OnList 1
63#define PosixEventFlag_Read 2
64#define PosixEventFlag_Write 4
65
66typedef void (*mDNSPosixEventCallback)(int fd, void *context);
67struct PosixEventSource
68{
69 struct PosixEventSource *next;
70 mDNSPosixEventCallback readCallback;
71 mDNSPosixEventCallback writeCallback;
72 const char *readTaskName;
73 const char *writeTaskName;
74 void *readContext;
75 void *writeContext;
76 int fd;
77 unsigned flags;
78};
79typedef struct PosixEventSource PosixEventSource;
80
81struct TCPSocket_struct
82{
83 mDNSIPPort port; // MUST BE FIRST FIELD -- mDNSCore expects every TCPSocket_struct to begin with mDNSIPPort
84 TCPSocketFlags flags; // MUST BE SECOND FIELD -- mDNSCore expects every TCPSocket_struct have TCPSocketFlags flags after mDNSIPPort
85 TCPConnectionCallback callback;
86 PosixEventSource events;
87 // SSL context goes here.
88 domainname *hostname;
89 mDNSAddr remoteAddress;
90 mDNSIPPort remotePort;
91 void *context;
92 mDNSBool setup;
93 mDNSBool connected;
94 mStatus err;
95};
96
97struct TCPListener_struct
98{
99 TCPAcceptedCallback callback;
100 PosixEventSource events;
101 void *context;
102 mDNSAddr_Type addressType;
103 TCPSocketFlags socketFlags;
104};
105
7cb34e5c
A
106#define uDNS_SERVERS_FILE "/etc/resolv.conf"
107extern int ParseDNSServers(mDNS *m, const char *filePath);
c9b9ae52 108extern mStatus mDNSPlatformPosixRefreshInterfaceList(mDNS *const m);
83fb1e36 109// See comment in implementation.
c9b9ae52 110
f0cc3e7b
A
111// Get the next upcoming mDNS (or DNS) event time as a posix timeval that can be passed to select.
112// This will only update timeout if the next mDNS event is sooner than the value that was passed.
113// Therefore, use { FutureTime, 0 } as an initializer if no other timer events are being managed.
114extern void mDNSPosixGetNextDNSEventTime(mDNS *m, struct timeval *timeout);
115
116// Returns all the FDs that the posix I/O event system expects to be passed to select.
117extern void mDNSPosixGetFDSetForSelect(mDNS *m, int *nfds, fd_set *readfds, fd_set *writefds);
118
c9b9ae52
A
119// Call mDNSPosixGetFDSet before calling select(), to update the parameters
120// as may be necessary to meet the needs of the mDNSCore code.
121// The timeout pointer MUST NOT be NULL.
12c5fa7a 122// Set timeout->tv_sec to FutureTime if you want to have effectively no timeout
c9b9ae52
A
123// After calling mDNSPosixGetFDSet(), call select(nfds, &readfds, NULL, NULL, &timeout); as usual
124// After select() returns, call mDNSPosixProcessFDSet() to let mDNSCore do its work
f0cc3e7b
A
125// mDNSPosixGetFDSet simply calls mDNSPosixGetNextDNSEventTime and then mDNSPosixGetFDSetForSelect.
126extern void mDNSPosixGetFDSet(mDNS *m, int *nfds, fd_set *readfds, fd_set *writefds, struct timeval *timeout);
c9b9ae52 127
f0cc3e7b
A
128
129extern void mDNSPosixProcessFDSet(mDNS *const m, fd_set *readfds, fd_set *writefds);
8e92c31c
A
130
131extern mStatus mDNSPosixAddFDToEventLoop( int fd, mDNSPosixEventCallback callback, void *context);
132extern mStatus mDNSPosixRemoveFDFromEventLoop( int fd);
133extern mStatus mDNSPosixListenForSignalInEventLoop( int signum);
134extern mStatus mDNSPosixIgnoreSignalInEventLoop( int signum);
135extern mStatus mDNSPosixRunEventLoopOnce( mDNS *m, const struct timeval *pTimeout, sigset_t *pSignalsReceived, mDNSBool *pDataDispatched);
136
f0cc3e7b
A
137extern mStatus mDNSPosixListenForSignalInEventLoop( int signum);
138extern mStatus mDNSPosixIgnoreSignalInEventLoop( int signum);
139extern mStatus mDNSPosixRunEventLoopOnce( mDNS *m, const struct timeval *pTimeout, sigset_t *pSignalsReceived, mDNSBool *pDataDispatched);
140
c9b9ae52 141#ifdef __cplusplus
83fb1e36 142}
c9b9ae52
A
143#endif
144
145#endif