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