3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_log.c,v 1.3 1999/08/28 01:15:33 peter Exp $
32 * Server Cache Synchronization Protocol (SCSP) Support
33 * ----------------------------------------------------
35 * SCSP logging routines
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <netatm/port.h>
45 #include <netatm/queue.h>
46 #include <netatm/atm.h>
47 #include <netatm/atm_if.h>
48 #include <netatm/atm_sap.h>
49 #include <netatm/atm_sys.h>
50 #include <netatm/atm_ioctl.h>
70 __RCSID("@(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_log.c,v 1.3 1999/08/28 01:15:33 peter Exp $");
77 FILE *scsp_trace_file = (FILE *)0;
81 * Write a message to SCSP's log
84 * level pointer to an SCSP cache key structure
85 * fmt printf-style format string
86 * ... parameters for printf-style use according to fmt
94 scsp_log(const int level, const char *fmt, ...)
96 scsp_log(level, fmt, va_alist)
111 * In debug mode, just write to stdout
113 if (scsp_debug_mode) {
120 * Write to syslog if it's active or if no log file is set up
122 if (scsp_log_syslog || !scsp_log_file) {
123 vsyslog(level, fmt, ap);
127 * Write to the log file if there's one set up
130 vfprintf(scsp_log_file, fmt, ap);
131 fprintf(scsp_log_file, "\n");
139 * Open SCSP's trace file
156 UM_ZERO(fname, sizeof(fname));
157 sprintf(fname, "/tmp/scspd.%d.trace", getpid());
160 * Open the trace file. If the open fails, log an error, but
161 * keep going. The trace routine will notice that the file
162 * isn't open and won't try to write to it.
164 scsp_trace_file = fopen(fname, "w");
165 if (scsp_trace_file == (FILE *)0) {
166 scsp_log(LOG_ERR, "Can't open trace file");
172 * Write a message to SCSP's trace file
175 * fmt printf-style format string
176 * ... parameters for printf-style use according to fmt
184 scsp_trace(const char *fmt, ...)
186 scsp_trace(fmt, va_alist)
200 * Write the message to the trace file, if it's open
202 if (scsp_trace_file) {
203 vfprintf(scsp_trace_file, fmt, ap);
211 * Write an SCSP message to SCSP's trace file
214 * dcsp pointer to DCS block for the message
215 * msg pointer to the message
216 * dir a direction indicator--0 for sending, 1 for receiving
223 scsp_trace_msg(dcsp, msg, dir)
231 * Copy the remote IP address into a struct in_addr
233 UM_COPY(dcsp->sd_dcsid.id, &addr.s_addr,
234 sizeof(struct in_addr));
237 * Write the message to the trace file, if it's open
239 if (scsp_trace_file) {
240 scsp_trace("SCSP message at 0x%x %s %s\n",
242 (dir ? "received from" : "sent to"),
243 format_ip_addr(&addr));
244 print_scsp_msg(scsp_trace_file, msg);
250 * Log a memory error and exit
256 * exits, does not return
263 scsp_log(LOG_CRIT, "out of memory: %s", cp);