home *** CD-ROM | disk | FTP | other *** search
/ PC World Plus! (NZ) 2001 June / HDC50.iso / Runimage / Delphi50 / Source / Rtl / Win / NB30.PAS < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  10KB  |  270 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Runtime Library                  }
  5. {       NetBIOS 3.0 interface unit                      }
  6. {                                                       }
  7. {       Copyright (C) 1999 Inprise Corporation          }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit NB30;
  12.  
  13. { This unit contains the definitions
  14.   for portable NetBIOS 3.0 support. }
  15.  
  16. interface
  17.  
  18. uses Windows;
  19.  
  20. { Data structure templates }
  21.  
  22. const
  23.   NCBNAMSZ = 16;               // absolute length of a net name
  24.   MAX_LANA = 254;              // lana's in range 0 to MAX_LANA inclusive
  25.  
  26. type
  27.   // Network Control Block
  28.   PNCB = ^TNCB;
  29.  
  30.   TNCBPostProc = procedure(P: PNCB);
  31.  
  32.   TNCB = packed record
  33.     ncb_command: Char;         // command code
  34.     ncb_retcode: Char;         // return code
  35.     ncb_lsn: Char;             // local session number
  36.     ncb_num: Char;             // number of our network name
  37.     ncb_buffer: PChar;         // address of message buffer
  38.     ncb_length: Word;          // size of message buffer
  39.     ncb_callname: array[0..NCBNAMSZ - 1] of char;  // blank-padded name of remote
  40.     ncb_name: array[0..NCBNAMSZ - 1] of char;      // our blank-padded netname
  41.     ncb_rto: Char;             // rcv timeout/retry count
  42.     ncb_sto: Char;             // send timeout/sys timeout
  43.     ncb_post: TNCBPostProc;    // POST routine address
  44.     ncb_lana_num: Char;        // lana (adapter) number
  45.     ncb_cmd_cplt: Char;        // 0xff => commmand pending
  46.     ncb_reserve: array[0..9] of Char;              // reserved, used by BIOS
  47.     ncb_event: THandle;        // HANDLE to Win32 event which
  48.                                // will be set to the signalled
  49.                                // state when an ASYNCH command
  50.                                // completes
  51.   end;
  52.  
  53.   // Structure returned to the NCB command NCBASTAT is ADAPTER_STATUS followed
  54.   // by an array of NAME_BUFFER structures.
  55.   PAdapterStatus = ^TAdapterStatus;
  56.   TAdapterStatus = packed record
  57.     adapter_address: array[0..5] of Char;
  58.     rev_major: Char;
  59.     reserved0: Char;
  60.     adapter_type: Char;
  61.     rev_minor: Char;
  62.     duration: Word;
  63.     frmr_recv: Word;
  64.     frmr_xmit: Word;
  65.     iframe_recv_err: Word;
  66.     xmit_aborts: Word;
  67.     xmit_success: DWORD;
  68.     recv_success: DWORD;
  69.     iframe_xmit_err: Word;
  70.     recv_buff_unavail: Word;
  71.     t1_timeouts: Word;
  72.     ti_timeouts: Word;
  73.     reserved1: DWORD;
  74.     free_ncbs: Word;
  75.     max_cfg_ncbs: Word;
  76.     max_ncbs: Word;
  77.     xmit_buf_unavail: Word;
  78.     max_dgram_size: Word;
  79.     pending_sess: Word;
  80.     max_cfg_sess: Word;
  81.     max_sess: Word;
  82.     max_sess_pkt_size: Word;
  83.     name_count: Word;
  84.   end;
  85.  
  86.   PNameBuffer = ^TNameBuffer;
  87.   TNameBuffer = packed record
  88.     name: array[0..NCBNAMSZ - 1] of Char;
  89.     name_num: Char;
  90.     name_flags: Char;
  91.   end;
  92.  
  93. const
  94.   // values for name_flags bits.
  95.   NAME_FLAGS_MASK = $87;
  96.  
  97.   GROUP_NAME      = $80;
  98.   UNIQUE_NAME     = $00;
  99.  
  100.   REGISTERING     = $00;
  101.   REGISTERED      = $04;
  102.   DEREGISTERED    = $05;
  103.   DUPLICATE       = $06;
  104.   DUPLICATE_DEREG = $07;
  105.  
  106. type
  107.   // Structure returned to the NCB command NCBSSTAT is SESSION_HEADER followed
  108.   // by an array of SESSION_BUFFER structures. If the NCB_NAME starts with an
  109.   // asterisk then an array of these structures is returned containing the
  110.   // status for all names.
  111.   PSessionHeader = ^TSessionHeader;
  112.   TSessionHeader = packed record
  113.     sess_name: Char;
  114.     num_sess: Char;
  115.     rcv_dg_outstanding: Char;
  116.     rcv_any_outstanding: Char;
  117.   end;
  118.  
  119.   PSessionBuffer = ^TSessionBuffer;
  120.   TSessionBuffer = packed record
  121.     lsn: Char;
  122.     state: Char;
  123.     local_name: array[0..NCBNAMSZ - 1] of Char;
  124.     remote_name: array[0..NCBNAMSZ - 1] of Char;
  125.     rcvs_outstanding: Char;
  126.     sends_outstanding: Char;
  127.   end;
  128.  
  129. const
  130.   // Values for state
  131.   LISTEN_OUTSTANDING      = $01;
  132.   CALL_PENDING            = $02;
  133.   SESSION_ESTABLISHED     = $03;
  134.   HANGUP_PENDING          = $04;
  135.   HANGUP_COMPLETE         = $05;
  136.   SESSION_ABORTED         = $06;
  137.  
  138. type
  139.   // Structure returned to the NCB command NCBENUM.
  140.   // On a system containing lana's 0, 2 and 3, a structure with
  141.   // length =3, lana[0]=0, lana[1]=2 and lana[2]=3 will be returned.
  142.   PLanaEnum = ^TLanaEnum;
  143.   TLanaEnum = packed record
  144.     length: Char;         //  Number of valid entries in lana[]
  145.     lana: array[0..MAX_LANA] of Char;
  146.   end;
  147.  
  148.   // Structure returned to the NCB command NCBFINDNAME is FIND_NAME_HEADER followed
  149.   // by an array of FIND_NAME_BUFFER structures.
  150.   PFindNameHeader = ^TFindNameHeader;
  151.   TFindNameHeader = packed record
  152.     node_count: Word;
  153.     reserved: Char;
  154.     unique_group: Char;
  155.   end;
  156.  
  157.   PFindNameBuffer = ^TFindNameBuffer;
  158.   TFindNameBuffer = packed record
  159.     length: Char;
  160.     access_control: Char;
  161.     frame_control: Char;
  162.     destination_addr: array[0..5] of Char;
  163.     source_addr: array[0..5] of Char;
  164.     routing_info: array[0..17] of Char;
  165.   end;
  166.  
  167.   // Structure provided with NCBACTION. The purpose of NCBACTION is to provide
  168.   // transport specific extensions to netbios.
  169.   PActionHeader = ^TActionHeader;
  170.   TActionHeader = packed record
  171.     transport_id: Longint;
  172.     action_code: Word;
  173.     reserved: Word;
  174.   end;
  175.  
  176. const
  177.   // Values for transport_id
  178.   ALL_TRANSPORTS  = 'M'#0#0#0;
  179.   MS_NBF          = 'MNBF';
  180.  
  181.  
  182. { Special values and constants }
  183.  
  184. const
  185.   // NCB Command codes
  186.   NCBCALL         = $10;            // NCB CALL
  187.   NCBLISTEN       = $11;            // NCB LISTEN
  188.   NCBHANGUP       = $12;            // NCB HANG UP
  189.   NCBSEND         = $14;            // NCB SEND
  190.   NCBRECV         = $15;            // NCB RECEIVE
  191.   NCBRECVANY      = $16;            // NCB RECEIVE ANY
  192.   NCBCHAINSEND    = $17;            // NCB CHAIN SEND
  193.   NCBDGSEND       = $20;            // NCB SEND DATAGRAM
  194.   NCBDGRECV       = $21;            // NCB RECEIVE DATAGRAM
  195.   NCBDGSENDBC     = $22;            // NCB SEND BROADCAST DATAGRAM
  196.   NCBDGRECVBC     = $23;            // NCB RECEIVE BROADCAST DATAGRAM
  197.   NCBADDNAME      = $30;            // NCB ADD NAME
  198.   NCBDELNAME      = $31;            // NCB DELETE NAME
  199.   NCBRESET        = $32;            // NCB RESET
  200.   NCBASTAT        = $33;            // NCB ADAPTER STATUS
  201.   NCBSSTAT        = $34;            // NCB SESSION STATUS
  202.   NCBCANCEL       = $35;            // NCB CANCEL
  203.   NCBADDGRNAME    = $36;            // NCB ADD GROUP NAME
  204.   NCBENUM         = $37;            // NCB ENUMERATE LANA NUMBERS
  205.   NCBUNLINK       = $70;            // NCB UNLINK
  206.   NCBSENDNA       = $71;            // NCB SEND NO ACK
  207.   NCBCHAINSENDNA  = $72;            // NCB CHAIN SEND NO ACK
  208.   NCBLANSTALERT   = $73;            // NCB LAN STATUS ALERT
  209.   NCBACTION       = $77;            // NCB ACTION
  210.   NCBFINDNAME     = $78;            // NCB FIND NAME
  211.   NCBTRACE        = $79;            // NCB TRACE
  212.  
  213.   ASYNCH          = $80;            // high bit set = asynchronous
  214.  
  215.   // NCB Return codes
  216.   NRC_GOODRET     = $00;    // good return
  217.                             // also returned when ASYNCH request accepted
  218.   NRC_BUFLEN      = $01;    // illegal buffer length
  219.   NRC_ILLCMD      = $03;    // illegal command
  220.   NRC_CMDTMO      = $05;    // command timed out
  221.   NRC_INCOMP      = $06;    // message incomplete, issue another command
  222.   NRC_BADDR       = $07;    // illegal buffer address
  223.   NRC_SNUMOUT     = $08;    // session number out of range
  224.   NRC_NORES       = $09;    // no resource available
  225.   NRC_SCLOSED     = $0a;    // session closed
  226.   NRC_CMDCAN      = $0b;    // command cancelled
  227.   NRC_DUPNAME     = $0d;    // duplicate name
  228.   NRC_NAMTFUL     = $0e;    // name table full
  229.   NRC_ACTSES      = $0f;    // no deletions, name has active sessions
  230.   NRC_LOCTFUL     = $11;    // local session table full
  231.   NRC_REMTFUL     = $12;    // remote session table full
  232.   NRC_ILLNN       = $13;    // illegal name number
  233.   NRC_NOCALL      = $14;    // no callname
  234.   NRC_NOWILD      = $15;    // cannot put * in NCB_NAME
  235.   NRC_INUSE       = $16;    // name in use on remote adapter
  236.   NRC_NAMERR      = $17;    // name deleted
  237.   NRC_SABORT      = $18;    // session ended abnormally
  238.   NRC_NAMCONF     = $19;    // name conflict detected
  239.   NRC_IFBUSY      = $21;    // interface busy, IRET before retrying
  240.   NRC_TOOMANY     = $22;    // too many commands outstanding, retry later
  241.   NRC_BRIDGE      = $23;    // NCB_lana_num field invalid
  242.   NRC_CANOCCR     = $24;    // command completed while cancel occurring
  243.   NRC_CANCEL      = $26;    // command not valid to cancel
  244.   NRC_DUPENV      = $30;    // name defined by anther local process
  245.   NRC_ENVNOTDEF   = $34;    // environment undefined. RESET required
  246.   NRC_OSRESNOTAV  = $35;    // required OS resources exhausted
  247.   NRC_MAXAPPS     = $36;    // max number of applications exceeded
  248.   NRC_NOSAPS      = $37;    // no saps available for netbios
  249.   NRC_NORESOURCES = $38;    // requested resources are not available
  250.   NRC_INVADDRESS  = $39;    // invalid ncb address or length > segment
  251.   NRC_INVDDID     = $3B;    // invalid NCB DDID
  252.   NRC_LOCKFAIL    = $3C;    // lock of user area failed
  253.   NRC_OPENERR     = $3f;    // NETBIOS not loaded
  254.   NRC_SYSTEM      = $40;    // system error
  255.  
  256.   NRC_PENDING     = $ff;    // asynchronous command is not yet finished
  257.  
  258. { main user entry point for NetBIOS 3.0
  259.    Usage: Result = Netbios( pncb ); }
  260.  
  261.  
  262. function Netbios(P: PNCB): Char; stdcall;
  263.  
  264. implementation
  265.  
  266. function Netbios; external 'netapi32.dll' name 'Netbios';
  267.  
  268. end.
  269.  
  270.