]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/dnssd_ipc.c
mDNSResponder-58.8.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 * 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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: dnssd_ipc.c,v $
26 Revision 1.7 2003/08/12 19:56:25 cheshire
27 Update to APSL 2.0
28
29 */
30
31 #include "dnssd_ipc.h"
32
33 void put_flags(const DNSServiceFlags flags, char **ptr)
34 {
35 memcpy(*ptr, &flags, sizeof(DNSServiceFlags));
36 *ptr += sizeof(flags);
37 }
38
39 DNSServiceFlags get_flags(char **ptr)
40 {
41 DNSServiceFlags flags;
42
43 flags = *(DNSServiceFlags *)*ptr;
44 *ptr += sizeof(DNSServiceFlags);
45 return flags;
46 }
47
48 void put_long(const uint32_t l, char **ptr)
49 {
50
51 *(uint32_t *)(*ptr) = l;
52 *ptr += sizeof(uint32_t);
53 }
54
55 uint32_t get_long(char **ptr)
56 {
57 uint32_t l;
58
59 l = *(uint32_t *)(*ptr);
60 *ptr += sizeof(uint32_t);
61 return l;
62 }
63
64 void put_error_code(const DNSServiceErrorType error, char **ptr)
65 {
66 memcpy(*ptr, &error, sizeof(error));
67 *ptr += sizeof(DNSServiceErrorType);
68 }
69
70 DNSServiceErrorType get_error_code(char **ptr)
71 {
72 DNSServiceErrorType error;
73
74 error = *(DNSServiceErrorType *)(*ptr);
75 *ptr += sizeof(DNSServiceErrorType);
76 return error;
77 }
78
79 void put_short(const uint16_t s, char **ptr)
80 {
81 *(uint16_t *)(*ptr) = s;
82 *ptr += sizeof(uint16_t);
83 }
84
85 uint16_t get_short(char **ptr)
86 {
87 uint16_t s;
88
89 s = *(uint16_t *)(*ptr);
90 *ptr += sizeof(uint16_t);
91 return s;
92 }
93
94
95 int put_string(const char *str, char **ptr)
96 {
97 if (!str) str = "";
98 strcpy(*ptr, str);
99 *ptr += strlen(str) + 1;
100 return 0;
101 }
102
103 // !!!KRS we don't properly handle the case where the string is longer than the buffer!!!
104 int get_string(char **ptr, char *buffer, int buflen)
105 {
106 int overrun;
107
108 overrun = (int)strlen(*ptr) < buflen ? 0 : -1;
109 strncpy(buffer, *ptr, buflen - 1);
110 buffer[buflen - 1] = '\0';
111 *ptr += strlen(buffer) + 1;
112 return overrun;
113 }
114
115 void put_rdata(const int rdlen, const char *rdata, char **ptr)
116 {
117 memcpy(*ptr, rdata, rdlen);
118 *ptr += rdlen;
119 }
120
121 char *get_rdata(char **ptr, int rdlen)
122 {
123 char *rd;
124
125 rd = *ptr;
126 *ptr += rdlen;
127 return rd;
128 }
129
130
131
132
133
134
135
136
137