Libinfo-173.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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26
27
28 #ifndef DNSSD_IPC_H
29 #define DNSSD_IPC_H
30
31 #include "dns_sd.h"
32 #include <sys/types.h>
33 #include <unistd.h>
34 #include <sys/un.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <sys/stat.h>
39
40 #define UDSDEBUG // verbose debug output
41
42 // General UDS constants
43 #define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
44 #define LISTENQ 100
45 #define TXT_RECORD_INDEX -1 // record index for default text record
46 #define MAX_CTLPATH 256 // longest legal control path length
47
48 // IPC data encoding constants and types
49 #define VERSION 1
50 #define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
51 #define IPC_FLAGS_REUSE_SOCKET 2 // set flag if synchronous errors are to be sent via the primary socket
52 // (if not set, first string in message buffer must be path to error socket
53
54
55 typedef enum
56 {
57 connection = 1, // connected socket via DNSServiceConnect()
58 reg_record_request, // reg/remove record only valid for connected sockets
59 remove_record_request,
60 enumeration_request,
61 reg_service_request,
62 browse_request,
63 resolve_request,
64 query_request,
65 reconfirm_record_request,
66 add_record_request,
67 update_record_request
68 } request_op_t;
69
70 typedef enum
71 {
72 enumeration_reply = 64,
73 reg_service_reply,
74 browse_reply,
75 resolve_reply,
76 query_reply,
77 reg_record_reply
78 } reply_op_t;
79
80
81 typedef struct ipc_msg_hdr_struct ipc_msg_hdr;
82
83
84 // client stub callback to process message from server and deliver results to
85 // client application
86
87 typedef void (*process_reply_callback)
88 (
89 DNSServiceRef sdr,
90 ipc_msg_hdr *hdr,
91 char *msg
92 );
93
94 // allow 64-bit client to interoperate w/ 32-bit daemon
95 typedef union
96 {
97 void *context;
98 uint32_t ptr64[2];
99 } client_context_t;
100
101
102 typedef struct ipc_msg_hdr_struct
103 {
104 uint32_t version;
105 uint32_t datalen;
106 uint32_t flags;
107 union
108 {
109 request_op_t request_op;
110 reply_op_t reply_op;
111 } op;
112 client_context_t client_context; // context passed from client, returned by server in corresponding reply
113 int reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
114 // socket connected by DNSServiceConnect(). Must be unique in the scope of the connection, such that and
115 // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
116 } ipc_msg_hdr_struct;
117
118
119
120
121 // routines to write to and extract data from message buffers.
122 // caller responsible for bounds checking.
123 // ptr is the address of the pointer to the start of the field.
124 // it is advanced to point to the next field, or the end of the message
125
126
127 void put_flags(const DNSServiceFlags flags, char **ptr);
128 DNSServiceFlags get_flags(char **ptr);
129
130 void put_long(const uint32_t l, char **ptr);
131 uint32_t get_long(char **ptr);
132
133 void put_error_code(const DNSServiceErrorType, char **ptr);
134 DNSServiceErrorType get_error_code(char **ptr);
135
136 int put_string(const char *str, char **ptr);
137 int get_string(char **ptr, char *buffer, int buflen);
138
139 void put_rdata(const int rdlen, const char *rdata, char **ptr);
140 char *get_rdata(char **ptr, int rdlen); // return value is rdata pointed to by *ptr -
141 // rdata is not copied from buffer.
142
143 void put_short(uint16_t s, char **ptr);
144 uint16_t get_short(char **ptr);
145
146
147
148 #endif // DNSSD_IPC_H
149
150
151
152
153
154
155
156
157
158
159