Deleted Added
full compact
mbuf.c (25630) mbuf.c (26516)
1/*
2 * PPP Memory handling module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP Memory handling module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: mbuf.c,v 1.5 1997/02/22 16:10:34 peter Exp $
20 * $Id: mbuf.c,v 1.6 1997/05/10 01:22:15 brian Exp $
21 *
22 */
21 *
22 */
23#include <sys/types.h>
24#include <sys/socket.h>
25#include <sys/param.h>
26#include <netinet/in.h>
23#include "defs.h"
27#include "defs.h"
28#include "loadalias.h"
29#include "vars.h"
24
25struct memmap {
26 struct mbuf *queue;
27 int count;
28} MemMap[MB_MAX+2];
29
30static int totalalloced;
31

--- 12 unchanged lines hidden (view full) ---

44mballoc(cnt, type)
45int cnt;
46int type;
47{
48 u_char *p;
49 struct mbuf *bp;
50
51 if (type > MB_MAX)
30
31struct memmap {
32 struct mbuf *queue;
33 int count;
34} MemMap[MB_MAX+2];
35
36static int totalalloced;
37

--- 12 unchanged lines hidden (view full) ---

50mballoc(cnt, type)
51int cnt;
52int type;
53{
54 u_char *p;
55 struct mbuf *bp;
56
57 if (type > MB_MAX)
52 logprintf("bad type %d\n", type);
58 LogPrintf(LogERROR, "Bad mbuf type %d\n", type);
53 bp = (struct mbuf *)malloc(sizeof(struct mbuf));
54 if (bp == NULL) {
59 bp = (struct mbuf *)malloc(sizeof(struct mbuf));
60 if (bp == NULL) {
55 logprintf("failed to allocate memory: %u\n", sizeof(struct mbuf));
56 fprintf(stderr,"failed to allocate memory: %u\n", sizeof(struct mbuf));
57 exit(0);
61 LogPrintf(LogALERT, "failed to allocate memory: %u\n", sizeof(struct mbuf));
62 exit(1);
58 }
59 bzero(bp, sizeof(struct mbuf));
60 p = (u_char *)malloc(cnt);
61 if (p == NULL) {
63 }
64 bzero(bp, sizeof(struct mbuf));
65 p = (u_char *)malloc(cnt);
66 if (p == NULL) {
62 logprintf("failed to allocate memory: %d\n", cnt);
63 fprintf(stderr,"failed to allocate memory: %d\n", cnt);
64 exit(0);
67 LogPrintf(LogALERT, "failed to allocate memory: %d\n", cnt);
68 exit(1);
65 }
66 MemMap[type].count += cnt;
67 totalalloced += cnt;
68 bp->base = p;
69 bp->size = bp->cnt = cnt;
70 bp->type = type;
71 return(bp);
72}

--- 66 unchanged lines hidden (view full) ---

139 while (cnt > 0) {
140 nb = (cnt < bp->cnt)? cnt : bp->cnt;
141 bcopy(ptr, MBUF_CTOP(bp), nb);
142 cnt -= bp->cnt;
143 bp = bp->next;
144 }
145}
146
69 }
70 MemMap[type].count += cnt;
71 totalalloced += cnt;
72 bp->base = p;
73 bp->size = bp->cnt = cnt;
74 bp->type = type;
75 return(bp);
76}

--- 66 unchanged lines hidden (view full) ---

143 while (cnt > 0) {
144 nb = (cnt < bp->cnt)? cnt : bp->cnt;
145 bcopy(ptr, MBUF_CTOP(bp), nb);
146 cnt -= bp->cnt;
147 bp = bp->next;
148 }
149}
150
147void
148DumpBp(bp)
149struct mbuf *bp;
150{
151 u_char *cp;
152 int cnt, loc;
153
154 logprintf("dump bp = %x (%d)\n", bp, plength(bp));
155 loc = 0;
156 while (bp) {
157 cp = MBUF_CTOP(bp);
158 cnt = bp->cnt;
159 while (cnt > 0) {
160 logprintf("%02x", *cp++);
161 loc++;
162 if (loc == 16) {
163 loc = 0;
164 logprintf("\n");
165 } else
166 logprintf(" ");
167 cnt--;
168 }
169 bp = bp->next;
170 }
171 if (loc) logprintf("\n");
172}
173
174int
175ShowMemMap()
176{
177 int i;
178
151int
152ShowMemMap()
153{
154 int i;
155
179 for (i = 0; i <= MB_MAX; i += 2) {
180 printf("%d: %d %d: %d\r\n",
156 if (!VarTerm)
157 return 1;
158
159 for (i = 0; i <= MB_MAX; i += 2)
160 fprintf(VarTerm, "%d: %d %d: %d\n",
181 i, MemMap[i].count, i+1, MemMap[i+1].count);
161 i, MemMap[i].count, i+1, MemMap[i+1].count);
182 }
183 return(1);
162
163 return 0;
184}
185
186void
187LogMemory()
188{
164}
165
166void
167LogMemory()
168{
189#ifdef DEBUG
190 logprintf("mem alloced: %d\n", totalalloced);
191 logprintf(" 1: %d 2: %d 3: %d 4: %d\n",
169 LogPrintf(LogDEBUG, "LogMemory: mem alloced: %d\n", totalalloced);
170 LogPrintf(LogDEBUG, "LogMemory: 1: %d 2: %d 3: %d 4: %d\n",
192 MemMap[1].count, MemMap[2].count, MemMap[3].count, MemMap[4].count);
171 MemMap[1].count, MemMap[2].count, MemMap[3].count, MemMap[4].count);
193 logprintf(" 5: %d 6: %d 7: %d 8: %d\n",
172 LogPrintf(LogDEBUG, "LogMemory: 5: %d 6: %d 7: %d 8: %d\n",
194 MemMap[5].count, MemMap[6].count, MemMap[7].count, MemMap[8].count);
173 MemMap[5].count, MemMap[6].count, MemMap[7].count, MemMap[8].count);
195#endif
196}
174}