home *** CD-ROM | disk | FTP | other *** search
- /* netrcv.c - program to receive messages
- * Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
- * Division of Cancer Prevention & Control, NCI
- */
-
- /* Revision history:
- * 1.00 ytm 12/14/90 first release
- */
-
- /* Program notes:
- * Current versions are specific for TurboC.
- */
-
- #include <local.h> /* standard definitions */
- #include "netbios.h"
-
- /* constants */
- #define USER_NUM 0xff /* receive any */
-
- /* status structure */
- #define STATUS_OK 0
- #define STATUS_UNKNOWN 0xff
- #define STATUS_STRUCT struct status
- typedef STATUS_STRUCT
- {
- word wCode;
- string sText;
- };
- STATUS_STRUCT aStatus[] =
- {
- {0, "OK"},
- {9, "message too large"},
- {19, "no local name"},
- {STATUS_UNKNOWN, "?"}
- };
-
- /* globals */
- NCB RcvNcb, CanNcb;
- char caPacket[MAX_PACKET];
- boolean bReceived = FALSE;
-
- /* function prototypes */
- short main(short argc, string argv[]);
- void NetCancel(NCB *pToCanNcb);
- void NetReceive(void interrupt (*PostFn)(), short iNbNum);
- void interrupt Post(void);
-
- /* cancel a NETBIOS command */
- void NetCancel(NCB *pToCanNcb)
- {
- memset(&CanNcb, 0, sizeof(NCB));
- CanNcb.NCB_COMMAND = CANCEL;
- CanNcb.NCB_BUFFER = (void far *) pToCanNcb;
- CanNcb.NCB_CMD_CPLT = 0xFF;
- _ES = FP_SEG(&CanNcb);
- _BX = FP_OFF(&CanNcb);
- _AX = 0x0100;
- geninterrupt(0x5c);
- } /* NetCancel */
-
- /* receive a datagram */
- void NetReceive(void interrupt (*pPostFn)(), short iNbNum)
- {
- memset(&RcvNcb, 0, sizeof(NCB));
- RcvNcb.NCB_COMMAND = RECEIVE_DATAGRAM;
- RcvNcb.NCB_NUM = iNbNum;
- RcvNcb.NCB_LENGTH = MAX_PACKET;
- RcvNcb.NCB_POST = pPostFn;
- RcvNcb.NCB_BUFFER = (void far *) caPacket;
- RcvNcb.NCB_CMD_CPLT = 0xFF;
- _ES = FP_SEG(&RcvNcb);
- _BX = FP_OFF(&RcvNcb);
- _AX = 0x0100;
- geninterrupt(0x5c);
- } /* NetReceive */
-
- void interrupt Post(void)
- {
- bReceived = TRUE;
- } /* Post */
-
- /* main */
- short main(short argc, string argv[])
- {
- boolean bMore = TRUE;
- short ch;
- short i;
- short iRcvNum = USER_NUM;
- word wStatus = 0;
- printf("Netrcv v1.00\n");
- if (argc > 1) iRcvNum = atoi(argv[1]);
- printf("Receiving for %d (press <Esc> to stop)\n", iRcvNum);
- NetReceive(Post, iRcvNum);
- while (bMore)
- {
- if (kbhit())
- {
- GETKEY(ch);
- if (ch == ESC)
- {
- bMore = FALSE;
- wStatus = STATUS_OK;
- NetCancel(&RcvNcb);
- }
- }
- if (bMore && bReceived)
- {
- wStatus = RcvNcb.NCB_CMD_CPLT;
- if (wStatus) bMore = FALSE;
- else
- {
- bReceived = FALSE;
- printf("%d byte datagram from %s\n", RcvNcb.NCB_LENGTH,
- RcvNcb.NCB_CALLNAME);
- printf("%s\n", caPacket);
- NetReceive(Post, iRcvNum);
- }
- }
- }
- for (i = 0; *(aStatus[i].sText) != '?'; i++)
- if (aStatus[i].wCode == wStatus) break;
- printf("Netrcv status: %s (%d)\n", aStatus[i].sText, RcvNcb.NCB_CMD_CPLT);
- return(i);
- } /* main */
-
-