]> git.saurik.com Git - apple/libinfo.git/blob - mdns.subproj/dnssd_ipc.h
Libinfo-222.3.6.tar.gz
[apple/libinfo.git] / mdns.subproj / dnssd_ipc.h
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: dnssd_ipc.h,v $
26 Revision 1.9 2004/09/22 20:05:38 majka
27 Integrated
28 3725573 - Need Error Codes for handling Lighthouse setup failure on NAT
29 3805822 - Socket-based APIs aren't endian-safe
30 3806739 - DNSServiceSetDefaultDomainForUser header comments incorrect
31
32 Revision 1.8.2.1 2004/09/20 21:54:33 ksekar
33 <rdar://problem/3805822> Socket-based APIs aren't endian-safe
34
35 Revision 1.8 2004/09/17 20:19:01 majka
36 Integrated 3804522
37
38 Revision 1.7.2.1 2004/09/17 20:15:30 ksekar
39 *** empty log message ***
40
41 Revision 1.7 2004/09/16 23:45:24 majka
42 Integrated 3775315 and 3765280.
43
44 Revision 1.6.4.1 2004/09/02 19:43:41 ksekar
45 <rdar://problem/3775315>: Sync dns-sd client files between Libinfo and
46 mDNSResponder projects
47
48 Revision 1.11 2004/08/10 06:24:56 cheshire
49 Use types with precisely defined sizes for 'op' and 'reg_index', for better
50 compatibility if the daemon and the client stub are built using different compilers
51
52 Revision 1.10 2004/07/07 17:39:25 shersche
53 Change MDNS_SERVERPORT from 5533 to 5354.
54
55 Revision 1.9 2004/06/25 00:26:27 rpantos
56 Changes to fix the Posix build on Solaris.
57
58 Revision 1.8 2004/06/18 04:56:51 rpantos
59 Add layer for platform code
60
61 Revision 1.7 2004/06/12 01:08:14 cheshire
62 Changes for Windows compatibility
63
64 Revision 1.6 2003/08/12 19:56:25 cheshire
65 Update to APSL 2.0
66
67 */
68
69 #ifndef DNSSD_IPC_H
70 #define DNSSD_IPC_H
71
72 #include "dns_sd.h"
73
74
75 //
76 // Common cross platform services
77 //
78 #if defined(WIN32)
79 # include <winsock2.h>
80 # define dnssd_InvalidSocket INVALID_SOCKET
81 # define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
82 # define dnssd_EINTR WSAEINTR
83 # define MSG_WAITALL 0
84 # define dnssd_sock_t SOCKET
85 # define dnssd_sockbuf_t
86 # define dnssd_close(sock) closesocket(sock)
87 # define dnssd_errno() WSAGetLastError()
88 # define ssize_t int
89 # define getpid _getpid
90 #else
91 # include <sys/types.h>
92 # include <unistd.h>
93 # include <sys/un.h>
94 # include <string.h>
95 # include <stdio.h>
96 # include <stdlib.h>
97 # include <sys/stat.h>
98 # include <sys/socket.h>
99 # include <netinet/in.h>
100 # define dnssd_InvalidSocket -1
101 # define dnssd_EWOULDBLOCK EWOULDBLOCK
102 # define dnssd_EINTR EINTR
103 # define dnssd_EPIPE EPIPE
104 # define dnssd_sock_t int
105 # define dnssd_close(sock) close(sock)
106 # define dnssd_errno() errno
107 #endif
108
109 #if defined(USE_TCP_LOOPBACK)
110 # define AF_DNSSD AF_INET
111 # define MDNS_TCP_SERVERADDR "127.0.0.1"
112 # define MDNS_TCP_SERVERPORT 5354
113 # define LISTENQ 5
114 # define dnssd_sockaddr_t struct sockaddr_in
115 #else
116 # define AF_DNSSD AF_LOCAL
117 # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
118 # define LISTENQ 100
119 // longest legal control path length
120 # define MAX_CTLPATH 256
121 # define dnssd_sockaddr_t struct sockaddr_un
122 #endif
123
124
125 //#define UDSDEBUG // verbose debug output
126
127 // Compatibility workaround
128 #ifndef AF_LOCAL
129 #define AF_LOCAL AF_UNIX
130 #endif
131
132 // General UDS constants
133 #define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
134
135 // IPC data encoding constants and types
136 #define VERSION 1
137 #define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
138 #define IPC_FLAGS_REUSE_SOCKET 2 // set flag if synchronous errors are to be sent via the primary socket
139 // (if not set, first string in message buffer must be path to error socket
140
141 typedef enum
142 {
143 connection = 1, // connected socket via DNSServiceConnect()
144 reg_record_request, // reg/remove record only valid for connected sockets
145 remove_record_request,
146 enumeration_request,
147 reg_service_request,
148 browse_request,
149 resolve_request,
150 query_request,
151 reconfirm_record_request,
152 add_record_request,
153 update_record_request,
154 setdomain_request
155 } request_op_t;
156
157 typedef enum
158 {
159 enumeration_reply = 64,
160 reg_service_reply,
161 browse_reply,
162 resolve_reply,
163 query_reply,
164 reg_record_reply
165 } reply_op_t;
166
167 typedef struct ipc_msg_hdr_struct ipc_msg_hdr;
168
169 // client stub callback to process message from server and deliver results to
170 // client application
171
172 typedef void (*process_reply_callback)
173 (
174 DNSServiceRef sdr,
175 ipc_msg_hdr *hdr,
176 char *msg
177 );
178
179 // allow 64-bit client to interoperate w/ 32-bit daemon
180 typedef union
181 {
182 void *context;
183 uint32_t ptr64[2];
184 } client_context_t;
185
186 typedef struct __attribute__((__packed__)) ipc_msg_hdr_struct
187 {
188 uint32_t version;
189 uint32_t datalen;
190 uint32_t flags;
191 uint32_t op; // request_op_t or reply_op_t
192 client_context_t client_context; // context passed from client, returned by server in corresponding reply
193 uint32_t reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
194 // socket connected by DNSServiceConnect(). Must be unique in the scope of the connection, such that and
195 // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
196 } ipc_msg_hdr_struct;
197
198 // it is advanced to point to the next field, or the end of the message
199 // routines to write to and extract data from message buffers.
200 // caller responsible for bounds checking.
201 // ptr is the address of the pointer to the start of the field.
202 // it is advanced to point to the next field, or the end of the message
203
204 void put_long(const uint32_t l, char **ptr);
205 uint32_t get_long(char **ptr);
206
207 void put_short(uint16_t s, char **ptr);
208 uint16_t get_short(char **ptr);
209
210 #define put_flags put_long
211 #define get_flags get_long
212
213 #define put_error_code put_long
214 #define get_error_code get_long
215
216 int put_string(const char *str, char **ptr);
217 int get_string(char **ptr, char *buffer, int buflen);
218
219 void put_rdata(const int rdlen, const char *rdata, char **ptr);
220 char *get_rdata(char **ptr, int rdlen); // return value is rdata pointed to by *ptr -
221 // rdata is not copied from buffer.
222
223 void ConvertHeaderBytes(ipc_msg_hdr *hdr);
224
225 #endif // DNSSD_IPC_H