source: rtems-libbsd/mDNSResponder/mDNSShared/mDNSDebug.c @ f7205c1

4.115-freebsd-12freebsd-9.3
Last change on this file since f7205c1 was f7205c1, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 23, 2014 at 2:27:19 PM

mDNS: mDNSShared/mDNSDebug.c

Avoid reference to ProgramName?.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17    File:               mDNSDebug.c
18
19    Contains:   Implementation of debugging utilities. Requires a POSIX environment.
20
21    Version:    1.0
22
23 */
24
25#include "mDNSDebug.h"
26
27#include <stdio.h>
28
29#if defined(WIN32) || defined(EFI32) || defined(EFI64) || defined(EFIX64)
30// Need to add Windows/EFI syslog support here
31#define LOG_PID 0x01
32#define LOG_CONS 0x02
33#define LOG_PERROR 0x20
34#else
35#include <syslog.h>
36#endif
37
38#include "mDNSEmbeddedAPI.h"
39
40mDNSexport int mDNS_LoggingEnabled       = 0;
41mDNSexport int mDNS_PacketLoggingEnabled = 0;
42mDNSexport int mDNS_McastLoggingEnabled  = 0;
43mDNSexport int mDNS_McastTracingEnabled  = 0; 
44
45#if MDNS_DEBUGMSGS
46mDNSexport int mDNS_DebugMode = mDNStrue;
47#else
48mDNSexport int mDNS_DebugMode = mDNSfalse;
49#endif
50
51// Note, this uses mDNS_vsnprintf instead of standard "vsnprintf", because mDNS_vsnprintf knows
52// how to print special data types like IP addresses and length-prefixed domain names
53#if MDNS_DEBUGMSGS > 1
54mDNSexport void verbosedebugf_(const char *format, ...)
55{
56    char buffer[512];
57    va_list ptr;
58    va_start(ptr,format);
59    buffer[mDNS_vsnprintf(buffer, sizeof(buffer), format, ptr)] = 0;
60    va_end(ptr);
61    mDNSPlatformWriteDebugMsg(buffer);
62}
63#endif
64
65// Log message with default "mDNSResponder" ident string at the start
66mDNSlocal void LogMsgWithLevelv(mDNSLogLevel_t logLevel, const char *format, va_list ptr)
67{
68    char buffer[512];
69    buffer[mDNS_vsnprintf((char *)buffer, sizeof(buffer), format, ptr)] = 0;
70#ifndef __rtems__
71    mDNSPlatformWriteLogMsg(ProgramName, buffer, logLevel);
72#else /* __rtems__ */
73    mDNSPlatformWriteLogMsg(NULL, buffer, logLevel);
74#endif /* __rtems__ */
75}
76
77#define LOG_HELPER_BODY(L) \
78    { \
79        va_list ptr; \
80        va_start(ptr,format); \
81        LogMsgWithLevelv(L, format, ptr); \
82        va_end(ptr); \
83    }
84
85// see mDNSDebug.h
86#if !MDNS_HAS_VA_ARG_MACROS
87void LogMsg_(const char *format, ...)       LOG_HELPER_BODY(MDNS_LOG_MSG)
88void LogOperation_(const char *format, ...) LOG_HELPER_BODY(MDNS_LOG_OPERATION)
89void LogSPS_(const char *format, ...)       LOG_HELPER_BODY(MDNS_LOG_SPS)
90void LogInfo_(const char *format, ...)      LOG_HELPER_BODY(MDNS_LOG_INFO)
91#endif
92
93#if MDNS_DEBUGMSGS
94void debugf_(const char *format, ...)       LOG_HELPER_BODY(MDNS_LOG_DEBUG)
95#endif
96
97// Log message with default "mDNSResponder" ident string at the start
98mDNSexport void LogMsgWithLevel(mDNSLogLevel_t logLevel, const char *format, ...)
99LOG_HELPER_BODY(logLevel)
Note: See TracBrowser for help on using the repository browser.