2 * Copyright (c) 2019-2020 Apple Inc. All rights reserved.
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
8 * https://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __MDNS_HELPERS_H__
18 #define __MDNS_HELPERS_H__
20 #include "mdns_base.h"
23 #include <netinet/in.h>
25 MDNS_ASSUME_NONNULL_BEGIN
30 mdns_snprintf_add(char * _Nonnull
* _Nonnull ptr
, const char * _Nullable lim
, const char *fmt
, ...);
33 mdns_replace_string(char * _Nullable
* _Nonnull string_ptr
, const char * _Nullable new_string
);
36 mdns_make_socket_nonblocking(int sock
);
39 mdns_mach_ticks_per_second(void);
42 mdns_print_obfuscated_ip_address(char *buf_ptr
, size_t buf_len
, const struct sockaddr
*sa
);
46 MDNS_ASSUME_NONNULL_END
48 #define MDNS_LOG_CATEGORY_DEFINE(SHORT_NAME, CATEGORY_STR) \
50 _mdns_ ## SHORT_NAME ## _log(void) \
52 static dispatch_once_t s_once = 0; \
53 static os_log_t s_log = NULL; \
54 dispatch_once(&s_once, \
56 s_log = os_log_create("com.apple.mdns", CATEGORY_STR); \
60 extern int _mdns_dummy_variable
62 #if !defined(nw_forget)
63 #define nw_forget(X) ForgetCustom(X, nw_release)
66 #if !defined(nw_release_null_safe)
67 #define nw_release_null_safe(X) do { if (X) { nw_release(X); } } while (0)
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)
74 #define _mdns_socket_forget(PTR) \
76 if (IsValidSocket(*(PTR))) { \
78 *(PTR) = kInvalidSocketRef; \
82 #endif // __MDNS_HELPERS_H__