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