]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/mdns_objects/mdns_helpers.h
mDNSResponder-1310.40.42.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / mdns_objects / mdns_helpers.h
1 /*
2 * Copyright (c) 2019-2020 Apple Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __MDNS_HELPERS_H__
18 #define __MDNS_HELPERS_H__
19
20 #include "mdns_base.h"
21
22 #include <MacTypes.h>
23 #include <netinet/in.h>
24
25 MDNS_ASSUME_NONNULL_BEGIN
26
27 __BEGIN_DECLS
28
29 int
30 mdns_snprintf_add(char * _Nonnull * _Nonnull ptr, const char * _Nullable lim, const char *fmt, ...);
31
32 OSStatus
33 mdns_replace_string(char * _Nullable * _Nonnull string_ptr, const char * _Nullable new_string);
34
35 OSStatus
36 mdns_make_socket_nonblocking(int sock);
37
38 uint64_t
39 mdns_mach_ticks_per_second(void);
40
41 int
42 mdns_print_obfuscated_ip_address(char *buf_ptr, size_t buf_len, const struct sockaddr *sa);
43
44 __END_DECLS
45
46 MDNS_ASSUME_NONNULL_END
47
48 #define MDNS_LOG_CATEGORY_DEFINE(SHORT_NAME, CATEGORY_STR) \
49 static os_log_t \
50 _mdns_ ## SHORT_NAME ## _log(void) \
51 { \
52 static dispatch_once_t s_once = 0; \
53 static os_log_t s_log = NULL; \
54 dispatch_once(&s_once, \
55 ^{ \
56 s_log = os_log_create("com.apple.mdns", CATEGORY_STR); \
57 }); \
58 return s_log; \
59 } \
60 extern int _mdns_dummy_variable
61
62 #if !defined(nw_forget)
63 #define nw_forget(X) ForgetCustom(X, nw_release)
64 #endif
65
66 #if !defined(nw_release_null_safe)
67 #define nw_release_null_safe(X) do { if (X) { nw_release(X); } } while (0)
68 #endif
69
70 #if !defined(nwi_state_release_null_safe)
71 #define nwi_state_release_null_safe(X) do { if (X) { nwi_state_release(X); } } while (0)
72 #endif
73
74 #define _mdns_socket_forget(PTR) \
75 do { \
76 if (IsValidSocket(*(PTR))) { \
77 close(*(PTR)); \
78 *(PTR) = kInvalidSocketRef; \
79 } \
80 } while (0)
81
82 #endif // __MDNS_HELPERS_H__