home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 62 / rmtinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  3.0 KB  |  123 lines

  1. #ifndef lint
  2. static char rcsid[] =
  3.     "@(#) $Header: rmtinfo.c,v 1.3 87/04/09 20:20:51 leres Exp $ (LBL)";
  4. #endif
  5. /*
  6.  *    The privilege NETMBX is required for use.
  7.  *
  8.  *    Warning: This routine is chalked full of undocumented MAGIC.
  9.  */
  10. #include <ctype.h>
  11. #include <strings.h>
  12.  
  13. #include "vms/nfbdef.h"
  14. #include "vms/ssdef.h"
  15. #include "vms/iodef.h"
  16.  
  17. /*
  18.  * Use nfb block to help define what we need.
  19.  */
  20. static struct XNFB {
  21.     struct NFB x;
  22. #define xnfb$b_fct x.nfb$b_fct
  23. #define xnfb$b_flags x.nfb$b_flags
  24. #define xnfb$b_database x.nfb$b_database
  25. #define xnfb$b_oper x.nfb$b_oper
  26. #define xnfb$l_srch_key x.nfb$l_srch_key
  27. #define xnfb$l_srch2_key x.nfb$l_srch2_key
  28. #define xnfb$l_x_lli_pna x.nfb$l_fldid
  29.     unsigned long xnfb$l_x_lli_pnn;
  30.     unsigned long xnfb$l_x_endoflist;
  31. } nfb;
  32.  
  33. static struct acpbuf {
  34.     long a_node;            /* decnet node number */
  35.     short a_length;            /* length of the decnet host name */
  36.     char a_name[6];            /* decnet host name */
  37. } abuf;
  38.  
  39. static struct dsc {
  40.     long d_length;
  41.     char *d_address;
  42. };
  43.  
  44. rmtinfo(link, node, name)
  45.     long link;
  46.     long *node;
  47.     char *name;
  48. {
  49.     register int i, status;
  50.     int sys$assign(), sys$qiow();
  51.     short iosb[4];
  52.     struct dsc netdsc, nfbdsc, keydsc, bufdsc;
  53.     long key[2];
  54.     static int chan = 0;
  55.  
  56.     /*
  57.      *    If necessary, assign a channel to NET
  58.      */
  59.     if (!chan) {
  60.         netdsc.d_address = "NET:";
  61.         netdsc.d_length = strlen(netdsc.d_address);
  62.         if ((status = sys$assign(&netdsc, &chan, 0, 0)) != SS$_NORMAL)
  63.             return(status);
  64.     }
  65.     /*
  66.      *    Set up the nfb request buffer
  67.      */
  68.     bzero(&nfb, sizeof(nfb));
  69.     nfb.xnfb$b_fct = NFB$C_FC_SHOW;
  70.     nfb.xnfb$b_flags = NFB$M_NOCTX;        /* don't update the database */
  71.     nfb.xnfb$b_database = NFB$C_DB_LLI;    /* logical link info database */
  72.     nfb.xnfb$b_oper = NFB$C_OP_EQL;        /* match the key exactly */
  73.     nfb.xnfb$l_srch_key = NFB$C_LLI_LLN;    /* key is logical link number */
  74.     nfb.xnfb$l_srch2_key = NFB$C_WILDCARD;    /* search the whole database */
  75.     nfb.xnfb$l_x_lli_pna = NFB$C_LLI_PNA;    /* partner's node address */
  76.     nfb.xnfb$l_x_lli_pnn = NFB$C_LLI_PNN;    /* partner's node name */
  77.     nfb.xnfb$l_x_endoflist = NFB$C_ENDOFLIST;
  78.     /*
  79.      *    Construct the nfb descriptor
  80.      */
  81.     nfbdsc.d_address = (char *) &nfb;
  82.     nfbdsc.d_length = sizeof(nfb);
  83.     /*
  84.      *    Construct the key descriptor
  85.      */
  86.     keydsc.d_address = (char *) &key[0];
  87.     keydsc.d_length = sizeof(key);
  88.     /*
  89.      *    Construct the logical link key descriptor
  90.      */
  91.     key[0] = 0;
  92.     key[1] = link;
  93.     /*
  94.      *    Construct the return buffer descriptor
  95.      */
  96.     bufdsc.d_address = (char *) &abuf;
  97.     bufdsc.d_length = sizeof(abuf);
  98.     /*
  99.      *    Ask NET about this port
  100.      */
  101.     status = sys$qiow(0, chan, IO$_ACPCONTROL, iosb, 0, 0,
  102.         &nfbdsc, &keydsc, 0, &bufdsc, 0, 0);
  103.     if (status != SS$_NORMAL)
  104.         return(status);
  105.     status = iosb[0];
  106.     if (status != SS$_NORMAL)
  107.         return(status);
  108.     /*
  109.      *    Return the node number
  110.      */
  111.     *node = abuf.a_node;
  112.     /*
  113.      *    Return the node name
  114.      */
  115.     if ((i = abuf.a_length) > sizeof(abuf.a_name))
  116.         i = sizeof(abuf.a_name);
  117.     name[i] = '\0';
  118.     for (--i; i >= 0; i--)
  119.         if (isupper(name[i] = abuf.a_name[i]))
  120.             name[i] = tolower(name[i]);
  121.     return(SS$_NORMAL);
  122. }
  123.