Annotation of driverkit/libDriver/Kernel/IONetwork.m, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: /*
        !            25:  * Copyright (c) 1992 NeXT Computer, Inc.
        !            26:  *
        !            27:  * Network interface class.
        !            28:  *
        !            29:  * HISTORY
        !            30:  *
        !            31:  * 1-Nov-93    John Immordino (jimmord) at NeXT
        !            32:  *     Added API to allow read access to counters and to increment counters
        !            33:  *     by an arbitrary number.  The latter is useful for hardware which
        !            34:  *     reports statistics in bursts. 
        !            35:  *
        !            36:  * 11 December 1992 David E. Bohman at NeXT
        !            37:  *     Created.
        !            38:  */
        !            39: #import        <sys/types.h>
        !            40: #import <sys/socket.h>
        !            41: #import <sys/param.h>
        !            42: #import <driverkit/IONetwork.h>
        !            43: #import <sys/mbuf.h>
        !            44: #import <net/if.h>
        !            45: #import <netinet/in.h>
        !            46: #import        <netinet/if_ether.h>
        !            47: #import <sys/kernel.h>
        !            48: 
        !            49: 
        !            50: static const char IFNAME_NULL[] = "null";
        !            51: 
        !            52: @implementation IONetwork
        !            53: 
        !            54: - initForNetworkDevice:device
        !            55:        name:(const char *)name
        !            56:        unit:(unsigned int)unit
        !            57:        type:(const char *)type
        !            58:        maxTransferUnit:(unsigned int)mtu
        !            59:        flags:(unsigned int)flags
        !            60: {
        !            61:        struct ifnet *ifp;
        !            62:        int reuse;
        !            63: 
        !            64:    [super init];
        !            65: 
        !            66:        ifp = [device allocateIfnet];
        !            67:        if(ifp == (struct ifnet *)NULL) return (0);
        !            68:        bzero((caddr_t)ifp, sizeof(struct ifnet));
        !            69: 
        !            70:        ifp->if_name = (char *)name;
        !            71:        ifp->if_type = (char *)type;
        !            72:        ifp->if_unit = unit;
        !            73:        ifp->if_mtu = mtu;
        !            74:        ifp->if_flags = flags;
        !            75:        ifp->if_private = device;
        !            76:        
        !            77: #if defined(i386) && 0                                                 // XXX fix later
        !            78:                /*************************************************
        !            79:                 * This code sets the hostid global variable for *
        !            80:                 * the i386 achitecure only.  Refer to Tracker   *
        !            81:                 * #35253 - JI                                   *
        !            82:                 *************************************************/
        !            83:                 
        !            84:                 /*
        !            85:                  * Do this only if hostid hasn't been set already.
        !            86:                  */
        !            87:                 if (hostid == 0) {
        !            88:                    unsigned char hardwareAddr[6];      
        !            89:                    
        !            90:                    /*
        !            91:                        * Get the hardware address for this interface.
        !            92:                        */
        !            93:                    if (if_control((netif_t)ifp, IFCONTROL_GETADDR,
        !            94:                        (void *)&hardwareAddr) == 0) {
        !            95:                        
        !            96:                        /* 
        !            97:                            * Xor the first 2 bytes into the 
        !            98:                            * middle 2 bytes, then set hostid.
        !            99:                            */  
        !           100:                        hardwareAddr[2] ^= hardwareAddr[0];
        !           101:                        hardwareAddr[3] ^= hardwareAddr[1];
        !           102:                        hostid = NXSwapHostLongToBig(*(long *)&hardwareAddr[2]);
        !           103:                    }
        !           104:                 }
        !           105: #endif i386
        !           106: 
        !           107:     _ifp = ifp;
        !           108:     _device = device;              
        !           109: 
        !           110:     return self;
        !           111: }
        !           112: 
        !           113: - free
        !           114: {
        !           115:     return [super free];
        !           116: }
        !           117: 
        !           118: - (int)handleInputPacket:(netbuf_t)pkt extra:(void *)extra
        !           119: {
        !           120:     if (_device == nil)
        !           121:                return -1;
        !           122: 
        !           123:     return [_device inputPacket:pkt extra:(void *)extra];
        !           124: }
        !           125: 
        !           126: - (unsigned)inputPackets
        !           127: {
        !           128:        return (_ifp->if_ipackets);
        !           129: }
        !           130: 
        !           131: - (void)incrementInputPackets
        !           132: {
        !           133:        _ifp->if_ipackets++;
        !           134: 
        !           135: }
        !           136: 
        !           137: - (void)incrementInputPacketsBy:(unsigned)increment
        !           138: {
        !           139:        _ifp->if_ipackets += increment;
        !           140: }
        !           141: 
        !           142: - (unsigned)inputErrors
        !           143: {
        !           144:        return (_ifp->if_ierrors);
        !           145: }
        !           146: 
        !           147: - (void)incrementInputErrors
        !           148: {
        !           149:        _ifp->if_ierrors++;
        !           150: }
        !           151: 
        !           152: - (void)incrementInputErrorsBy:(unsigned)increment
        !           153: {
        !           154:        _ifp->if_ierrors += increment;
        !           155: }
        !           156: 
        !           157: - (unsigned)outputPackets
        !           158: {
        !           159:        return (_ifp->if_opackets);
        !           160: }
        !           161: 
        !           162: - (void)incrementOutputPackets
        !           163: {
        !           164:        _ifp->if_opackets++;
        !           165: }
        !           166: 
        !           167: - (void)incrementOutputPacketsBy:(unsigned)increment
        !           168: {
        !           169:        _ifp->if_opackets += increment;
        !           170: }
        !           171: 
        !           172: - (unsigned)outputErrors
        !           173: {
        !           174:        return (_ifp->if_oerrors);
        !           175: }
        !           176: 
        !           177: - (void)incrementOutputErrors
        !           178: {
        !           179:        _ifp->if_oerrors++;
        !           180: }
        !           181: 
        !           182: - (void)incrementOutputErrorsBy:(unsigned)increment
        !           183: {
        !           184:        _ifp->if_oerrors += increment;
        !           185: }
        !           186: 
        !           187: - (unsigned)collisions
        !           188: {
        !           189:        return (_ifp->if_collisions);
        !           190: }
        !           191: 
        !           192: - (void)incrementCollisions
        !           193: {
        !           194:        _ifp->if_collisions++;
        !           195: }
        !           196: 
        !           197: - (void)incrementCollisionsBy:(unsigned)increment
        !           198: {
        !           199:        _ifp->if_collisions += increment;
        !           200: }
        !           201: 
        !           202: - (struct ifnet *)getIONetworkIfnet
        !           203: {
        !           204:        return(_ifp);
        !           205: }
        !           206: 
        !           207: - property_IODeviceClass:(char *)classes length:(unsigned int *)maxLen
        !           208: {
        !           209:     strcpy( classes, IOClassNetwork);
        !           210:     return( self);
        !           211: }
        !           212: 
        !           213: @end
        !           214: 

unix.superglobalmegacorp.com

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