]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/dnssd_ipc.h
mDNSResponder-107.4.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.20 2005/03/21 00:39:31 shersche
31 <rdar://problem/4021486> Fix build warnings on Win32 platform
32
33 Revision 1.19 2005/02/02 02:25:22 cheshire
34 <rdar://problem/3980388> /var/run/mDNSResponder should be /var/run/mdnsd on Linux
35
36 Revision 1.18 2005/01/27 22:57:56 cheshire
37 Fix compile errors on gcc4
38
39 Revision 1.17 2004/11/23 03:39:47 cheshire
40 Let interface name/index mapping capability live directly in JNISupport.c,
41 instead of having to call through to the daemon via IPC to get this information.
42
43 Revision 1.16 2004/11/12 03:21:41 rpantos
44 rdar://problem/3809541 Add DNSSDMapIfIndexToName, DNSSDMapNameToIfIndex.
45
46 Revision 1.15 2004/10/06 02:22:20 cheshire
47 Changed MacRoman copyright symbol (should have been UTF-8 in any case :-) to ASCII-compatible "(c)"
48
49 Revision 1.14 2004/10/01 22:15:55 rpantos
50 rdar://problem/3824265: Replace APSL in client lib with BSD license.
51
52 Revision 1.13 2004/09/16 23:14:25 cheshire
53 Changes for Windows compatibility
54
55 Revision 1.12 2004/09/16 21:46:38 ksekar
56 <rdar://problem/3665304> Need SPI for LoginWindow to associate a UID with a Wide Area domain
57
58 Revision 1.11 2004/08/10 06:24:56 cheshire
59 Use types with precisely defined sizes for 'op' and 'reg_index', for better
60 compatibility if the daemon and the client stub are built using different compilers
61
62 Revision 1.10 2004/07/07 17:39:25 shersche
63 Change MDNS_SERVERPORT from 5533 to 5354.
64
65 Revision 1.9 2004/06/25 00:26:27 rpantos
66 Changes to fix the Posix build on Solaris.
67
68 Revision 1.8 2004/06/18 04:56:51 rpantos
69 Add layer for platform code
70
71 Revision 1.7 2004/06/12 01:08:14 cheshire
72 Changes for Windows compatibility
73
74 Revision 1.6 2003/08/12 19:56:25 cheshire
75 Update to APSL 2.0
76
77 */
78
79 #ifndef DNSSD_IPC_H
80 #define DNSSD_IPC_H
81
82 #include "dns_sd.h"
83
84
85 //
86 // Common cross platform services
87 //
88 #if defined(WIN32)
89 # include <winsock2.h>
90 # define dnssd_InvalidSocket INVALID_SOCKET
91 # define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
92 # define dnssd_EINTR WSAEINTR
93 # define MSG_WAITALL 0
94 # define dnssd_sock_t SOCKET
95 # define dnssd_socklen_t int
96 # define dnssd_sockbuf_t const char*
97 # define dnssd_close(sock) closesocket(sock)
98 # define dnssd_errno() WSAGetLastError()
99 # define ssize_t int
100 # define getpid _getpid
101 #else
102 # include <sys/types.h>
103 # include <unistd.h>
104 # include <sys/un.h>
105 # include <string.h>
106 # include <stdio.h>
107 # include <stdlib.h>
108 # include <sys/stat.h>
109 # include <sys/socket.h>
110 # include <netinet/in.h>
111 # define dnssd_InvalidSocket -1
112 # define dnssd_EWOULDBLOCK EWOULDBLOCK
113 # define dnssd_EINTR EINTR
114 # define dnssd_EPIPE EPIPE
115 # define dnssd_sock_t int
116 # define dnssd_socklen_t unsigned int
117 # define dnssd_sockbuf_t const char*
118 # define dnssd_close(sock) close(sock)
119 # define dnssd_errno() errno
120 #endif
121
122 #if defined(USE_TCP_LOOPBACK)
123 # define AF_DNSSD AF_INET
124 # define MDNS_TCP_SERVERADDR "127.0.0.1"
125 # define MDNS_TCP_SERVERPORT 5354
126 # define LISTENQ 5
127 # define dnssd_sockaddr_t struct sockaddr_in
128 #else
129 # define AF_DNSSD AF_LOCAL
130 # ifndef MDNS_UDS_SERVERPATH
131 # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
132 # endif
133 # define LISTENQ 100
134 // longest legal control path length
135 # define MAX_CTLPATH 256
136 # define dnssd_sockaddr_t struct sockaddr_un
137 #endif
138
139
140 //#define UDSDEBUG // verbose debug output
141
142 // Compatibility workaround
143 #ifndef AF_LOCAL
144 #define AF_LOCAL AF_UNIX
145 #endif
146
147 // General UDS constants
148 #define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
149
150 // IPC data encoding constants and types
151 #define VERSION 1
152 #define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
153 #define IPC_FLAGS_REUSE_SOCKET 2 // set flag if synchronous errors are to be sent via the primary socket
154 // (if not set, first string in message buffer must be path to error socket
155
156 typedef enum
157 {
158 connection = 1, // connected socket via DNSServiceConnect()
159 reg_record_request, // reg/remove record only valid for connected sockets
160 remove_record_request,
161 enumeration_request,
162 reg_service_request,
163 browse_request,
164 resolve_request,
165 query_request,
166 reconfirm_record_request,
167 add_record_request,
168 update_record_request,
169 setdomain_request
170 } request_op_t;
171
172 typedef enum
173 {
174 enumeration_reply = 64,
175 reg_service_reply,
176 browse_reply,
177 resolve_reply,
178 query_reply,
179 reg_record_reply
180 } reply_op_t;
181
182 typedef struct ipc_msg_hdr_struct ipc_msg_hdr;
183
184 // client stub callback to process message from server and deliver results to
185 // client application
186
187 typedef void (*process_reply_callback)
188 (
189 DNSServiceRef sdr,
190 ipc_msg_hdr *hdr,
191 char *msg
192 );
193
194 // allow 64-bit client to interoperate w/ 32-bit daemon
195 typedef union
196 {
197 void *context;
198 uint32_t ptr64[2];
199 } client_context_t;
200
201 typedef struct ipc_msg_hdr_struct
202 {
203 uint32_t version;
204 uint32_t datalen;
205 uint32_t flags;
206 uint32_t op; // request_op_t or reply_op_t
207 client_context_t client_context; // context passed from client, returned by server in corresponding reply
208 uint32_t reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
209 // socket connected by DNSServiceConnect(). Must be unique in the scope of the connection, such that and
210 // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
211 } ipc_msg_hdr_struct;
212
213 // it is advanced to point to the next field, or the end of the message
214 // routines to write to and extract data from message buffers.
215 // caller responsible for bounds checking.
216 // ptr is the address of the pointer to the start of the field.
217 // it is advanced to point to the next field, or the end of the message
218
219 void put_long(const uint32_t l, char **ptr);
220 uint32_t get_long(char **ptr);
221
222 void put_short(uint16_t s, char **ptr);
223 uint16_t get_short(char **ptr);
224
225 #define put_flags put_long
226 #define get_flags get_long
227
228 #define put_error_code put_long
229 #define get_error_code get_long
230
231 int put_string(const char *str, char **ptr);
232 int get_string(char **ptr, char *buffer, int buflen);
233
234 void put_rdata(const int rdlen, const unsigned char *rdata, char **ptr);
235 char *get_rdata(char **ptr, int rdlen); // return value is rdata pointed to by *ptr -
236 // rdata is not copied from buffer.
237
238 void ConvertHeaderBytes(ipc_msg_hdr *hdr);
239
240 #endif // DNSSD_IPC_H