Annotation of embedaddon/coova-chilli/src/syserr.c, revision 1.1
1.1 ! misho 1: /*
! 2: *
! 3: * Syslog functions.
! 4: * Copyright (C) 2003, 2004 Mondru AB.
! 5: * Copyright (c) 2006-2007 David Bird <david@coova.com>
! 6: *
! 7: * The contents of this file may be used under the terms of the GNU
! 8: * General Public License Version 2, provided that the above copyright
! 9: * notice and this permission notice is included in all copies or
! 10: * substantial portions of the software.
! 11: *
! 12: */
! 13:
! 14: #include "system.h"
! 15: #include "syserr.h"
! 16: #include "radius.h"
! 17: #include "md5.h"
! 18: #include "dhcp.h"
! 19: #include "redir.h"
! 20: #include "chilli.h"
! 21: #include "options.h"
! 22: #include "bstrlib.h"
! 23:
! 24: void sys_err(int pri, char *fn, int ln, int en, const char *fmt, ...) {
! 25: if (pri==LOG_DEBUG && !options.debug) return;
! 26: {
! 27: bstring bt = bfromcstralloc(128,"");
! 28: int sz;
! 29:
! 30: bvformata(sz, bt, fmt, fmt);
! 31:
! 32: if (options.foreground && options.debug) {
! 33: fprintf(stderr, "%s: %d: %d (%s) %s\n", fn, ln, en, en ? strerror(en) : "Debug", bt->data);
! 34: } else {
! 35: if (en)
! 36: syslog(pri, "%s: %d: %d (%s) %s", fn, ln, en, strerror(en), bt->data);
! 37: else
! 38: syslog(pri, "%s: %d: %s", fn, ln, bt->data);
! 39: }
! 40:
! 41: bdestroy(bt);
! 42: }
! 43: }
! 44:
! 45: void sys_errpack(int pri, char *fn, int ln, int en, struct sockaddr_in *peer,
! 46: void *pack, unsigned len, char *fmt, ...) {
! 47: bstring bt = bfromcstr("");
! 48: bstring bt2 = bfromcstr("");
! 49: int sz;
! 50: int n;
! 51:
! 52: bvformata(sz, bt, fmt, fmt);
! 53:
! 54: bassignformat(bt2, ". Packet from %s:%u, length: %d, content:",
! 55: inet_ntoa(peer->sin_addr),
! 56: ntohs(peer->sin_port),
! 57: len);
! 58:
! 59: bconcat(bt, bt2);
! 60:
! 61: for(n=0; n < len; n++) {
! 62: bassignformat(bt, " %02hhx", ((unsigned char*)pack)[n]);
! 63: bconcat(bt, bt2);
! 64: }
! 65:
! 66: if (options.foreground && options.debug) {
! 67: fprintf(stderr, "%s: %d: %d (%s) %s", fn, ln, en, strerror(en), bt->data);
! 68: } else {
! 69: if (en)
! 70: syslog(pri, "%s: %d: %d (%s) %s", fn, ln, en, strerror(en), bt->data);
! 71: else
! 72: syslog(pri, "%s: %d: %s", fn, ln, bt->data);
! 73: }
! 74:
! 75: bdestroy(bt);
! 76: bdestroy(bt2);
! 77: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>