home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / NETB32.ZIP / TEST.C < prev   
Text File  |  1993-04-12  |  4KB  |  119 lines

  1. #define INCL_DOS
  2. #include <os2.h>
  3. #include <netbview.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #define Local "TEST1"
  9. #define Remote "TEST2"
  10. #define Anyone "*"
  11. #define SendMsg "Message sent from Client to Server"
  12. #define NETBIOS 0
  13. #define NETBEUI 1
  14. BOOL API = NETBIOS;
  15. #define Adapter 0
  16. APIRET16 APIENTRY16 Dos16SemWait(PULONG,ULONG);
  17.  
  18. PNCB WorkNcb;
  19. main(int argc, char *argv[], char *envp)
  20. {
  21.   BYTE Buffer[100];
  22.   USHORT rc,lsn;
  23.   PBYTE Name,CallName;
  24.  
  25.   if(!netbios_avail(API))
  26.     {
  27.     WorkNcb=(PNCB)malloc(sizeof(NCBSIZE));
  28.     if(!(rc=NCBReset(API,WorkNcb,Adapter,2,2,2)))
  29.       {
  30.       if(argc==1)
  31.         {
  32.         Name=Local;
  33.         CallName=Remote;
  34.         } /* end if */
  35.       else
  36.         {
  37.         Name=Remote;
  38.         CallName=Local;
  39.         } /* end else */
  40.       if(!(rc=NCBAddName(API,WorkNcb,Adapter,Name)) || rc==13)
  41.         {
  42.         printf("Name added\n");
  43.         if(argc==1)             // process as client
  44.           {
  45.           if(!(rc=NCBCall(API,WorkNcb,Adapter,Name,CallName,0,0,TRUE)))
  46.             {
  47.             lsn=WorkNcb->basic_ncb.bncb.ncb_lsn;
  48.             if(!(rc=NCBSend(API,WorkNcb,Adapter,lsn,SendMsg,sizeof(SendMsg)-1, TRUE)))
  49.               {
  50.               printf("Send completed\n");
  51.               } /* end if */
  52.             else
  53.               {
  54.               printf("Send failed rc=%d\n",rc);
  55.               } /* end else */
  56.             NCBHangup(API,WorkNcb,Adapter,lsn);
  57.             } /* end if */
  58.           else
  59.             {
  60.             printf("Call failed rc=%d\n",rc);
  61.             } /* end else */
  62.           } /* end if */
  63.         else                    // process as server
  64.           {
  65.           if(!(rc=NCBListen(API,WorkNcb,Adapter,Name,Anyone,0,0,TRUE)))
  66.             {
  67.             lsn=WorkNcb->basic_ncb.bncb.ncb_lsn;
  68.             printf("Listen ready\n");
  69.             if(API==NETBIOS)
  70.               {
  71.               if(!(rc=NCBReceive(API,WorkNcb,Adapter,lsn,Buffer,sizeof(Buffer),FALSE)))
  72.                 {
  73.                 rc=Dos16SemWait(&WorkNcb->basic_ncb.ncb_semiphore,SEM_INDEFINITE_WAIT);
  74.                 printf("Data received='%.*s' rc=%d\n",(int)WorkNcb->basic_ncb.bncb.ncb_length,Buffer,rc);
  75.                 } /* end if */
  76.               else
  77.                 {
  78.                 printf("Receive failed rc=%d\n");
  79.                 } /* end else */
  80.               } /* end if */
  81.             else
  82.               {
  83.               if(!(rc=NCBReceive(API,WorkNcb,Adapter,lsn,Buffer,sizeof(Buffer),TRUE)))
  84.                 {
  85.                 printf("Data received='%.*s' rc=%d\n",(int)WorkNcb->basic_ncb.bncb.ncb_length,Buffer,rc);
  86.                 } /* end if */
  87.               else
  88.                 {
  89.                 printf("Receive failed rc=%d\n");
  90.                 } /* end else */
  91.               } /* end else */
  92.             NCBHangup(API,WorkNcb,Adapter,lsn);
  93.             } /* end if */
  94.           else
  95.             {
  96.             printf("Listen failed rc=%d\n");
  97.             } /* end else */
  98.           } /* end else */
  99.         NCBDeleteName(API,WorkNcb,Adapter,Name);
  100.         } /* end if */
  101.       else
  102.         {
  103.         printf("AddName Failed rc=%d\n",rc);
  104.         } /* end else */
  105.       NCBClose(API,WorkNcb,Adapter);
  106.       } /* end if */
  107.     else
  108.       {
  109.       printf("Reset failed rc=%d\n",rc);
  110.       } /* end else */
  111.  
  112.     } /* end if */
  113.   else
  114.     {
  115.     printf("ACSNETB.DLL could not be found, Netbios not installed\n");
  116.     } /* end else */
  117.   return rc;
  118. }
  119.