home *** CD-ROM | disk | FTP | other *** search
- /* netsend.c - send a message
- * Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
- * Division of Cancer Prevention & Control, NCI
- */
-
- /* Revision history:
- * 1.01 ytm 02/07/91 prompt for username & msg
- * 1.00 ytm 01/31/91 first release
- */
-
- /* Program notes:
- * Current versions are specific for TurboC.
- */
-
- #include <local.h> /* standard definitions */
- #include "netbios.h"
-
- /* defines */
- #define HELP 1
- #define USER_NUM 4 /* should be username */
-
- /* status structure */
- #define STATUS_ABORT 100
- #define STATUS_UNKNOWN 0xff
- #define STATUS_STRUCT struct status
- STATUS_STRUCT
- {
- word wCode;
- string sText;
- };
- STATUS_STRUCT aStatus[] =
- {
- {0, "OK"},
- {9, "no local name"},
- {STATUS_ABORT, "aborted"},
- {STATUS_UNKNOWN, "?"}
- };
-
- /* globals */
- NCB Ncb;
-
- /* function prototypes */
- short main(short argc, string argv[]);
- string GetsEsc(string sLine);
- word NetSend(string sName, string sMsg, short iNbNum);
-
- /* main */
- short main(short argc, string argv[])
- {
- boolean bGetInput;
- char caMsg[MAXLINE];
- char caName[NETBIOS_NAME_LEN];
- short i;
- word wStatus = 0;
- printf("Netsend v1.01");
- if (argc < 2)
- {
- bGetInput = TRUE;
- while (bGetInput)
- {
- printf("\nSend to: ");
- switch (*GetsEsc(caName))
- {
- case ESC:
- wStatus = STATUS_ABORT;
- bGetInput = FALSE;
- break;
- case '\0':
- case '?':
- case HELP:
- printf("\nEnter the user initials of the person ");
- printf("to whom you wish to send a message.");
- printf("\nPress <Esc> to abort");
- break;
- default:
- bGetInput = FALSE;
- break;
- }
- }
- }
- else
- {
- strcpy(caName, argv[1]);
- printf("\nSend to: %s", caName);
- }
- if (!wStatus && argc < 3)
- {
- bGetInput = TRUE;
- while (bGetInput)
- {
- printf("\nMessage: ");
- switch (*GetsEsc(caMsg))
- {
- case ESC:
- wStatus = STATUS_ABORT;
- bGetInput = FALSE;
- break;
- case '\0':
- case '?':
- case HELP:
- printf("\nEnter the message you wish to send to %s.", caName);
- printf("\nPress <Esc> to abort");
- break;
- default:
- bGetInput = FALSE;
- break;
- }
- }
- }
- else
- {
- strcpy(caMsg, argv[2]);
- printf("\nMessage: %s", caMsg);
- }
- if (!wStatus)
- wStatus = NetSend(caName, caMsg, (argc > 3) ? atoi(argv[3]) : USER_NUM);
- for (i = 0; *(aStatus[i].sText) != '?'; i++)
- if (aStatus[i].wCode == wStatus) break;
- printf("\nNetsend status: %s (%d)\n", aStatus[i].sText, Ncb.NCB_CMD_CPLT);
- return(i);
- } /* main */
-
- /* get a string from the console allowing escape */
- string GetsEsc(string sLine)
- {
- boolean bGetInput = TRUE;
- short iCol, iRow;
- short c;
- string s = sLine;
- union REGS Reg;
- while (bGetInput)
- {
- GETKEY(c);
- switch (c)
- {
- case BS:
- if (s > sLine)
- {
- Reg.h.ah = 3;
- Reg.h.bh = 0;
- int86(0x10, &Reg, &Reg);
- iCol = --Reg.h.dl;
- iRow = Reg.h.dh;
- Reg.h.ah = 2;
- int86(0x10, &Reg, &Reg);
- putch(' ');
- Reg.h.ah = 2;
- Reg.h.dl = iCol;
- Reg.h.dh = iRow;
- int86(0x10, &Reg, &Reg);
- s--;
- }
- break;
- case CR:
- bGetInput = FALSE;
- break;
- case ESC:
- bGetInput = FALSE;
- s = sLine;
- *s++ = ESC;
- break;
- case F1:
- bGetInput = FALSE;
- s = sLine;
- *s++ = HELP;
- break;
- default:
- if (c >= SPACE && c < DEL)
- {
- putch(c);
- *s++ = c;
- }
- else putch(BELL);
- break;
- }
- }
- *s = '\0';
- return(sLine);
- } /* GetsEsc */
-
- /* send a Msg to Name from iNbNum */
- word NetSend(string sName, string sMsg, short iNbNum)
- {
- string s;
- memset(&Ncb, 0, sizeof(NCB));
- Ncb.NCB_COMMAND = SEND_DATAGRAM_WAIT;
- Ncb.NCB_NUM = iNbNum;
- strncpy(Ncb.NCB_CALLNAME, sName, NETBIOS_NAME_LEN);
- for (s = Ncb.NCB_CALLNAME; s < Ncb.NCB_NAME - 1; s++)
- *s = ((*s) ? toupper(*s) : ' ');
- Ncb.NCB_BUFFER = (void far *) sMsg;
- Ncb.NCB_LENGTH = strlen(sMsg);
- Ncb.NCB_CMD_CPLT = STATUS_UNKNOWN;
- _ES = FP_SEG(&Ncb);
- _BX = FP_OFF(&Ncb);
- _AX = 0x0100;
- geninterrupt(0x5c);
- return(Ncb.NCB_CMD_CPLT);
- } /* NetSend */
-