3 * Copyright (C) 2003, 2004 Mondru AB.
5 * The contents of this file may be used under the terms of the GNU
6 * General Public License Version 2, provided that the above copyright
7 * notice and this permission notice is included in all copies or
8 * substantial portions of the software.
13 #include <sys/socket.h>
14 #include <netinet/in.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
23 void sys_err(int pri
, char *fn
, int ln
, int en
, char *fmt
, ...)
26 char buf
[SYSERR_MSGSIZE
];
29 vsnprintf(buf
, SYSERR_MSGSIZE
, fmt
, args
);
31 buf
[SYSERR_MSGSIZE
- 1] = 0; /* Make sure it is null terminated */
33 syslog(pri
, "%s: %d: %d (%s) %s", fn
, ln
, en
, strerror(en
),
36 syslog(pri
, "%s: %d: %s", fn
, ln
, buf
);
39 void sys_errpack(int pri
, char *fn
, int ln
, int en
, struct sockaddr_in
*peer
,
40 void *pack
, unsigned len
, char *fmt
, ...)
44 char buf
[SYSERR_MSGSIZE
];
45 char buf2
[SYSERR_MSGSIZE
];
50 vsnprintf(buf
, SYSERR_MSGSIZE
, fmt
, args
);
52 buf
[SYSERR_MSGSIZE
- 1] = 0;
54 snprintf(buf2
, SYSERR_MSGSIZE
,
55 "Packet from %s:%u, length: %d, content:",
56 inet_ntoa(peer
->sin_addr
), ntohs(peer
->sin_port
), len
);
57 buf2
[SYSERR_MSGSIZE
- 1] = 0;
59 for (n
= 0; n
< len
; n
++) {
60 if ((pos
+ 4) < SYSERR_MSGSIZE
) {
61 sprintf((buf2
+ pos
), " %02hhx",
62 ((unsigned char *)pack
)[n
]);
69 syslog(pri
, "%s: %d: %d (%s) %s. %s", fn
, ln
, en
, strerror(en
),
72 syslog(pri
, "%s: %d: %s. %s", fn
, ln
, buf
, buf2
);