/************************************************************* * LAN Sample Test Program * * This LAN test program sends a MOP loopback message to the Loopback Assistant * Multicast address and waits for a response. The program uses the LAN device * EWA0. To use a different device, etchnge the device name in the program or * define the desired lan device as EWA0. * * To build on VAX: To build on Alpha: * $ CC LAN802E $ CC LAN802E + SYS$LIBRARY:SYS$LIB_C.TLB/LIB * $ LINK LAN802E,SYS$INPUT:/OPT $ LINK LAN802E * SYS$SHARE:VAXCRTL.EXE/SHARE *************************************************************/ #include /* Character type classification macros/routines */ #include /* For VMS descriptor manipulation */ #include /* I/O function code definitions */ #include /* System service return status code definitions */ #include /* System library routine prototypes */ #include /* ANSI C Standard Input/Output */ #include /* General utilities */ #include /* String handling */ #include /* VMS status code definitions */ #include #include #include #include #include #include #define __NEW_STARLET 1 #include "arpdef.h" #pragma nomember_alignment unsigned char buffer[512]; /* Sensemode buffer */ struct { short pcli_fmt; /* Format - 802E */ int fmt_value; short pcli_pty; /* Protocol ID - 08-00-2B-90-00 */ int pty_value; } plist = {NMA$C_PCLI_FMT, NMA$C_LINFM_ETH, NMA$C_PCLI_PTY,0x8006}; struct { int len; void * ptr; } bufdsc = {sizeof(buffer),&buffer}, parmdsc = {sizeof(plist),&plist}; struct { /* P5 Receive header buffer */ unsigned char da[6], sa[6], misc[20]; } rcv_param, /* Receive header structure */ xmt_param={0xCF,0,0,0,0,0}; /* Transmit header structure */ /* Loopback Assistant Multicast Address */ $DESCRIPTOR(nicdsc ,"EWA0:"); $DESCRIPTOR(ipdsc ,"IPA0:"); iosb _iosb; /* IOSB structure */ char rcvbuffer[512]; /* Receive buffer */ char xmtbuffer[20]={ /* Transmit buffer */ 0,0, /* Skip count */ 2,0, /* Forward request */ 0,0,0,0,0,0, /* Forward address */ 1,0, /* Reply request */ 0,0}; /* * MAIN */ struct routetab { struct in_addr dst, gate; unsigned short flags, ref; unsigned use, lineid; } *route = (struct routetab* ) &buffer; struct arptab { union { struct in_addr dst; unsigned _dst; } u; unsigned char pha[6]; unsigned short flags;} *arp = (struct arptab*) &buffer; ARP$_PDU pdu; main(int argc, char *argv[]) { int status,etchn,ipchn,i,j; /* ** Start a channel to the NIC */ if ( !(1 & (status = sys$assign(&nicdsc,&etchn,0,0))) ) lib$signal((1 & status)?_iosb.iosb$w_status:status);; if ( !(1 & (status = sys$qiow(EFN$C_ENF,etchn,IO$_SETMODE|IO$M_CTRL|IO$M_STARTUP, &_iosb,0,0, 0,&parmdsc,0,0,0,0))) || !(1 & _iosb.iosb$w_status) ) lib$signal((1 & status)?_iosb.iosb$w_status:status); /* * Issue the SENSEMODE QIO to get our physical address for the loopback message. */ if ( !(1 & (status = sys$qiow(EFN$C_ENF,etchn,IO$_SENSEMODE|IO$M_CTRL, &_iosb,0,0,0,&bufdsc,0,0,0,0))) || !(1 & _iosb.iosb$w_status) ) lib$signal((1 & status)?_iosb.iosb$w_status:status); /* ** Locate the PHA parameter in the SENSEMODE buffer and copy it into the ** ARP-request transmit message. The PHA parameter is a string parameter. */ for (j = 0;j < sizeof(buffer); ) { i = (buffer[j] + (buffer[j+1]<<8) ); if ( i & 0x1000 ) { if ( (i & 0xFFF) == NMA$C_PCLI_PHA) { memcpy(&pdu.arp$b_src,&buffer[j+4],6); break; } j += (buffer[j+2] + (buffer[j+3]<<8) ) + 4; } else j += 6; /* Skip over longword parameter */ } /* ** Now we need to run over ARP table to get IP-GateWay/MAC pair */ if ( !(1 & (status = sys$assign(&ipdsc,&ipchn,0,0))) ) lib$signal((1 & status)?_iosb.iosb$w_status:status);; if ( !(1 & (status = sys$qiow(EFN$C_ENF,ipchn,IO$_SETMODE|IO$M_CTRL|IO$M_STARTUP, &_iosb,0,0,0,0,0,0,0,0))) || !(1 & _iosb.iosb$w_status) ) lib$signal((1 & status)?_iosb.iosb$w_status:status); /* ** Reading the Routing Table */ if ( !(1 & (status = sys$qiow(EFN$C_ENF,ipchn,IO$_SENSEMODE|IO$M_CTRL,&_iosb,0,0, 0,&bufdsc,2,0,0,0))) || !(1 & _iosb.iosb$w_status) ) lib$signal((1 & status)?_iosb.iosb$w_status:status); printf(" gate line\n"); for(; route->lineid; route++) printf("%15s %08.8X\n",inet_ntoa(route->dst),route->lineid); /* ** Reading the ARP Table */ if ( !(1 & (status = sys$qiow(EFN$C_ENF,ipchn,IO$_SENSEMODE|IO$M_CTRL,&_iosb,0,0, 0,&bufdsc,3,0x00000A02,0,0))) || !(1 & _iosb.iosb$w_status) ) lib$signal((1 & status)?_iosb.iosb$w_status:status); printf("\n dst pha\n"); for(; arp->u._dst; arp++) printf("%15s %02.2X-%02.2X-%02.2X-%02.2X-%02.2X-%02.2X-%02.2X\n", inet_ntoa(arp->u.dst), arp->pha[0],arp->pha[1],arp->pha[2], arp->pha[3],arp->pha[4],arp->pha[5]); /* ** Transmit ARP-Request - Wait & receive ARP-Reply */ if ( (!1 & (status = sys$qiow(EFN$C_ENF,etchn,IO$_WRITEVBLK,&_iosb,0,0,&xmtbuffer, sizeof(xmtbuffer),0,0,&xmt_param,0))) || !(1 & _iosb.iosb$w_status) ) lib$signal((1 & status)?_iosb.iosb$w_status:status); if ( !(1 & (status = sys$qio(0,etchn,IO$_READVBLK|IO$M_NOW,&_iosb,0,0,&rcvbuffer, sizeof(rcvbuffer),0,0,&rcv_param,0))) || !(1 & _iosb.iosb$w_status) ) return (1 & status)?_iosb.iosb$w_status:status; }