]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/mDNSDebug.c
d7b19f0b7a711c7c56036f36d089293caf65bbb8
1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 Contains: Implementation of debugging utilities. Requires a POSIX environment.
23 Change History (most recent first):
26 Revision 1.7 2006/08/14 23:24:56 cheshire
27 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
29 Revision 1.6 2005/01/27 22:57:56 cheshire
30 Fix compile errors on gcc4
32 Revision 1.5 2004/09/17 01:08:55 cheshire
33 Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
34 The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
35 declared in that file are ONLY appropriate to single-address-space embedded applications.
36 For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
38 Revision 1.4 2004/06/11 22:36:51 cheshire
39 Fixes for compatibility with Windows
41 Revision 1.3 2004/01/28 21:14:23 cheshire
42 Reconcile debug_mode and gDebugLogging into a single flag (mDNS_DebugMode)
44 Revision 1.2 2003/12/09 01:30:40 rpantos
45 Fix usage of ARGS... macros to build properly on Windows.
47 Revision 1.1 2003/12/08 21:11:42; rpantos
48 Changes necessary to support mDNSResponder on Linux.
52 #include "mDNSDebug.h"
57 // Need to add Windows syslog support here
60 #define LOG_PERROR 0x20
61 #define openlog(A,B,C) (void)(A); (void)(B)
68 #include "mDNSEmbeddedAPI.h"
71 mDNSexport
int mDNS_DebugMode
= mDNStrue
;
73 mDNSexport
int mDNS_DebugMode
= mDNSfalse
;
76 // Note, this uses mDNS_vsnprintf instead of standard "vsnprintf", because mDNS_vsnprintf knows
77 // how to print special data types like IP addresses and length-prefixed domain names
79 mDNSexport
void debugf_(const char *format
, ...)
81 unsigned char buffer
[512];
84 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
86 fprintf(stderr
,"%s\n", buffer
);
91 #if MDNS_DEBUGMSGS > 1
92 mDNSexport
void verbosedebugf_(const char *format
, ...)
94 unsigned char buffer
[512];
97 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
99 fprintf(stderr
,"%s\n", buffer
);
104 mDNSlocal
void WriteLogMsg(const char *ident
, const char *buffer
, int logoptflags
)
106 if (mDNS_DebugMode
) // In debug mode we write to stderr
108 fprintf(stderr
,"%s\n", buffer
);
111 else // else, in production mode, we write to syslog
113 openlog(ident
, LOG_CONS
| LOG_PERROR
| logoptflags
, LOG_DAEMON
);
114 syslog(LOG_ERR
, "%s", buffer
);
119 // Log message with default "mDNSResponder" ident string at the start
120 mDNSexport
void LogMsg(const char *format
, ...)
124 va_start(ptr
,format
);
125 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
127 WriteLogMsg("mDNSResponder", buffer
, 0);
130 // Log message with specified ident string at the start
131 mDNSexport
void LogMsgIdent(const char *ident
, const char *format
, ...)
135 va_start(ptr
,format
);
136 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
138 WriteLogMsg(ident
, buffer
, ident
&& *ident
? LOG_PID
: 0);
141 // Log message with no ident string at the start
142 mDNSexport
void LogMsgNoIdent(const char *format
, ...)
146 va_start(ptr
,format
);
147 buffer
[mDNS_vsnprintf((char *)buffer
, sizeof(buffer
), format
, ptr
)] = 0;
149 WriteLogMsg("", buffer
, 0);