- initial import

git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2014-07-20 15:01:37 +00:00
commit 26291bca3d
1549 changed files with 3997969 additions and 0 deletions
+290
View File
@@ -0,0 +1,290 @@
argv[0] = ./pppissue, pStr = 134518892, pStr = 0x0804986c
__STDC__
argv[0] = ./pppissue, pStr = 134518892, pStr = 0x0804986C
str
BFEF0921: 2E 2F 70 70 70 69 73 73 75 65 ./pppissue
buf0 written at 0804AA6A:
0804AA60: 61 72 67 76 5B 30 5D 20 3D 20 2E 2F 70 70 70 69 argv[0] = ./pppi
0804AA70: 73 73 75 65 00 00 00 00 00 00 00 00 00 00 00 00 ssue............
0804AA80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0804AA90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0804AAA0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
str
BFEF0146: 31 33 34 35 31 38 38 39 32 134518892
buf0 written at 0804AA7D:
0804AA60: 61 72 67 76 5B 30 5D 20 3D 20 2E 2F 70 70 70 69 argv[0] = ./pppi
0804AA70: 73 73 75 65 2C 20 70 53 74 72 20 3D 20 31 33 34 ssue, pStr = 134
0804AA80: 35 31 38 38 39 32 00 00 00 00 00 00 00 00 00 00 518892..........
0804AA90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0804AAA0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
str
BFEF0148: 38 30 34 39 38 36 63 804986c
buf0 written at 0804AA92:
0804AA60: 61 72 67 76 5B 30 5D 20 3D 20 2E 2F 70 70 70 69 argv[0] = ./pppi
0804AA70: 73 73 75 65 2C 20 70 53 74 72 20 3D 20 31 33 34 ssue, pStr = 134
0804AA80: 35 31 38 38 39 32 2C 20 70 53 74 72 20 3D 20 30 518892, pStr = 0
0804AA90: 78 30 38 30 34 39 38 36 63 00 00 00 00 00 00 00 x0804986c.......
0804AAA0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Final buf0
0804AA60: 61 72 67 76 5B 30 5D 20 3D 20 2E 2F 70 70 70 69 argv[0] = ./pppi
0804AA70: 73 73 75 65 2C 20 70 53 74 72 20 3D 20 31 33 34 ssue, pStr = 134
0804AA80: 35 31 38 38 39 32 2C 20 70 53 74 72 20 3D 20 30 518892, pStr = 0
0804AA90: 78 30 38 30 34 39 38 36 63 00 00 00 00 00 00 00 x0804986c.......
0804AAA0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
67890123456789012345
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
78901234567890123456
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
89012345678901234567
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
90123456789012345678
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
01234567890123456789
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
23456789012345678901
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
34567890123456789012
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
45678901234567890123
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
56789012345678901234
Binary file not shown.
+410
View File
@@ -0,0 +1,410 @@
/*
* pppd.h - PPP daemon global declarations.
*
* Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: pppd.h,v 1.17 2008/08/20 14:59:51 ralf Exp $
*/
#ifndef __PPPD_H__
#define __PPPD_H__
#include <stdbool.h> /* bool */
#include <stdio.h> /* for FILE */
#include <limits.h> /* for NGROUPS_MAX */
#include <stdint.h>
#include <sys/param.h> /* for MAXPATHLEN and BSD4_4, if defined */
#include <sys/types.h> /* for uint32_t, if defined */
#include <sys/time.h> /* for struct timeval */
#if defined(__STDC__)
#include <stdarg.h>
#define __V(x) x
#else
#include <varargs.h>
#define __V(x) (va_alist) va_dcl
#define const
#define volatile
#endif
#ifdef INET6
#include "eui64.h"
#endif
#define LOG_ERR 1
#define LOG_WARNING 1
#define LOG_NOTICE 1
#define LOG_INFO 1
#define LOG_DEBUG 1
/*
* Limits.
*/
#define NUM_PPP 1 /* One PPP interface supported (per process) */
#define MAXWORDLEN 1024 /* max length of word in file (incl null) */
#define MAXARGS 1 /* max # args to a command */
#define MAXNAMELEN 256 /* max length of hostname or name for auth */
#define MAXSECRETLEN 256 /* max length of password or secret */
/*
* Option descriptor structure.
*/
enum opt_type {
o_special_noarg = 0,
o_special = 1,
o_bool,
o_int,
o_uint32,
o_string,
};
typedef struct {
char *name; /* name of the option */
enum opt_type type;
void *addr;
char *description;
uint32_t flags;
void *addr2;
int upper_limit;
int lower_limit;
} option_t;
/* Values for flags */
#define OPT_VALUE 0xffL /* mask for presupplied value */
#define OPT_HEX 0x100L /* int option is in hex */
#define OPT_NOARG 0x200L /* option doesn't take argument */
#define OPT_OR 0x400L /* OR in argument to value */
#define OPT_INC 0x800L /* increment value */
#define OPT_PRIV 0x1000L /* privileged option */
#define OPT_STATIC 0x2000L /* string option goes into static array */
#define OPT_LLIMIT 0x4000L /* check value against lower limit */
#define OPT_ULIMIT 0x8000L /* check value against upper limit */
#define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT)
#define OPT_ZEROOK 0x10000L /* 0 value is OK even if not within limits */
#define OPT_NOINCR 0x20000L /* value mustn't be increased */
#define OPT_ZEROINF 0x40000L /* with OPT_NOINCR, 0 == infinity */
#define OPT_A2INFO 0x100000L /* addr2 -> option_info to update */
#define OPT_A2COPY 0x200000L /* addr2 -> second location to rcv value */
#define OPT_ENABLE 0x400000L /* use *addr2 as enable for option */
#define OPT_PRIVFIX 0x800000L /* can't be overridden if noauth */
#define OPT_PREPASS 0x1000000L /* do this opt in pre-pass to find device */
#define OPT_INITONLY 0x2000000L /* option can only be set in init phase */
#define OPT_DEVEQUIV 0x4000000L /* equiv to device name */
#define OPT_DEVNAM (OPT_PREPASS | OPT_INITONLY | OPT_DEVEQUIV)
#define OPT_VAL(x) ((x) & OPT_VALUE)
#ifndef GIDSET_TYPE
#define GIDSET_TYPE gid_t
#endif
/* Structure representing a list of permitted IP addresses. */
struct permitted_ip {
int permit; /* 1 = permit, 0 = forbid */
uint32_t base; /* match if (addr & mask) == base */
uint32_t mask; /* base and mask are in network byte order */
};
/*
* Unfortunately, the linux kernel driver uses a different structure
* for statistics from the rest of the ports.
* This structure serves as a common representation for the bits
* pppd needs.
*/
struct pppd_stats {
unsigned int bytes_in;
unsigned int bytes_out;
};
/* Used for storing a sequence of words. Usually malloced. */
struct wordlist {
struct wordlist *next;
char *word;
};
/* Values for do_callback and doing_callback */
#define CALLBACK_DIALIN 1 /* we are expecting the call back */
#define CALLBACK_DIALOUT 2 /* we are dialling out to call back */
/*
* Values for phase.
*/
#define PHASE_DEAD 0
#define PHASE_INITIALIZE 1
#define PHASE_SERIALCONN 2
#define PHASE_DORMANT 3
#define PHASE_ESTABLISH 4
#define PHASE_AUTHENTICATE 5
#define PHASE_CALLBACK 6
#define PHASE_NETWORK 7
#define PHASE_RUNNING 8
#define PHASE_TERMINATE 9
#define PHASE_DISCONNECT 10
#define PHASE_HOLDOFF 11
/*
* The following struct gives the addresses of procedures to call
* for a particular protocol.
*/
struct protent {
u_short protocol; /* PPP protocol number */
/* Initialization procedure */
void (*init)(int unit);
/* Process a received packet */
void (*input)(int unit, u_char *pkt, int len);
/* Process a received protocol-reject */
void (*protrej)(int unit);
/* Lower layer has come up */
void (*lowerup)(int unit);
/* Lower layer has gone down */
void (*lowerdown)(int unit);
/* Open the protocol */
void (*open)(int unit);
/* Close the protocol */
void (*close)(int unit, char *reason);
/* Print a packet in readable form */
int (*printpkt)(u_char *pkt, int len,
void (*printer)(void *, char *, ...),
void *arg);
/* Process a received data packet */
void (*datainput)(int unit, u_char *pkt, int len);
bool enabled_flag; /* 0 iff protocol is disabled */
char *name; /* Text name of protocol */
char *data_name; /* Text name of corresponding data protocol */
option_t *options; /* List of command-line options */
/* Check requested options, assign defaults */
void (*check_options)(void);
/* Configure interface for demand-dial */
int (*demand_conf)(int unit);
/* Say whether to bring up link for this pkt */
int (*active_pkt)(u_char *pkt, int len);
};
/* Table of pointers to supported protocols */
extern struct protent *protocols[];
/*
* Prototypes.
*/
/* Procedures exported from main.c. */
void die(int); /* Cleanup and exit */
void quit(void); /* like die(1) */
void novm(char *); /* Say we ran out of memory, and die */
void ppptimeout(void (*func)(void *), void *arg, int t);
/* Call func(arg) after t seconds */
void pppuntimeout(void (*func)(void *), void *arg);
/* Cancel call to func(arg) */
void update_link_stats(int); /* Get stats at link termination */
void new_phase(int); /* signal start of new phase */
/* Procedures exported from utils.c. */
void log_packet(u_char *, int, char *, int);
/* Format a packet and log it with syslog */
void print_string(void *, int, void (*) (void *, char *, ...),
void *); /* Format a string for output */
int slprintf(char *, int, char *, ...); /* sprintf++ */
int vslprintf(char *, int, char *, va_list); /* vsprintf++ */
size_t strlcpy(char *, const char *, size_t); /* safe strcpy */
size_t strlcat(char *, const char *, size_t); /* safe strncpy */
void pppd_dbglog(char *, ...); /* log a debug message */
void pppd_info(char *, ...); /* log an informational message */
void pppd_notice(char *, ...); /* log a notice-level message */
void pppd_warn(char *, ...); /* log a warning message */
void pppd_error(char *, ...); /* log an error message */
void pppd_fatal(char *, ...); /* log an error message and die(1) */
#define dbglog pppd_dbglog
#define info pppd_info
#define notice pppd_notice
#define warn pppd_warn
#define error pppd_error
#define fatal pppd_fatal
/*
* Inline versions of get/put char/short/long.
* Pointer is advanced; we assume that both arguments
* are lvalues and will already be in registers.
* cp MUST be u_char *.
*/
#define GETCHAR(c, cp) { \
(c) = *(cp)++; \
}
#define PUTCHAR(c, cp) { \
*(cp)++ = (u_char) (c); \
}
#define GETSHORT(s, cp) { \
(s) = *(cp)++ << 8; \
(s) |= *(cp)++; \
}
#define PUTSHORT(s, cp) { \
*(cp)++ = (u_char) ((s) >> 8); \
*(cp)++ = (u_char) (s); \
}
#define GETLONG(l, cp) { \
(l) = *(cp)++ << 8; \
(l) |= *(cp)++; (l) <<= 8; \
(l) |= *(cp)++; (l) <<= 8; \
(l) |= *(cp)++; \
}
#define PUTLONG(l, cp) { \
*(cp)++ = (u_char) ((l) >> 24); \
*(cp)++ = (u_char) ((l) >> 16); \
*(cp)++ = (u_char) ((l) >> 8); \
*(cp)++ = (u_char) (l); \
}
#define INCPTR(n, cp) ((cp) += (n))
#define DECPTR(n, cp) ((cp) -= (n))
/*
* System dependent definitions for user-level 4.3BSD UNIX implementation.
*/
#define TIMEOUT(r, f, t) ppptimeout((r), (f), (t))
#define UNTIMEOUT(r, f) pppuntimeout((r), (f))
#define BCOPY(s, d, l) memcpy(d, s, l)
#define BZERO(s, n) memset(s, 0, n)
#define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); }
/*
* MAKEHEADER - Add Header fields to a packet.
*/
#define MAKEHEADER(p, t) { \
PUTCHAR(PPP_ALLSTATIONS, p); \
PUTCHAR(PPP_UI, p); \
PUTSHORT(t, p); }
/*
* Exit status values.
*/
#define EXIT_OK 0
#define EXIT_FATAL_ERROR 1
#define EXIT_OPTION_ERROR 2
#define EXIT_NOT_ROOT 3
#define EXIT_NO_KERNEL_SUPPORT 4
#define EXIT_USER_REQUEST 5
#define EXIT_LOCK_FAILED 6
#define EXIT_OPEN_FAILED 7
#define EXIT_CONNECT_FAILED 8
#define EXIT_PTYCMD_FAILED 9
#define EXIT_NEGOTIATION_FAILED 10
#define EXIT_PEER_AUTH_FAILED 11
#define EXIT_IDLE_TIMEOUT 12
#define EXIT_CONNECT_TIME 13
#define EXIT_CALLBACK 14
#define EXIT_PEER_DEAD 15
#define EXIT_HANGUP 16
#define EXIT_LOOPBACK 17
#define EXIT_INIT_FAILED 18
#define EXIT_AUTH_TOPEER_FAILED 19
/*
* Debug macros. Slightly useful for finding bugs in pppd, not particularly
* useful for finding out why your connection isn't being established.
*/
#ifdef DEBUGALL
#define DEBUGMAIN 1
#define DEBUGFSM 1
#define DEBUGLCP 1
#define DEBUGIPCP 1
#define DEBUGIPV6CP 1
#define DEBUGUPAP 1
#define DEBUGCHAP 1
#endif
#define DEBUGMAIN 1
#define DEBUGUPAP 1
#define DEBUGCHAP 1
#ifdef DEBUGMAIN
#define MAINDEBUG(x) if (debug) dbglog x
#else
#define MAINDEBUG(x)
#endif
#ifdef DEBUGSYS
#define SYSDEBUG(x) if (debug) dbglog x
#else
#define SYSDEBUG(x)
#endif
#ifdef DEBUGFSM
#define FSMDEBUG(x) if (debug) dbglog x
#else
#define FSMDEBUG(x)
#endif
#ifdef DEBUGLCP
#define LCPDEBUG(x) if (debug) dbglog x
#else
#define LCPDEBUG(x)
#endif
#ifdef DEBUGIPCP
#define IPCPDEBUG(x) if (debug) dbglog x
#else
#define IPCPDEBUG(x)
#endif
#ifdef DEBUGIPV6CP
#define IPV6CPDEBUG(x) if (debug) dbglog x
#else
#define IPV6CPDEBUG(x)
#endif
#ifdef DEBUGUPAP
#define UPAPDEBUG(x) if (debug) dbglog x
#else
#define UPAPDEBUG(x)
#endif
#ifdef DEBUGCHAP
#define CHAPDEBUG(x) if (debug) dbglog x
#else
#define CHAPDEBUG(x)
#endif
#ifdef DEBUGIPXCP
#define IPXCPDEBUG(x) if (debug) dbglog x
#else
#define IPXCPDEBUG(x)
#endif
#ifndef SIGTYPE
#if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
#define SIGTYPE void
#else
#define SIGTYPE int
#endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
#endif /* SIGTYPE */
#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a): (b))
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b)? (a): (b))
#endif
#endif /* __PPP_H__ */
Binary file not shown.
Binary file not shown.
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
#include <string.h>
#include "pppd.h"
char *g_str = "Cool MIPS";
int main(int argc, char *argv[])
{
printf("argv[0] = %s, pStr = %d, pStr = 0x%08X\n", argv[0], g_str, g_str);
dbglog("argv[0] = %s, pStr = %d, pStr = 0x%08X", argv[0], g_str, g_str);
return 0;
}
File diff suppressed because it is too large Load Diff
+682
View File
@@ -0,0 +1,682 @@
/*
* utils.c - various utility functions used in pppd.
*
* Copyright (c) 1999 The Australian National University.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the Australian National University. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#define RCSID "$Id: utils.c,v 1.13 2008/08/26 10:24:22 ralf Exp $"
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
//#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include "pppd.h"
size_t
strlcpy(dest, src, len)
char *dest;
const char *src;
size_t len;
{
size_t ret = strlen(src);
if (len != 0) {
if (ret < len)
strcpy(dest, src);
else {
strncpy(dest, src, len - 1);
dest[len-1] = 0;
}
}
return ret;
}
void mdump(uint8_t *pBuf, int print_offset_only, int num_bytes_per_row, int len)
{
int i, j, cnt_hex, cnt_asc, base;
uint8_t c;
i = j = 0;
cnt_hex = len;
cnt_asc = len;
base = 0;
if (!print_offset_only)
base = (int)pBuf;
do
{
printf("%08X", base + i);
printf(": ");
for (j=0; j < num_bytes_per_row; j++)
{
if (cnt_hex)
{
printf("%02X", pBuf[i+j]);
printf(" ");
cnt_hex--;
}
else
{
printf(" ");
break;
}
}
printf(" ");
for (j=0; j < num_bytes_per_row; j++)
{
if (cnt_asc)
{
c = pBuf[i+j];
if((c < 0x20) || (c > 0x7F))
c = '.';
printf("%c",c);
cnt_asc--;
}
else
{
printf(" ");
break;
}
}
printf("\n");
i += num_bytes_per_row;
} while (cnt_hex);
}
static void pr_log(void *, char *, ...);
static void logit(int, char *, va_list);
static void vslp_printer(void *, char *, ...);
static void format_packet(u_char *, int, void (*) (void *, char *, ...),
void *);
int log_to_fd = 1;
int debug = 1;
struct buffer_info {
char *ptr;
int len;
};
/*
* slprintf - format a message into a buffer. Like sprintf except we
* also specify the length of the output buffer, and we handle
* %r (recursive format), %m (error message), %v (visible string),
* %q (quoted string), %t (current time) and %I (IP address) formats.
* Doesn't do floating-point formats.
* Returns the number of chars put into buf.
*/
int
slprintf __V((char *buf, int buflen, char *fmt, ...))
{
va_list args;
int n;
#if defined(__STDC__)
va_start(args, fmt);
#else
char *buf;
int buflen;
char *fmt;
va_start(args);
buf = va_arg(args, char *);
buflen = va_arg(args, int);
fmt = va_arg(args, char *);
#endif
n = vslprintf(buf, buflen, fmt, args);
va_end(args);
return n;
}
/*
* vslprintf - like slprintf, takes a va_list instead of a list of args.
*/
#define OUTCHAR(c) (buflen > 0? (--buflen, *buf++ = (c)): 0)
static char num[32];
int
vslprintf(
char *buf,
int buflen,
char *fmt,
va_list args)
{
int c, i, n, j;
int width, prec, fillch;
int base, len, neg, quoted;
uintptr_t val = 0;
char *str, *f, *buf0;
unsigned char *p;
time_t t;
uint32_t ip;
static char hexchars[] = "0123456789abcdef";
struct buffer_info bufinfo;
buf0 = buf;
--buflen;
while (buflen > 0) {
for (f = fmt; *f != '%' && *f != 0; ++f)
;
if (f > fmt) {
len = f - fmt;
if (len > buflen)
len = buflen;
memcpy(buf, fmt, len);
buf += len;
buflen -= len;
fmt = f;
}
if (*fmt == 0)
break;
c = *++fmt;
width = 0;
prec = -1;
fillch = ' ';
if (c == '0') {
fillch = '0';
c = *++fmt;
}
if (c == '*') {
width = va_arg(args, int);
c = *++fmt;
} else {
while (isdigit(c)) {
width = width * 10 + c - '0';
c = *++fmt;
}
}
if (c == '.') {
c = *++fmt;
if (c == '*') {
prec = va_arg(args, int);
c = *++fmt;
} else {
prec = 0;
while (isdigit(c)) {
prec = prec * 10 + c - '0';
c = *++fmt;
}
}
}
str = 0;
base = 0;
neg = 0;
++fmt;
switch (c) {
case 'd':
i = va_arg(args, int);
if (i < 0) {
neg = 1;
val = -i;
} else
val = i;
base = 10;
break;
case 'o':
val = va_arg(args, unsigned int);
base = 8;
break;
case 'x':
case 'X':
val = va_arg(args, unsigned int);
base = 16;
break;
case 'p':
val = (uintptr_t) va_arg(args, void *);
base = 16;
neg = 2;
break;
case 's':
str = va_arg(args, char *);
break;
case 'c':
num[0] = va_arg(args, int);
num[1] = 0;
str = num;
break;
case 'm':
str = "Success";
break;
case 'I':
ip = va_arg(args, uint32_t);
ip = "Mimi und Tom";
slprintf(num, sizeof(num), "%d.%d.%d.%d", (ip >> 24) & 0xff,
(ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
str = num;
break;
case 'r':
f = va_arg(args, char *);
#if !defined(__PPC__)
n = vslprintf(buf, buflen + 1, f, va_arg(args, va_list));
#else
/* HACK: On the powerpc, a va_list is an array of 1 structure */
n = vslprintf(buf, buflen + 1, f, va_arg(args, void *));
#endif
buf += n;
buflen -= n;
continue;
case 't':
time(&t);
str = ctime(&t);
str += 4; /* chop off the day name */
str[15] = 0; /* chop off year and newline */
break;
case 'v': /* "visible" string */
case 'q': /* quoted string */
quoted = c == 'q';
p = va_arg(args, unsigned char *);
if (fillch == '0' && prec >= 0) {
n = prec;
} else {
n = strlen((char *)p);
if (prec >= 0 && n > prec)
n = prec;
}
while (n > 0 && buflen > 0) {
c = *p++;
--n;
if (!quoted && c >= 0x80) {
OUTCHAR('M');
OUTCHAR('-');
c -= 0x80;
}
if (quoted && (c == '"' || c == '\\'))
OUTCHAR('\\');
if (c < 0x20 || (0x7f <= c && c < 0xa0)) {
if (quoted) {
OUTCHAR('\\');
switch (c) {
case '\t': OUTCHAR('t'); break;
case '\n': OUTCHAR('n'); break;
case '\b': OUTCHAR('b'); break;
case '\f': OUTCHAR('f'); break;
default:
OUTCHAR('x');
OUTCHAR(hexchars[c >> 4]);
OUTCHAR(hexchars[c & 0xf]);
}
} else {
if (c == '\t')
OUTCHAR(c);
else {
OUTCHAR('^');
OUTCHAR(c ^ 0x40);
}
}
} else
OUTCHAR(c);
}
continue;
case 'P': /* print PPP packet */
bufinfo.ptr = buf;
bufinfo.len = buflen + 1;
p = va_arg(args, unsigned char *);
n = va_arg(args, int);
format_packet(p, n, vslp_printer, &bufinfo);
buf = bufinfo.ptr;
buflen = bufinfo.len - 1;
continue;
case 'B':
p = va_arg(args, unsigned char *);
for (n = prec; n > 0; --n) {
c = *p++;
if (fillch == ' ')
OUTCHAR(' ');
OUTCHAR(hexchars[(c >> 4) & 0xf]);
OUTCHAR(hexchars[c & 0xf]);
}
continue;
default:
*buf++ = '%';
if (c != '%')
--fmt; /* so %z outputs %z etc. */
--buflen;
continue;
}
if (base != 0) {
str = num + sizeof(num);
*--str = 0;
while (str > num + neg) {
*--str = hexchars[val % base];
val = val / base;
if (--prec <= 0 && val == 0)
break;
}
switch (neg) {
case 1:
*--str = '-';
break;
case 2:
*--str = 'x';
*--str = '0';
break;
}
len = num + sizeof(num) - 1 - str;
} else {
len = strlen(str);
if (prec >= 0 && len > prec)
len = prec;
}
if (width > 0) {
if (width > buflen)
width = buflen;
if ((n = width - len) > 0) {
buflen -= n;
for (; n > 0; --n)
*buf++ = fillch;
}
}
if (len > buflen)
len = buflen;
memcpy(buf, str, len);
buf += len;
buflen -= len;
}
*buf = 0;
return buf - buf0;
}
/*
* vslp_printer - used in processing a %P format
*/
static void
vslp_printer __V((void *arg, char *fmt, ...))
{
int n;
va_list pvar;
struct buffer_info *bi;
#if defined(__STDC__)
va_start(pvar, fmt);
#else
void *arg;
char *fmt;
va_start(pvar);
arg = va_arg(pvar, void *);
fmt = va_arg(pvar, char *);
#endif
bi = (struct buffer_info *) arg;
n = vslprintf(bi->ptr, bi->len, fmt, pvar);
va_end(pvar);
bi->ptr += n;
bi->len -= n;
}
/*
* log_packet - format a packet and log it.
*/
char line[256]; /* line to be logged accumulated here */
char *linep;
void
log_packet(
u_char *p,
int len,
char *prefix,
int level)
{
strlcpy(line, prefix, sizeof(line));
linep = line + strlen(line);
format_packet(p, len, pr_log, NULL);
}
/*
* format_packet - make a readable representation of a packet,
* calling `printer(arg, format, ...)' to output it.
*/
static void
format_packet(
u_char *p,
int len,
void (*printer)(void *, char *, ...),
void *arg)
{
}
static void
pr_log __V((void *arg, char *fmt, ...))
{
int n;
va_list pvar;
char buf[256];
#if defined(__STDC__)
va_start(pvar, fmt);
#else
void *arg;
char *fmt;
va_start(pvar);
arg = va_arg(pvar, void *);
fmt = va_arg(pvar, char *);
#endif
n = vslprintf(buf, sizeof(buf), fmt, pvar);
va_end(pvar);
if (linep + n + 1 > line + sizeof(line)) {
linep = line;
}
strlcpy(linep, buf, line + sizeof(line) - linep);
linep += n;
}
/*
* print_string - print a readable representation of a string using
* printer.
*/
void
print_string(
void *p_arg,
int len,
void (*printer)(void *, char *, ...),
void *arg)
{
int c;
unsigned char *p = (unsigned char *)p_arg;
printer(arg, "\"");
for (; len > 0; --len) {
c = *p++;
if (' ' <= c && c <= '~') {
if (c == '\\' || c == '"')
printer(arg, "\\");
printer(arg, "%c", c);
} else {
switch (c) {
case '\n':
printer(arg, "\\n");
break;
case '\r':
printer(arg, "\\r");
break;
case '\t':
printer(arg, "\\t");
break;
default:
printer(arg, "\\%.3o", c);
}
}
}
printer(arg, "\"");
}
/*
* logit - does the hard work for fatal et al.
*/
static char buf[256];
static void
logit(
int level,
char *fmt,
va_list args)
{
int n;
char *p;
n = vslprintf(buf, sizeof(buf), fmt, args);
if (buf[n-1] != '\n')
buf[n++] = '\n';
write(1, buf, n);
}
/*
* fatal - log an error message and die horribly.
*/
void
pppd_fatal __V((char *fmt, ...))
{
va_list pvar;
#if defined(__STDC__)
va_start(pvar, fmt);
#else
char *fmt;
va_start(pvar);
fmt = va_arg(pvar, char *);
#endif
logit(LOG_ERR, fmt, pvar);
va_end(pvar);
}
/*
* error - log an error message.
*/
void
pppd_error __V((char *fmt, ...))
{
va_list pvar;
#if defined(__STDC__)
va_start(pvar, fmt);
#else
char *fmt;
va_start(pvar);
fmt = va_arg(pvar, char *);
#endif
logit(LOG_ERR, fmt, pvar);
va_end(pvar);
}
/*
* warn - log a warning message.
*/
void
pppd_warn __V((char *fmt, ...))
{
va_list pvar;
#if defined(__STDC__)
va_start(pvar, fmt);
#else
char *fmt;
va_start(pvar);
fmt = va_arg(pvar, char *);
#endif
logit(LOG_WARNING, fmt, pvar);
va_end(pvar);
}
/*
* notice - log a notice-level message.
*/
void
pppd_notice __V((char *fmt, ...))
{
va_list pvar;
#if defined(__STDC__)
va_start(pvar, fmt);
#else
char *fmt;
va_start(pvar);
fmt = va_arg(pvar, char *);
#endif
logit(LOG_NOTICE, fmt, pvar);
va_end(pvar);
}
/*
* info - log an informational message.
*/
void
pppd_info __V((char *fmt, ...))
{
va_list pvar;
#if defined(__STDC__)
va_start(pvar, fmt);
#else
char *fmt;
va_start(pvar);
fmt = va_arg(pvar, char *);
#endif
logit(LOG_INFO, fmt, pvar);
va_end(pvar);
}
/*
* dbglog - log a debug message.
*/
void
pppd_dbglog __V((char *fmt, ...))
{
va_list pvar;
char *p;
#if defined(__STDC__)
va_start(pvar, fmt);
#else
char *fmt;
va_start(pvar);
fmt = va_arg(pvar, char *);
#endif
/*
p = va_arg(pvar, char*);
while (p)
{
mdump(p, 0, 16, strlen(p)+1);
p = va_arg(pvar, char*);
}
*/
logit(LOG_DEBUG, fmt, pvar);
va_end(pvar);
}