Annotation of Net2/netccitt/pk_acct.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_acct.c   7.6 (Berkeley) 6/26/91
        !            39:  */
        !            40: 
        !            41: #include "param.h"
        !            42: #include "systm.h"
        !            43: #include "namei.h"
        !            44: #include "proc.h"
        !            45: #include "vnode.h"
        !            46: #include "kernel.h"
        !            47: #include "file.h"
        !            48: #include "socket.h"
        !            49: #include "socketvar.h"
        !            50: 
        !            51: #include "../net/if.h"
        !            52: 
        !            53: #include "x25.h"
        !            54: #include "pk.h"
        !            55: #include "pk_var.h"
        !            56: #include "x25acct.h"
        !            57: 
        !            58: 
        !            59: struct vnode *pkacctp;
        !            60: /* 
        !            61:  *  Turn on packet accounting
        !            62:  */
        !            63: 
        !            64: pk_accton (path)
        !            65:        char *path;
        !            66: {
        !            67:        register struct vnode *vp = NULL;
        !            68:        struct nameidata nd;
        !            69:        struct vnode *oacctp = pkacctp;
        !            70:        struct proc *p = curproc;
        !            71:        int error;
        !            72: 
        !            73:        if (path == 0)
        !            74:                goto close;
        !            75:        nd.ni_segflg = UIO_USERSPACE;
        !            76:        nd.ni_dirp = path;
        !            77:        if (error = vn_open (&nd, p, FWRITE, 0644))
        !            78:                return (error);
        !            79:        vp = nd.ni_vp;
        !            80:        VOP_UNLOCK(vp);
        !            81:        if (vp -> v_type != VREG) {
        !            82:                vrele (vp);
        !            83:                return (EACCES);
        !            84:        }
        !            85:        pkacctp = vp;
        !            86:        if (oacctp) {
        !            87:        close:
        !            88:                error = vn_close (oacctp, FWRITE, p -> p_ucred, p);
        !            89:        }
        !            90:        return (error);
        !            91: }
        !            92: 
        !            93: /* 
        !            94:  *  Write a record on the accounting file.
        !            95:  */
        !            96: 
        !            97: pk_acct (lcp)
        !            98: register struct pklcd *lcp;
        !            99: {
        !           100:        register struct vnode *vp;
        !           101:        register struct sockaddr_x25 *sa;
        !           102:        register char *src, *dst;
        !           103:        register int len;
        !           104:        register long etime;
        !           105:        static struct x25acct acbuf;
        !           106: 
        !           107:        if ((vp = pkacctp) == 0)
        !           108:                return;
        !           109:        bzero ((caddr_t)&acbuf, sizeof (acbuf));
        !           110:        if (lcp -> lcd_ceaddr != 0)
        !           111:                sa = lcp -> lcd_ceaddr;
        !           112:        else if (lcp -> lcd_craddr != 0) {
        !           113:                sa = lcp -> lcd_craddr;
        !           114:                acbuf.x25acct_callin = 1;
        !           115:        } else
        !           116:                return;
        !           117: 
        !           118:        if (sa -> x25_opts.op_flags & X25_REVERSE_CHARGE)
        !           119:                acbuf.x25acct_revcharge = 1;
        !           120:        acbuf.x25acct_stime = lcp -> lcd_stime;
        !           121:        acbuf.x25acct_etime = time.tv_sec - acbuf.x25acct_stime;
        !           122:        acbuf.x25acct_uid = curproc -> p_cred -> p_ruid;
        !           123:        acbuf.x25acct_psize = sa -> x25_opts.op_psize;
        !           124:        acbuf.x25acct_net = sa -> x25_net;
        !           125:        /*
        !           126:         * Convert address to bcd
        !           127:         */
        !           128:        src = sa -> x25_addr;
        !           129:        dst = acbuf.x25acct_addr;
        !           130:        for (len = 0; *src; len++)
        !           131:                if (len & 01)
        !           132:                        *dst++ |= *src++ & 0xf;
        !           133:                else
        !           134:                        *dst = *src++ << 4;
        !           135:        acbuf.x25acct_addrlen = len;
        !           136: 
        !           137:        bcopy (sa -> x25_udata, acbuf.x25acct_udata,
        !           138:                sizeof (acbuf.x25acct_udata));
        !           139:        acbuf.x25acct_txcnt = lcp -> lcd_txcnt;
        !           140:        acbuf.x25acct_rxcnt = lcp -> lcd_rxcnt;
        !           141: 
        !           142:        (void) vn_rdwr(UIO_WRITE, vp, (caddr_t)&acbuf, sizeof (acbuf),
        !           143:                (off_t)0, UIO_SYSSPACE, IO_UNIT|IO_APPEND,
        !           144:                curproc -> p_ucred, (int *)0,
        !           145:                (struct proc *)0);
        !           146: }

unix.superglobalmegacorp.com

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