home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
lan
/
nbsamp.arc
/
NBRCV2.C
< prev
next >
Wrap
Text File
|
1988-09-26
|
3KB
|
103 lines
/* NBRCV2.C - sample program - receives NetBIOS datagram. - */
/* Paul McGinnis - AST Research, Data Comm Support - Dept. 430 */
/* Sept. 1988. - comments added 9/26/88 */
/* */
/* General calling sequence for NetBIOS calls: */
/* 1. Set up NCB (Network Control Block) */
/* 2. Make ES:BX point to NCB structure */
/* 3. Load AX with 100h */
/* 4. Generate an INT 5Ch */
/* */
/* NetBIOS commands and definitions in NETBIOS.H */
/* */
/* Compilation information: */
/* Compiler: Borland Turbo C v1.5 */
/* Memory model: Small */
/* Floating point support: none */
#include <dos.h>
#include <stdio.h>
#include <netbios.h>
#include <stdlib.h>
#include <string.h>
main()
{
NCB * rcv_block;
char * rcv_message;
char * session;
char * sender;
unsigned char ret_code, net_num, iflag;
rcv_block = (NCB *) malloc(sizeof(NCB));
rcv_message = (char *) malloc(80);
session = (char *) malloc(16);
sender = (char *) malloc(16);
_AH = 0;
geninterrupt(0x2a); /* Check to see if NetBIOS is loaded */
iflag = _AH;
if (!iflag)
{
puts(" *** ERROR - NetBIOS not installed. ***");
return;
}
printf("Enter network name: ");
gets(session);
printf("Enter sender's name: ");
gets(sender);
puts("Generating network name...");
rcv_block -> NCB_COMMAND = ADD_NAME_WAIT;
rcv_block -> NCB_LANA_NUM = 0;
rcv_block -> NCB_STO = 0;
rcv_block -> NCB_RTO = 0;
strncpy(rcv_block -> NCB_NAME, session, 16);
strncpy(rcv_block -> NCB_CALLNAME, "*", 16);
_ES = _DS;
_BX = rcv_block;
_AX = 0x100;
geninterrupt(0x5c);
ret_code = _AL;
net_num = rcv_block -> NCB_NUM;
if (ret_code)
{
printf("Bad return code = %02Xh\n", ret_code);
return;
}
printf("Session established. Name number = %02Xh\n", net_num);
puts("Waiting for datagram...");
rcv_block -> NCB_RTO = 0;
strncpy(rcv_block -> NCB_CALLNAME, sender, 16);
rcv_block -> NCB_BUFFER_OFFSET = rcv_message;
rcv_block -> NCB_BUFFER_SEGMENT = _DS;
rcv_block -> NCB_LENGTH = 80;
rcv_block -> NCB_COMMAND = RECEIVE_DATAGRAM_WAIT;
_ES = _DS;
_BX = rcv_block;
_AX = 0x100;
geninterrupt(0x5c);
ret_code = _AL;
pokeb(_DS, rcv_message + rcv_block -> NCB_LENGTH, 0); /* end buffer with 0 */
if (ret_code)
printf("Error number = %02Xh\n", ret_code);
else
{
printf("%c*** %s\n", 7, rcv_message);
printf("From: %s\n", rcv_block -> NCB_CALLNAME);
}
printf("Releasing session >>>%s<<<, number %02Xh\n",
rcv_block -> NCB_NAME, net_num);
rcv_block -> NCB_NUM = net_num;
rcv_block -> NCB_COMMAND = DELETE_NAME_WAIT;
_ES = _DS;
_BX = rcv_block;
_AX = 0x100;
geninterrupt(0x5c);
ret_code = _AL;
if (ret_code)
printf("Error number = %02Xh.\n", ret_code);
else
puts("Completed normally.");
}