]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/dnssd_ipc.c
mDNSResponder-66.3.tar.gz
[apple/mdnsresponder.git] / mDNSShared / dnssd_ipc.c
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 Change History (most recent first):
26
27 $Log: dnssd_ipc.c,v $
28 Revision 1.9 2004/05/18 23:51:27 cheshire
29 Tidy up all checkin comments to use consistent "<rdar://problem/xxxxxxx>" format for bug numbers
30
31 Revision 1.8 2003/11/05 22:44:57 ksekar
32 <rdar://problem/3335230>: No bounds checking when reading data from client
33 Reviewed by: Stuart Cheshire
34
35 Revision 1.7 2003/08/12 19:56:25 cheshire
36 Update to APSL 2.0
37
38 */
39
40 #include "dnssd_ipc.h"
41
42 void put_flags(const DNSServiceFlags flags, char **ptr)
43 {
44 memcpy(*ptr, &flags, sizeof(DNSServiceFlags));
45 *ptr += sizeof(flags);
46 }
47
48 DNSServiceFlags get_flags(char **ptr)
49 {
50 DNSServiceFlags flags;
51
52 flags = *(DNSServiceFlags *)*ptr;
53 *ptr += sizeof(DNSServiceFlags);
54 return flags;
55 }
56
57 void put_long(const uint32_t l, char **ptr)
58 {
59
60 *(uint32_t *)(*ptr) = l;
61 *ptr += sizeof(uint32_t);
62 }
63
64 uint32_t get_long(char **ptr)
65 {
66 uint32_t l;
67
68 l = *(uint32_t *)(*ptr);
69 *ptr += sizeof(uint32_t);
70 return l;
71 }
72
73 void put_error_code(const DNSServiceErrorType error, char **ptr)
74 {
75 memcpy(*ptr, &error, sizeof(error));
76 *ptr += sizeof(DNSServiceErrorType);
77 }
78
79 DNSServiceErrorType get_error_code(char **ptr)
80 {
81 DNSServiceErrorType error;
82
83 error = *(DNSServiceErrorType *)(*ptr);
84 *ptr += sizeof(DNSServiceErrorType);
85 return error;
86 }
87
88 void put_short(const uint16_t s, char **ptr)
89 {
90 *(uint16_t *)(*ptr) = s;
91 *ptr += sizeof(uint16_t);
92 }
93
94 uint16_t get_short(char **ptr)
95 {
96 uint16_t s;
97
98 s = *(uint16_t *)(*ptr);
99 *ptr += sizeof(uint16_t);
100 return s;
101 }
102
103
104 int put_string(const char *str, char **ptr)
105 {
106 if (!str) str = "";
107 strcpy(*ptr, str);
108 *ptr += strlen(str) + 1;
109 return 0;
110 }
111
112 int get_string(char **ptr, char *buffer, int buflen)
113 {
114 int overrun;
115
116 overrun = (int)strlen(*ptr) < buflen ? 0 : -1;
117 strncpy(buffer, *ptr, buflen - 1);
118 buffer[buflen - 1] = '\0';
119 *ptr += strlen(buffer) + 1;
120 return overrun;
121 }
122
123 void put_rdata(const int rdlen, const char *rdata, char **ptr)
124 {
125 memcpy(*ptr, rdata, rdlen);
126 *ptr += rdlen;
127 }
128
129 char *get_rdata(char **ptr, int rdlen)
130 {
131 char *rd;
132
133 rd = *ptr;
134 *ptr += rdlen;
135 return rd;
136 }
137
138
139
140
141
142
143
144
145