2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
26 Revision 1.9 2004/09/22 20:05:38 majka
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
32 Revision 1.8.2.1 2004/09/20 21:54:33 ksekar
33 <rdar://problem/3805822> Socket-based APIs aren't endian-safe
35 Revision 1.8 2004/09/17 20:19:01 majka
38 Revision 1.7.2.1 2004/09/17 20:15:30 ksekar
39 *** empty log message ***
41 Revision 1.7 2004/09/16 23:45:24 majka
42 Integrated 3775315 and 3765280.
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
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
52 Revision 1.10 2004/07/07 17:39:25 shersche
53 Change MDNS_SERVERPORT from 5533 to 5354.
55 Revision 1.9 2004/06/25 00:26:27 rpantos
56 Changes to fix the Posix build on Solaris.
58 Revision 1.8 2004/06/18 04:56:51 rpantos
59 Add layer for platform code
61 Revision 1.7 2004/06/12 01:08:14 cheshire
62 Changes for Windows compatibility
64 Revision 1.6 2003/08/12 19:56:25 cheshire
76 // Common cross platform services
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()
89 # define getpid _getpid
91 # include <sys/types.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
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
114 # define dnssd_sockaddr_t struct sockaddr_in
116 # define AF_DNSSD AF_LOCAL
117 # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
119 // longest legal control path length
120 # define MAX_CTLPATH 256
121 # define dnssd_sockaddr_t struct sockaddr_un
125 //#define UDSDEBUG // verbose debug output
127 // Compatibility workaround
129 #define AF_LOCAL AF_UNIX
132 // General UDS constants
133 #define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
135 // IPC data encoding constants and types
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
143 connection
= 1, // connected socket via DNSServiceConnect()
144 reg_record_request
, // reg/remove record only valid for connected sockets
145 remove_record_request
,
151 reconfirm_record_request
,
153 update_record_request
,
159 enumeration_reply
= 64,
167 typedef struct ipc_msg_hdr_struct ipc_msg_hdr
;
169 // client stub callback to process message from server and deliver results to
170 // client application
172 typedef void (*process_reply_callback
)
179 // allow 64-bit client to interoperate w/ 32-bit daemon
186 typedef struct __attribute__((__packed__
)) ipc_msg_hdr_struct
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
;
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
204 void put_long(const uint32_t l
, char **ptr
);
205 uint32_t get_long(char **ptr
);
207 void put_short(uint16_t s
, char **ptr
);
208 uint16_t get_short(char **ptr
);
210 #define put_flags put_long
211 #define get_flags get_long
213 #define put_error_code put_long
214 #define get_error_code get_long
216 int put_string(const char *str
, char **ptr
);
217 int get_string(char **ptr
, char *buffer
, int buflen
);
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.
223 void ConvertHeaderBytes(ipc_msg_hdr
*hdr
);
225 #endif // DNSSD_IPC_H