PL/I for OpenVMS and Tru64

Examples ...   


Example-PLI How To get the MAC, machine address, of a network device using a call to QIOW

Copyright (c) Kednos Corporation 2007. All rights reserved
LAYERED PRODUCT:  Alpha PLI, V4.5          OP/SYS: VMS, V8.3
                  VAX   PLI, V3.8          OP/SYS  VMS, V7.3

SOURCE:     Kednos Customer Support Center


OVERVIEW:

This program demonstrates how to find installed network devices, how to set up the 
QIOW call and how to find the MAC address in the data returned from QIO.


*** CAUTION ***

This sample program has been tested using Alpha PLI V4.5 on OpenVMS V8.3 and on
VAX PL/I V3.8 on OpenVMS 7.3.  If compiling on VAX generates the following  diagnostic

%PLIG-F-LIBLOOKUP, "$EFNDEF" was not found in any of the specified libraries.

Then insert the following module,

$ type $EFNDEF.TXT
/*** MODULE $EFNDEF ***/
%replace EFN$C_ENF by 128;              /* Event No Flag (no stored state)  */
%replace EFN$C_CTX by 129;              /* Wait for context                 */

as follows

$ lib/insert SYS$COMMON:[SYSLIB]PLI$STARLET.TLB $EFNDEF.TXT

However, we cannot guarantee its effectiveness because of the possibility of error
in transmitting or implementing it.  It is meant to be used as a template
for writing your own program and it may require modification for use on your
system.

Sample output
$ pli getmac
$ link getmac
$ run getmac

EIA0: 0002A5ADF78A
EIB0: 0002A5ADF78B


PROGRAM NOTES:

/*                           COPYRIGHT (C) 2007 BY
**                     KEDNOS CORPORATION, PEBBLE BEACH.
**                           ALL RIGHTS RESERVED.
**
**  THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
**  ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE INCLUSION
**  OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY OTHER COPIES
**  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
**  PERSON.  NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.
**
**  THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
**  SHOULD NOT BE CONSTRUED AS A COMMITMENT BY KEDNOS CORPORATION.
**
**  KEDNOS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS
**  SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY KEDNOS.
**
**  NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE
**  ON EQUIPMENT THAT IS NOT SUPPLIED BY KEDNOS CORPORATION.
**
**  SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY KEDNOS SOFTWARE
**  PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE
**  CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED.
*/
GetMACmain: proc options(main);
dcl output char(12);
%replace NET_TYPES      by   23;

dcl net_type(NET_TYPES) char(5) static init(
/* Ethernet */ 'EWA0:', 'EIA0:', 'XEA0:', 'XQA0:', 
               'ESA0:', 'ETA0:', 'EXA0:', 'EFA0:', 
               'EZA0:', 'ECA0:', 'ERA0:', 'EBA0:', 'EGA0:',
/* FDDI */
               'FCA0:', 'FXA0:', 'FAA0:', 'FWA0:', 
               'FRA0:', 'FQA0:', 'CLA0:', 'ELA0:',
/* Token Ring */
               'ICA0:', 'IRA0:');
dcl X(2) char static init('A','B');
dcl dev_name char(5);
dcl (i,j) fixed bin(31);

do i = 1 to NET_TYPES;
   do j = 1 to 2;
      output = getmac(i,j);
      if output ^= '' then do;
	dev_name = net_type(i);
	substr(dev_name,3,1) = X(j);
	put skip edit(dev_name,output) (A(5),X,A(12));
	end;
      end;
   end;

GetMAC: proc(net_dev_index,d) returns(char(12));
%include SYS$QIO;
%include $efndef;
%include $iodef;
%include SYS$assign;
%include $STSDEF;
%include $SSDEF;

%dcl (SENSE_BUF_LEN,  HWA_PARAM_TYPE)  fixed;
%SENSE_BUF_LEN  = 1024;
%HWA_PARAM_TYPE = 1160;

dcl ascii(0:15) char(1) init(	'0','1','2','3','4','5','6','7',
				'8','9','A','B','C','D','E','F');
dcl mac char(12) init('');
dcl device char(5);
dcl (iosb(4),i,j) fixed bin(15);

dcl result char(20) varying;

dcl 1 RtnData static union,
	2 BytOvl(SENSE_BUF_LEN) fixed bin(7),
	2 sense_buf char(SENSE_BUF_LEN),
	2 HexOvl(SENSE_BUF_LEN*2) bit(4);

dcl 1 sense_buf_dsc static,
      2 length fixed bin(31),
      2 buf    pointer;

dcl attr_ptr                pointer;
dcl 1 attr_dsc              structure based(attr_ptr),
      2 id                      bit(12),
	2 is_string		bit(1),
	2 spare			bit(2),
	2 mbz			bit(1),
	2 param			union,
            3 count             fixed bin(15),
	    3 value             fixed bin(31);

dcl (net_dev_index,d)        fixed bin(31);
dcl netchan              fixed bin(15);

sts$value = 0;
sts$success = '0'b;

 device = net_type(net_dev_index);
   mac = '';
   substr(device,3,1) = X(d);
   sts$value = SYS$ASSIGN(device,netchan,,);
   result = 'HWA('||device||') = ';

   if sts$value = 1  then do;
       if ^sts$success then do;
        	put skip list('Problems with assign');
	        signal vaxcondition(sts$value);
        	end;
       else do;
		sts$value = 0;
		sts$success = '0'b;
		sense_buf_dsc.length = SENSE_BUF_LEN;
		sense_buf_dsc.buf = addr(sense_buf);

        	sts$value = sys$QIOW( EFN$C_ENF,
                	              netchan,
                        	      IO$_SENSEMODE | IO$M_CTRL,
	                              IOSB,,,,
	                              reference(sense_buf_dsc),,,,);

		if sts$success then sts$value = iosb(1);
		end;


	if ^sts$success then do;
		put skip list('Problems with QIOW');
		signal vaxcondition(sts$value);
		end;
	else do i = 1 to SENSE_BUF_LEN;
		attr_ptr = addr(BytOvl(i));
		if binary(reverse(id),15) = HWA_PARAM_TYPE then do;
			do j=4 to 9;
			   substr(mac,2*j-7,1) = 	ascii(BINARY(reverse(HexOvl(2*i+2*j  )),15));
			   substr(mac,2*j-6,1) = 	ascii(BINARY(reverse(HexOvl(2*i+2*j-1)),15));
			   end;
			   leave;
			end;

		end;
	end;
   return(mac);
   end GetMAC;
end getMACmain;




Last updated 30-OCT-2007
   and Web-enabled with