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