Annotation of Net2/netccitt/pk_debug.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) University of British Columbia, 1984
        !             3:  * Copyright (c) 1990 The Regents of the University of California.
        !             4:  * All rights reserved.
        !             5:  *
        !             6:  * This code is derived from software contributed to Berkeley by
        !             7:  * the Laboratory for Computation Vision and the Computer Science Department
        !             8:  * of the University of British Columbia.
        !             9:  *
        !            10:  * Redistribution and use in source and binary forms, with or without
        !            11:  * modification, are permitted provided that the following conditions
        !            12:  * are met:
        !            13:  * 1. Redistributions of source code must retain the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer.
        !            15:  * 2. Redistributions in binary form must reproduce the above copyright
        !            16:  *    notice, this list of conditions and the following disclaimer in the
        !            17:  *    documentation and/or other materials provided with the distribution.
        !            18:  * 3. All advertising materials mentioning features or use of this software
        !            19:  *    must display the following acknowledgement:
        !            20:  *     This product includes software developed by the University of
        !            21:  *     California, Berkeley and its contributors.
        !            22:  * 4. Neither the name of the University nor the names of its contributors
        !            23:  *    may be used to endorse or promote products derived from this software
        !            24:  *    without specific prior written permission.
        !            25:  *
        !            26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            36:  * SUCH DAMAGE.
        !            37:  *
        !            38:  *     @(#)pk_debug.c  7.7 (Berkeley) 5/9/91
        !            39:  */
        !            40: 
        !            41: #include "param.h"
        !            42: #include "systm.h"
        !            43: #include "mbuf.h"
        !            44: #include "socket.h"
        !            45: #include "protosw.h"
        !            46: #include "socketvar.h"
        !            47: #include "errno.h"
        !            48: 
        !            49: #include "../net/if.h"
        !            50: 
        !            51: #include "x25.h"
        !            52: #include "pk.h"
        !            53: #include "pk_var.h"
        !            54: 
        !            55: char   *pk_state[] = {
        !            56:        "Listen",       "Ready",        "Received-Call",
        !            57:        "Sent-Call",    "Data-Transfer","Received-Clear",
        !            58:        "Sent-Clear",
        !            59: };
        !            60: 
        !            61: char   *pk_name[] = {
        !            62:        "Call",         "Call-Conf",    "Clear",
        !            63:        "Clear-Conf",   "Data",         "Intr",         "Intr-Conf",
        !            64:        "Rr",           "Rnr",          "Reset",        "Reset-Conf",
        !            65:        "Restart",      "Restart-Conf", "Reject",       "Diagnostic",
        !            66:        "Invalid"
        !            67: };
        !            68: 
        !            69: pk_trace (xcp, m, dir)
        !            70: struct x25config *xcp;
        !            71: register struct mbuf *m;
        !            72: char *dir;
        !            73: {
        !            74:        register char *s;
        !            75:        struct x25_packet *xp = mtod(m, struct x25_packet *);
        !            76:        register int i, len = 0, cnt = 0;
        !            77: 
        !            78:        if (xcp -> xc_ptrace == 0)
        !            79:                return;
        !            80: 
        !            81:        i = pk_decode (xp) / MAXSTATES;
        !            82:        for (; m; m = m -> m_next) {
        !            83:                len = len + m -> m_len;
        !            84:                ++cnt;
        !            85:        }
        !            86:        printf ("LCN=%d %s:     %s      #=%d, len=%d ",
        !            87:                LCN(xp), dir, pk_name[i], cnt, len);
        !            88:        for (s = (char *) xp, i = 0; i < 5; ++i, ++s)
        !            89:                printf ("%x ", (int) * s & 0xff);
        !            90:        printf ("\n");
        !            91: }
        !            92: 
        !            93: mbuf_cache(c, m)
        !            94: register struct mbuf_cache *c;
        !            95: struct mbuf *m;
        !            96: {
        !            97:        register struct mbuf **mp;
        !            98: 
        !            99:        if (c->mbc_size != c->mbc_oldsize) {
        !           100:                unsigned zero_size, copy_size;
        !           101:                unsigned new_size = c->mbc_size * sizeof(m);
        !           102:                caddr_t cache = (caddr_t)c->mbc_cache;
        !           103: 
        !           104:                if (new_size) {
        !           105:                        c->mbc_cache = (struct mbuf **)
        !           106:                                malloc(new_size, M_MBUF, M_NOWAIT);
        !           107:                        if (c->mbc_cache == 0) {
        !           108:                                c->mbc_cache = (struct mbuf **)cache;
        !           109:                                return;
        !           110:                        }
        !           111:                        c->mbc_num %= c->mbc_size;
        !           112:                } else
        !           113:                        c->mbc_cache = 0;
        !           114:                if (c->mbc_size < c->mbc_oldsize) {
        !           115:                        register struct mbuf **mplim;
        !           116:                        mp = c->mbc_size + (struct mbuf **)cache;
        !           117:                        mplim = c->mbc_oldsize + (struct mbuf **)cache;
        !           118:                        while (mp < mplim)
        !           119:                                m_freem(*mp++);
        !           120:                        zero_size = 0;
        !           121:                } else
        !           122:                        zero_size = (c->mbc_size - c->mbc_oldsize) * sizeof(m);
        !           123:                copy_size = new_size - zero_size;
        !           124:                c->mbc_oldsize = c->mbc_size;
        !           125:                if (copy_size)
        !           126:                        bcopy(cache, (caddr_t)c->mbc_cache, copy_size);
        !           127:                if (cache)
        !           128:                        free(cache, M_MBUF);
        !           129:                if (zero_size)
        !           130:                        bzero(copy_size + (caddr_t)c->mbc_cache, zero_size);
        !           131:        }
        !           132:        if (c->mbc_size == 0)
        !           133:                return;
        !           134:        mp = c->mbc_cache + c->mbc_num;
        !           135:        c->mbc_num = (1 + c->mbc_num) % c->mbc_size;
        !           136:        if (*mp)
        !           137:                m_freem(*mp);
        !           138:        *mp = m_copym(m, 0, M_COPYALL, M_DONTWAIT);
        !           139: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.