]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/mDNSDebug.c
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 Contains: Implementation of debugging utilities. Requires a POSIX environment.
29 Change History (most recent first):
32 Revision 1.6 2005/01/27 22:57:56 cheshire
33 Fix compile errors on gcc4
35 Revision 1.5 2004/09/17 01:08:55 cheshire
36 Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
37 The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
38 declared in that file are ONLY appropriate to single-address-space embedded applications.
39 For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
41 Revision 1.4 2004/06/11 22:36:51 cheshire
42 Fixes for compatibility with Windows
44 Revision 1.3 2004/01/28 21:14:23 cheshire
45 Reconcile debug_mode and gDebugLogging into a single flag (mDNS_DebugMode)
47 Revision 1.2 2003/12/09 01:30:40 rpantos
48 Fix usage of ARGS... macros to build properly on Windows.
50 Revision 1.1 2003/12/08 21:11:42; rpantos
51 Changes necessary to support mDNSResponder on Linux.
55 #include "mDNSDebug.h"
60 // Need to add Windows syslog support here
63 #define LOG_PERROR 0x20
64 #define openlog(A,B,C) (void)(A); (void)(B)
71 #include "mDNSEmbeddedAPI.h"
74 mDNSexport
int mDNS_DebugMode
= mDNStrue
;
76 mDNSexport
int mDNS_DebugMode
= mDNSfalse
;
79 // Note, this uses mDNS_vsnprintf instead of standard "vsnprintf", because mDNS_vsnprintf knows
80 // how to print special data types like IP addresses and length-prefixed domain names
82 mDNSexport
void debugf_(const char *format
, ...)
84 unsigned char buffer
[512];
87 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
89 fprintf(stderr
,"%s\n", buffer
);
94 #if MDNS_DEBUGMSGS > 1
95 mDNSexport
void verbosedebugf_(const char *format
, ...)
97 unsigned char buffer
[512];
100 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
102 fprintf(stderr
,"%s\n", buffer
);
107 mDNSlocal
void WriteLogMsg(const char *ident
, const char *buffer
, int logoptflags
)
109 if (mDNS_DebugMode
) // In debug mode we write to stderr
111 fprintf(stderr
,"%s\n", buffer
);
114 else // else, in production mode, we write to syslog
116 openlog(ident
, LOG_CONS
| LOG_PERROR
| logoptflags
, LOG_DAEMON
);
117 syslog(LOG_ERR
, "%s", buffer
);
122 // Log message with default "mDNSResponder" ident string at the start
123 mDNSexport
void LogMsg(const char *format
, ...)
127 va_start(ptr
,format
);
128 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
130 WriteLogMsg("mDNSResponder", buffer
, 0);
133 // Log message with specified ident string at the start
134 mDNSexport
void LogMsgIdent(const char *ident
, const char *format
, ...)
138 va_start(ptr
,format
);
139 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
141 WriteLogMsg(ident
, buffer
, ident
&& *ident
? LOG_PID
: 0);
144 // Log message with no ident string at the start
145 mDNSexport
void LogMsgNoIdent(const char *format
, ...)
149 va_start(ptr
,format
);
150 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
152 WriteLogMsg("", buffer
, 0);