home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / MAILMIND.ZOO / NETSEND2.C < prev    next >
Text File  |  1991-04-12  |  2KB  |  85 lines

  1. /* netsend2.c - send a message from an OS/2 machine
  2.  * Division of Cancer Prevention & Control, NCI
  3.  */
  4.  
  5. /* Revision history:
  6.  * 1.02  tam  04/12/91  convert to OS/2, temporarily eliminating prompt mode
  7.  * 1.01  tam  02/07/91  prompt for username & msg
  8.  * 1.00  tam  01/31/91  first release
  9.  */
  10.  
  11. #include <local.h>                      /* standard definitions */
  12. #define     INCL_NETBIOS
  13. #define     INCL_NETERRORS
  14. #include    <lan.h>                     /* LAN Manager header files */
  15.  
  16. /* defines */
  17. #define NETBIOS_NAME_LEN 16
  18. #define NCB_CHAIN_SINGLE 0
  19. #define HELP 1
  20. #define USER_NUM 2                      /* ? */
  21.  
  22. /* status structure */
  23. #define STATUS_NOPARAM 100
  24. #define STATUS_UNKNOWN 0xff
  25. #define STATUS_STRUCT struct status
  26. STATUS_STRUCT
  27.   {
  28.   word   wCode;
  29.   string sText;
  30.   };
  31. STATUS_STRUCT aStatus[] =
  32.   {
  33.   {0, "OK"},
  34.   {9, "no local name"},
  35.   {STATUS_NOPARAM, "too few parameters"},
  36.   {STATUS_UNKNOWN, "?"}
  37.   };
  38.  
  39. /* globals */
  40. NCB     Ncb;
  41.  
  42. /* function prototypes */
  43. short main(short argc, string argv[]);
  44. word NetSend(string sName, string sMsg, word iNbNum);
  45.  
  46. /* main */
  47. short main(short argc, string argv[])
  48. {
  49. short  i;
  50. word   wStatus = 0;
  51. printf("Netsend2 v1.02");
  52. if (argc < 3) wStatus = STATUS_NOPARAM;
  53. else
  54.   wStatus = NetSend(argv[1], argv[2], (argc > 3) ? atoi(argv[3]) : USER_NUM);
  55. for (i = 0; *(aStatus[i].sText) != '?'; i++)
  56.   if (aStatus[i].wCode == wStatus) break;
  57. printf("\nNetsend2 status: %s (%d)\n", aStatus[i].sText, Ncb.ncb_cmd_cplt);
  58. return(i);
  59. } /* main */
  60.  
  61. /* send a Msg to Name from iNbNum */
  62. word NetSend(string sName, string sMsg, word iNbNum)
  63. {
  64. string s;
  65. word   wStatus;
  66. word   wHandle;                         /* Handle to logical network */
  67. wStatus = NetBiosOpen("NET1", 0, NB_REGULAR, &wHandle);
  68. if (wStatus == NERR_Success)
  69.   {
  70.   memset(&Ncb, 0, sizeof(NCB));
  71.   Ncb.ncb_command = NCBDGSEND;
  72.   Ncb.ncb_num = (byte) iNbNum;
  73.   strncpy(Ncb.ncb_callname, sName, NETBIOS_NAME_LEN);
  74.   for (s = Ncb.ncb_callname; s < Ncb.ncb_name - 1; s++)
  75.     *s = ((*s) ? toupper(*s) : ' ');
  76.   Ncb.ncb_buffer = (void far *) sMsg;
  77.   Ncb.ncb_length = strlen(sMsg);
  78.   Ncb.ncb_cmd_cplt = (byte) STATUS_UNKNOWN;
  79.   NetBiosSubmit(wHandle, NCB_CHAIN_SINGLE, &Ncb);
  80.   NetBiosClose(wHandle, 0);
  81.   wStatus = (word) Ncb.ncb_retcode;
  82.   }
  83. return(wStatus);
  84. } /* NetSend */ 
  85.