Annotation of xinu/sys/TEST/test.c.eth2, revision 1.1.1.1

1.1       root        1: /* test.c - main */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <deqna.h>
                      6: #include <ether.h>
                      7: #include <ip.h>
                      8: #include <arp.h>
                      9: 
                     10: /*------------------------------------------------------------------------
                     11:  *  main  --  test ethernet by reading packets
                     12:  *------------------------------------------------------------------------
                     13:  */
                     14: main()
                     15: {
                     16:        char    buff[1600];
                     17:        struct  xx      {
                     18:                struct  eheader ethead;
                     19:                struct  arppak  arpout;
                     20:        } outpak;
                     21:        int     i, iterate, len;
                     22:        char    *p, ch;
                     23:        struct  arppak  *arpptr;
                     24:        struct  epacket *epkptr;
                     25: 
                     26:        /* call buffer pool stuff so 'freebuf' can be mentioned */
                     27:        /* without generating a load-time error */
                     28:        mkpool(10,10);
                     29: 
                     30:        printf("Read %d packets from Ethernet\n", iterate=2);
                     31:        epkptr = (struct epacket *)buff;
                     32:        while (iterate--) {
                     33:            len = read(ETHER, buff, 1500);
                     34:            epkptr->ep_hdr.e_ptype = netorder(epkptr->ep_hdr.e_ptype);
                     35:            if (len == SYSERR) {
                     36:                kprintf("\nError...\n");
                     37:            } else if (epkptr->ep_hdr.e_ptype == EP_ARP) {
                     38:                /* do ARP */ kprintf("ARP...\n");
                     39:            } else {
                     40:                p = (char *)buff;
                     41:                kprintf("\n TYP: %d\n",epkptr->ep_hdr.e_ptype);
                     42:                kprintf(" LEN: %d\n  TO: ",len);
                     43:                for (i=0 ; i<6 ; i++)
                     44:                        kprintf("%03o ", 0377& *p++);
                     45:                kprintf("\nFROM: ");
                     46:                for (i=0 ; i<6 ; i++)
                     47:                        kprintf("%03o ", 0377& *p++);
                     48:                kprintf("\nTYPE: ");
                     49:                kprintf("%03o ", 0377 & *p++);
                     50:                kprintf("%03o ", 0377 & *p++);
                     51:                kprintf("\nDATA: ");
                     52:                for (i=0 ; i<60 ; i++) {
                     53:                        ch = *p++;
                     54:                        if ( ((ch >= 'a') && (ch <= 'z')) ||
                     55:                             ((ch >= 'A') && (ch <= 'Z')) )
                     56:                                kprintf("%c",ch);
                     57:                }
                     58:                kprintf("\n");
                     59:            }
                     60:        }
                     61: 
                     62:        kprintf("Preparing to transmit ARP request %d times...\n", iterate=2);
                     63:        /* make up packet */
                     64: 
                     65:        for (i=0 ; i<EPADLEN ; i++) {
                     66:                outpak.ethead.e_dest[i] = 0377;
                     67:        }
                     68:        blkcopy(outpak.ethead.e_src, eth[0].etpaddr, EPADLEN);
                     69:        outpak.ethead.e_ptype = netorder(EP_ARP);
                     70:        outpak.arpout.ar_hrd = netorder(AR_HRD);
                     71:        outpak.arpout.ar_prot = netorder(AR_PROT); 
                     72:        outpak.arpout.ar_hlen = AR_HLEN;
                     73:        outpak.arpout.ar_plen = AR_PLEN;
                     74:        outpak.arpout.ar_op = netorder(AR_REQ);
                     75:        for (i=0 ; i<EPADLEN ; i++) {
                     76:                outpak.arpout.ar_sha[i] = eth[0].etpaddr[i];
                     77:                outpak.arpout.ar_tha[i] = (char)0;
                     78:        }
                     79:        dot2ip(outpak.arpout.ar_spa,192,5,48,30);       /* xinutest1 */
                     80:        dot2ip(outpak.arpout.ar_tpa,192,5,48,23);       /* Lancelot*/
                     81:        epkptr = (struct epacket *) buff;
                     82:        arpptr = (struct arppak *) epkptr->ep_data;
                     83:        while (iterate--) {
                     84:                if ( (len=sizeof(struct xx)) < EMINPAK)
                     85:                        len = EMINPAK;
                     86:                kprintf("Sending %d byte packet\n", len);
                     87:                if (write(ETHER, &outpak,len) == SYSERR)
                     88:                        kprintf("\nTE\n");
                     89:                len = read(ETHER, buff,1500);
                     90:                epkptr->ep_hdr.e_ptype = netorder(epkptr->ep_hdr.e_ptype);
                     91:                if (len == SYSERR) {
                     92:                        kprintf("\nRE\n");
                     93:                } else if (epkptr->ep_hdr.e_ptype == EP_ARP) {
                     94:                        kprintf("ARP: len=%d\n",len);
                     95:                        kprintf(" FR: %o %o %o %o %o %o\n",
                     96:                                epkptr->ep_hdr.e_src[0] &0377,
                     97:                                epkptr->ep_hdr.e_src[1] &0377,
                     98:                                epkptr->ep_hdr.e_src[2] &0377,
                     99:                                epkptr->ep_hdr.e_src[3] &0377,
                    100:                                epkptr->ep_hdr.e_src[4] &0377,
                    101:                                epkptr->ep_hdr.e_src[5] &0377);
                    102:                        kprintf(" TO: %o %o %o %o %o %o\n",
                    103:                                epkptr->ep_hdr.e_dest[0] &0377,
                    104:                                epkptr->ep_hdr.e_dest[1] &0377,
                    105:                                epkptr->ep_hdr.e_dest[2] &0377,
                    106:                                epkptr->ep_hdr.e_dest[3] &0377,
                    107:                                epkptr->ep_hdr.e_dest[4] &0377,
                    108:                                epkptr->ep_hdr.e_dest[5] &0377);
                    109:                        kprintf(" OP: %d\n SH: %o %o %o %o %o %o \n",
                    110:                                netorder(arpptr->ar_op),
                    111:                                arpptr->ar_sha[0] &0377,
                    112:                                arpptr->ar_sha[1] &0377,
                    113:                                arpptr->ar_sha[2] &0377,
                    114:                                arpptr->ar_sha[3] &0377,
                    115:                                arpptr->ar_sha[4] &0377,
                    116:                                arpptr->ar_sha[5] &0377);
                    117:                        kprintf(" SP: %d.%d.%d.%d\n",
                    118:                                arpptr->ar_spa[0] &0377,
                    119:                                arpptr->ar_spa[1] &0377,
                    120:                                arpptr->ar_spa[2] &0377,
                    121:                                arpptr->ar_spa[3] &0377);
                    122:                        kprintf(" TH: %o %o %o %o %o %o\n TP: %d.%d.%d.%d\n",
                    123:                                arpptr->ar_tha[0] &0377,
                    124:                                arpptr->ar_tha[1] &0377,
                    125:                                arpptr->ar_tha[2] &0377,
                    126:                                arpptr->ar_tha[3] &0377,
                    127:                                arpptr->ar_tha[4] &0377,
                    128:                                arpptr->ar_tha[5] &0377,
                    129:                                arpptr->ar_tpa[0] &0377,
                    130:                                arpptr->ar_tpa[1] &0377,
                    131:                                arpptr->ar_tpa[2] &0377,
                    132:                                arpptr->ar_tpa[3] &0377);
                    133:                } else {
                    134:                        kprintf("Typ=%o\n",netorder(epkptr->ep_hdr.e_ptype));
                    135:                        iterate++;
                    136:                }
                    137:        }               
                    138: }
                    139: 
                    140: dot2ip(ip, b1, b2, b3, b4)
                    141: char   *ip;
                    142: int    b1, b2, b3, b4;
                    143: {
                    144:        *ip++ = LOWBYTE & b1;
                    145:        *ip++ = LOWBYTE & b2;
                    146:        *ip++ = LOWBYTE & b3;
                    147:        *ip++ = LOWBYTE & b4;
                    148: }
                    149: 
                    150: 
                    151: netorder(i)
                    152: int    i;
                    153: {
                    154:        char c;
                    155: 
                    156:        return( ((i&0377)<<8) | ((i>>8)&0377) );
                    157: }
                    158: 
                    159: 
                    160: blkcopy(to, from, bytes)
                    161: char   *from;
                    162: char   *to;
                    163: int    bytes;
                    164: {
                    165:        while (bytes-- > 0)
                    166:                *to++ = *from++;
                    167: }

unix.superglobalmegacorp.com

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