]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/dnssd_ipc.h
mDNSResponder-108.5.tar.gz
[apple/mdnsresponder.git] / mDNSShared / dnssd_ipc.h
1 /*
2 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
13 * contributors may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 Change History (most recent first):
28
29 $Log: dnssd_ipc.h,v $
30 Revision 1.21 2005/09/29 06:38:13 herscher
31 Remove #define MSG_WAITALL on Windows. We don't use this macro anymore, and it's presence causes warnings to be emitted when compiling against the latest Microsoft Platform SDK.
32
33 Revision 1.20 2005/03/21 00:39:31 shersche
34 <rdar://problem/4021486> Fix build warnings on Win32 platform
35
36 Revision 1.19 2005/02/02 02:25:22 cheshire
37 <rdar://problem/3980388> /var/run/mDNSResponder should be /var/run/mdnsd on Linux
38
39 Revision 1.18 2005/01/27 22:57:56 cheshire
40 Fix compile errors on gcc4
41
42 Revision 1.17 2004/11/23 03:39:47 cheshire
43 Let interface name/index mapping capability live directly in JNISupport.c,
44 instead of having to call through to the daemon via IPC to get this information.
45
46 Revision 1.16 2004/11/12 03:21:41 rpantos
47 rdar://problem/3809541 Add DNSSDMapIfIndexToName, DNSSDMapNameToIfIndex.
48
49 Revision 1.15 2004/10/06 02:22:20 cheshire
50 Changed MacRoman copyright symbol (should have been UTF-8 in any case :-) to ASCII-compatible "(c)"
51
52 Revision 1.14 2004/10/01 22:15:55 rpantos
53 rdar://problem/3824265: Replace APSL in client lib with BSD license.
54
55 Revision 1.13 2004/09/16 23:14:25 cheshire
56 Changes for Windows compatibility
57
58 Revision 1.12 2004/09/16 21:46:38 ksekar
59 <rdar://problem/3665304> Need SPI for LoginWindow to associate a UID with a Wide Area domain
60
61 Revision 1.11 2004/08/10 06:24:56 cheshire
62 Use types with precisely defined sizes for 'op' and 'reg_index', for better
63 compatibility if the daemon and the client stub are built using different compilers
64
65 Revision 1.10 2004/07/07 17:39:25 shersche
66 Change MDNS_SERVERPORT from 5533 to 5354.
67
68 Revision 1.9 2004/06/25 00:26:27 rpantos
69 Changes to fix the Posix build on Solaris.
70
71 Revision 1.8 2004/06/18 04:56:51 rpantos
72 Add layer for platform code
73
74 Revision 1.7 2004/06/12 01:08:14 cheshire
75 Changes for Windows compatibility
76
77 Revision 1.6 2003/08/12 19:56:25 cheshire
78 Update to APSL 2.0
79
80 */
81
82 #ifndef DNSSD_IPC_H
83 #define DNSSD_IPC_H
84
85 #include "dns_sd.h"
86
87
88 //
89 // Common cross platform services
90 //
91 #if defined(WIN32)
92 # include <winsock2.h>
93 # define dnssd_InvalidSocket INVALID_SOCKET
94 # define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
95 # define dnssd_EINTR WSAEINTR
96 # define dnssd_sock_t SOCKET
97 # define dnssd_socklen_t int
98 # define dnssd_sockbuf_t const char*
99 # define dnssd_close(sock) closesocket(sock)
100 # define dnssd_errno() WSAGetLastError()
101 # define ssize_t int
102 # define getpid _getpid
103 #else
104 # include <sys/types.h>
105 # include <unistd.h>
106 # include <sys/un.h>
107 # include <string.h>
108 # include <stdio.h>
109 # include <stdlib.h>
110 # include <sys/stat.h>
111 # include <sys/socket.h>
112 # include <netinet/in.h>
113 # define dnssd_InvalidSocket -1
114 # define dnssd_EWOULDBLOCK EWOULDBLOCK
115 # define dnssd_EINTR EINTR
116 # define dnssd_EPIPE EPIPE
117 # define dnssd_sock_t int
118 # define dnssd_socklen_t unsigned int
119 # define dnssd_sockbuf_t const char*
120 # define dnssd_close(sock) close(sock)
121 # define dnssd_errno() errno
122 #endif
123
124 #if defined(USE_TCP_LOOPBACK)
125 # define AF_DNSSD AF_INET
126 # define MDNS_TCP_SERVERADDR "127.0.0.1"
127 # define MDNS_TCP_SERVERPORT 5354
128 # define LISTENQ 5
129 # define dnssd_sockaddr_t struct sockaddr_in
130 #else
131 # define AF_DNSSD AF_LOCAL
132 # ifndef MDNS_UDS_SERVERPATH
133 # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
134 # endif
135 # define LISTENQ 100
136 // longest legal control path length
137 # define MAX_CTLPATH 256
138 # define dnssd_sockaddr_t struct sockaddr_un
139 #endif
140
141
142 //#define UDSDEBUG // verbose debug output
143
144 // Compatibility workaround
145 #ifndef AF_LOCAL
146 #define AF_LOCAL AF_UNIX
147 #endif
148
149 // General UDS constants
150 #define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
151
152 // IPC data encoding constants and types
153 #define VERSION 1
154 #define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
155 #define IPC_FLAGS_REUSE_SOCKET 2 // set flag if synchronous errors are to be sent via the primary socket
156 // (if not set, first string in message buffer must be path to error socket
157
158 typedef enum
159 {
160 connection = 1, // connected socket via DNSServiceConnect()
161 reg_record_request, // reg/remove record only valid for connected sockets
162 remove_record_request,
163 enumeration_request,
164 reg_service_request,
165 browse_request,
166 resolve_request,
167 query_request,
168 reconfirm_record_request,
169 add_record_request,
170 update_record_request,
171 setdomain_request
172 } request_op_t;
173
174 typedef enum
175 {
176 enumeration_reply = 64,
177 reg_service_reply,
178 browse_reply,
179 resolve_reply,
180 query_reply,
181 reg_record_reply
182 } reply_op_t;
183
184 typedef struct ipc_msg_hdr_struct ipc_msg_hdr;
185
186 // client stub callback to process message from server and deliver results to
187 // client application
188
189 typedef void (*process_reply_callback)
190 (
191 DNSServiceRef sdr,
192 ipc_msg_hdr *hdr,
193 char *msg
194 );
195
196 // allow 64-bit client to interoperate w/ 32-bit daemon
197 typedef union
198 {
199 void *context;
200 uint32_t ptr64[2];
201 } client_context_t;
202
203 typedef struct ipc_msg_hdr_struct
204 {
205 uint32_t version;
206 uint32_t datalen;
207 uint32_t flags;
208 uint32_t op; // request_op_t or reply_op_t
209 client_context_t client_context; // context passed from client, returned by server in corresponding reply
210 uint32_t reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
211 // socket connected by DNSServiceConnect(). Must be unique in the scope of the connection, such that and
212 // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
213 } ipc_msg_hdr_struct;
214
215 // it is advanced to point to the next field, or the end of the message
216 // routines to write to and extract data from message buffers.
217 // caller responsible for bounds checking.
218 // ptr is the address of the pointer to the start of the field.
219 // it is advanced to point to the next field, or the end of the message
220
221 void put_long(const uint32_t l, char **ptr);
222 uint32_t get_long(char **ptr);
223
224 void put_short(uint16_t s, char **ptr);
225 uint16_t get_short(char **ptr);
226
227 #define put_flags put_long
228 #define get_flags get_long
229
230 #define put_error_code put_long
231 #define get_error_code get_long
232
233 int put_string(const char *str, char **ptr);
234 int get_string(char **ptr, char *buffer, int buflen);
235
236 void put_rdata(const int rdlen, const unsigned char *rdata, char **ptr);
237 char *get_rdata(char **ptr, int rdlen); // return value is rdata pointed to by *ptr -
238 // rdata is not copied from buffer.
239
240 void ConvertHeaderBytes(ipc_msg_hdr *hdr);
241
242 #endif // DNSSD_IPC_H