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