home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / n / netbioc.zip / Q8.C < prev    next >
C/C++ Source or Header  |  1992-03-01  |  5KB  |  222 lines

  1. // This is a sample for Post Routine code for DOS ncb
  2.  
  3. #define FALSE 0
  4. #define TRUE  1
  5.  
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include <string.h>
  9.  
  10. #include <netcons.h>
  11. #include <ncb.h>
  12. #include <netbios.h>
  13. #include "astat.h"
  14.  
  15. void NetBiosRequest(NCB far *);
  16.  
  17.  
  18. struct sstat {
  19.     unsigned char  ss_namenum;
  20.     unsigned char  ss_numsess;
  21.     unsigned char  ss_numrdgm;
  22.     unsigned char  ss_numrany;
  23.     struct ss_sess ss_struct[1];
  24.     };
  25.  
  26. //post Routine
  27.  
  28. extern void  cdecl interrupt far  PostRoutine(
  29.                 unsigned int es, unsigned int ds,
  30.                 unsigned int di, unsigned int si,
  31.                 unsigned int bp, unsigned int sp,
  32.                 unsigned int bx, unsigned int dx,
  33.                 unsigned int cx, unsigned int ax,
  34.                 unsigned int ip, unsigned int cs,
  35.                 unsigned int flags);
  36.  
  37.  
  38.  
  39. // Boolean signal between main and PostRoutine
  40.  
  41. int  PostRoutineDriven;
  42.  
  43. void main()
  44. {
  45.     NCB tstNCB;
  46.     ASTAT AStatBuf;
  47.     register int i,j;
  48.     unsigned short *usPtr;
  49.  
  50.     // assign a pointer to PostRoutine
  51.     void  (far *PostRoutinePtr)() = (void (far *)()) PostRoutine;
  52.  
  53.             // ADD A NAME
  54.  
  55.     tstNCB.ncb_command = NCBADDNAME | ASYNCH;
  56.     strcpy(tstNCB.ncb_name,"aa");
  57.     tstNCB.ncb_lana_num = 0;
  58.  
  59.     usPtr = (unsigned short *) &tstNCB.ncb_post;
  60.     *usPtr  = FP_OFF( PostRoutinePtr);
  61.     usPtr++;
  62.     *usPtr  = FP_SEG( PostRoutinePtr);
  63.  
  64.  
  65.     printf("submitting NCBADDNAME   ");
  66.     NetBiosRequest((NCB far *)&tstNCB);
  67.     do {
  68.  
  69.         // We will come out once Post Routine is done
  70.  
  71.     }while (PostRoutineDriven == FALSE );
  72.     PostRoutineDriven = FALSE;
  73.  
  74.     printf("cmd cplt code: %d\n",tstNCB.ncb_cmd_cplt);
  75.     printf("ret code: %d\n",tstNCB.ncb_retcode);
  76.  
  77.         // NOW DELETE NAME
  78.  
  79.     tstNCB.ncb_command = NCBDELNAME | ASYNCH;
  80.     strcpy(tstNCB.ncb_name,"aa");
  81.     tstNCB.ncb_lana_num = 0;
  82.  
  83.     usPtr = (unsigned short *) &tstNCB.ncb_post;
  84.     *usPtr  = FP_OFF( PostRoutinePtr);
  85.     usPtr++;
  86.     *usPtr  = FP_SEG( PostRoutinePtr);
  87.  
  88.  
  89.  
  90.     printf("submitting NCBDELNAME   ");
  91.     NetBiosRequest((NCB far *)&tstNCB);
  92.     do {
  93.  
  94.         // We will come out once Post Routine is done
  95.  
  96.     }while (PostRoutineDriven == FALSE );
  97.     PostRoutineDriven = FALSE;
  98.  
  99.     printf("cmd cplt code: %d\n",tstNCB.ncb_cmd_cplt);
  100.     printf("ret code: %d\n",tstNCB.ncb_retcode);
  101.  
  102.  
  103.  
  104.         // ADD A GROUP NAME
  105.  
  106.     tstNCB.ncb_command = NCBADDGRNAME | ASYNCH;
  107.     strcpy(tstNCB.ncb_name,"aa");
  108.     tstNCB.ncb_lana_num = 0;
  109.  
  110.     usPtr = (unsigned short *) &tstNCB.ncb_post;
  111.     *usPtr  = FP_OFF( PostRoutinePtr);
  112.     usPtr++;
  113.     *usPtr  = FP_SEG( PostRoutinePtr);
  114.  
  115.  
  116.  
  117.     printf("submitting NCBADDGRNAME   ");
  118.     NetBiosRequest((NCB far *)&tstNCB);
  119.     do {
  120.  
  121.         // We will come out once Post Routine is done
  122.  
  123.     }while (PostRoutineDriven == FALSE );
  124.     PostRoutineDriven = FALSE;
  125.  
  126.     printf("cmd cplt code: %d\n",tstNCB.ncb_cmd_cplt);
  127.     printf("ret code: %d\n",tstNCB.ncb_retcode);
  128.  
  129.  
  130.         // NOW DELETE GROUP NAME
  131.  
  132.     tstNCB.ncb_command = NCBDELNAME | ASYNCH;
  133.     strcpy(tstNCB.ncb_name,"aa");
  134.     tstNCB.ncb_lana_num = 0;
  135.  
  136.     usPtr = (unsigned short *) &tstNCB.ncb_post;
  137.     *usPtr  = FP_OFF( PostRoutinePtr);
  138.     usPtr++;
  139.     *usPtr  = FP_SEG( PostRoutinePtr);
  140.  
  141.  
  142.  
  143.     printf("submitting NCBDELNAME   ");
  144.     NetBiosRequest((NCB far *)&tstNCB);
  145.     do {
  146.  
  147.         // We will come out once Post Routine is done
  148.  
  149.     }while (PostRoutineDriven == FALSE );
  150.     PostRoutineDriven = FALSE;
  151.  
  152.     printf("cmd cplt code: %d\n",tstNCB.ncb_cmd_cplt);
  153.     printf("ret code: %d\n",tstNCB.ncb_retcode);
  154.  
  155.  
  156.         // ADAPTOR STATUS
  157.  
  158.     tstNCB.ncb_command = NCBASTAT;
  159.     tstNCB.ncb_buffer = (char far *)&AStatBuf;
  160.     tstNCB.ncb_length = sizeof(ASTAT);
  161.     strcpy(tstNCB.ncb_callname,"*");
  162.     tstNCB.ncb_lana_num = 0;
  163.  
  164.     printf("submitting NCBASTAT     ");
  165.     NetBiosRequest((NCB far *)&tstNCB);
  166.     printf("ret code: %d\n",tstNCB.ncb_retcode);
  167.  
  168.     printf("-- names in adapter --\n");
  169.     for(i=0;i<AStatBuf.as_names;i++)  {
  170.     for(j=0;j<NCBNAMSZ;j++)
  171.         if (AStatBuf.as_struct[i].as_name[j] != 0)
  172.         printf("%c",AStatBuf.as_struct[i].as_name[j]);
  173.         else  {
  174.         for(;j<NCBNAMSZ;j++) printf(" ");
  175.         break;
  176.         }
  177.     printf("   %3d",AStatBuf.as_struct[i].as_number);
  178.     printf("   %4x\n",AStatBuf.as_struct[i].as_status);
  179.     }
  180.     printf("----------------------\n");
  181.  
  182.  
  183.     printf("\n All is well!!!\n");
  184.  
  185.  
  186. }
  187.  
  188. void NetBiosRequest(NcbPtr)
  189. NCB *NcbPtr;
  190. {
  191.     union REGS InRegs,OutRegs;
  192.     struct SREGS SegRegs;
  193.  
  194.     InRegs.x.bx = FP_OFF(NcbPtr);
  195.     SegRegs.es    = FP_SEG(NcbPtr);
  196.  
  197.     int86x(0x5C,&InRegs,&OutRegs,&SegRegs);
  198. }
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205. void  cdecl interrupt far  PostRoutine(
  206.                  es,      ds,
  207.                  di,      si,
  208.                  bp,      sp,
  209.                  bx,      dx,
  210.                  cx,      ax,
  211.                  ip,      cs,
  212.                  flags)
  213.   unsigned es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags;
  214.   {
  215.  
  216.     PostRoutineDriven = TRUE;
  217.    /* NO DOS CALLS ALLOWED HERE SINCE DOS IS NON-REENTRANT*/
  218.  
  219.     // ES:BX point to completed ncb
  220.  
  221. }
  222.