This application exhibits the different datagram operations conceivable from NetBIOS. This incorporates sending and eceiving both coordinated and gathering datagrams and additionally show datagrams.
Assemble
cl - o Nbdgram.exe Nbdgram.c ..\Common\Nbcommon.obj Netapi32.lib User32.lib
Charge Line Options
nbdgram.exe choices
- n:NAME Register my exceptional NAME
- g:NAME Register my gathering NAME
- s I will be sending datagrams
- c:xxx Number of datagrams to send
- r:NAME The beneficiaries NetBIOS name
- b Use telecast datagrams
- a Receive datagrams for any NetBIOS name
- l:xxx Send datagrams on LANA number xxx just
- d:xxx Delay (in milliseconds) between sends
/Module Name: Nbdgram.c
/
/Description:
/This application shows the different datagram operations
/conceivable from NetBIOS. This incorporates sending and accepting
/both coordinated and gathering datagrams and show datagrams.
/
/Compile:
/cl - o Nbdgram.exe Nbdgram.c ..\Common\Nbcommon.obj
/Netapi32.lib User32.lib
/
/Command Line Options:
/nbdgram.exe alternatives
/ - n:NAME Register my one of a kind NAME
/ - g:NAME Register my gathering NAME
/ - s I will be sending datagrams
/ - c:xxx Number of datagrams to send
/ - r:NAME The beneficiaries NetBIOS name
/ - b Use telecast datagrams
/ - a Receive datagrams for any NetBIOS name
/ - l:xxx Send datagrams on LANA number xxx just
/ - d:xxx Delay (in milliseconds) between sends
/
#include
#include
#include
#include "..\Common\nbcommon.h"
#define MAX_SESSIONS 254
#define MAX_NAMES 254
#define MAX_DATAGRAM_SIZE 512
BOOL bSender = FALSE,/Send or get datagrams
bRecvAny = FALSE,/Receive for any name
bUniqueName = TRUE,/Register my name as one of a kind?
bBroadcast = FALSE,/Use telecast datagrams?
bOneLana = FALSE;/Use all LANAs or only one?
singe szLocalName[NCBNAMSZ + 1],/Local NetBIOS name
szRecipientName[NCBNAMSZ + 1];/Recipients NetBIOS name
DWORD dwNumDatagrams = 25,/Number of datagrams to sen
dwOneLana,/If utilizing one LANA, which one
dwDelay = 0;/Delay between datagram send
/
/Function: ValidateArgs
/
/Description:
/This capacity parses the charge line contentions
/and sets different worldwide banners demonstrating the determinations.
/
void ValidateArgs(int argc, burn **argv)
{
int i;
for(i = 1; i < argc; i++)
{
on the off chance that (strlen(argv[i]) < 2)
proceed;
in the event that ((argv[i][0] == '- ') || (argv[i][0] == '/'))
{
switch (tolower(argv[i][1]))
{
case 'n':/Use an one of a kind name
bUniqueName = TRUE;
in the event that (strlen(argv[i]) > 2)
strcpy(szLocalName, &argv[i][3]);
break;
case 'g':/Use a gathering name
bUniqueName = FALSE;
in the event that (strlen(argv[i]) > 2)
strcpy(szLocalName, &argv[i][3]);
break;
case 's':/Send datagrams
bSender = TRUE;
break;
case 'c':/Num datagrams to send or get
in the event that (strlen(argv[i]) > 2)
dwNumDatagrams = atoi(&argv[i][3]);
break;
case 'r':/Recipient's name for datagrams
in the event that (strlen(argv[i]) > 2)
strcpy(szRecipientName, &argv[i][3]);
break;
case 'b':/Use telecast datagrams
bBroadcast = TRUE;
break;
case 'a':/Receive datagrams on any name
bRecvAny = TRUE;
break;
case 'l':/Operate on this LANA just
bOneLana = TRUE;
in the event that (strlen(argv[i]) > 2)
dwOneLana = atoi(&argv[i][3]);
break;
case 'd':/Delay (millisecs) between sends
in the event that (strlen(argv[i]) > 2)
dwDelay = atoi(&argv[i][3]);
break;
default:
printf("usage: nbdgram ?\n");
break;
}
}
}
return;
}
/
/Function: DatagramSend
/
/Description:
/Send a coordinated datagram to the predefined beneficiary on the
/determined LANA number from the given name number to the
/determined beneficiary. Additionally determined is the information cradle and
/the quantity of bytes to send.
/
int DatagramSend(int lana, int num, singe *recipient,
singe *buffer, int buflen)
{
Ncb;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBDGSEND;
ncb.ncb_lana_num = lana;
ncb.ncb_num = num;
ncb.ncb_buffer = (PUCHAR)buffer;
ncb.ncb_length = buflen;
memset(ncb.ncb_callname, " ', NCBNAMSZ);
strncpy(ncb.ncb_callname, beneficiary, strlen(recipient));
on the off chance that (Netbios(&ncb) != NRC_GOODRET)
{
printf("Netbios: NCBDGSEND fizzled: %d\n", ncb.ncb_retcode);
return ncb.ncb_retcode;
}
return NRC_GOODRET;
}
/
/Function: DatagramSendBC
/
/Description:
/Send a show datagram on the predetermined LANA number from the
/given name number. Likewise indicated is the information cushion and number
/of bytes to send.
/
int DatagramSendBC(int lana, int num, roast *buffer, int buflen)
{
Ncb;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBDGSENDBC;
ncb.ncb_lana_num = lana;
ncb.ncb_num = num;
ncb.ncb_buffer = (PUCHAR)buffer;
ncb.ncb_length = buflen;
on the off chance that (Netbios(&ncb) != NRC_GOODRET)
{
printf("Netbios: NCBDGSENDBC fizzled: %d\n", ncb.ncb_retcode);
return ncb.ncb_retcode;
}
return NRC_GOODRET;
}
/
/Function: DatagramRecv
/
/Description:
/Receive a datagram on the given LANA number coordinated towards the
/name spoke to by num. Information is replicated into the supplied support.
/If hEvent is not zero then the get call is made nonconcurrently
/with the supplied occasion handle. On the off chance that num is 0xFF then listen for a
/datagram bound for any NetBIOS name enrolled by the procedure.
/
int DatagramRecv(PNCB pncb, int lana, int num, singe *buffer,
int buflen, HANDLE hEvent)
{
ZeroMemory(pncb, sizeof(NCB));
in the event that (hEvent)
{
pncb->ncb_command = NCBDGRECV | ASYNCH;
pncb->ncb_event = hEvent;
}
else
pncb->ncb_command = NCBDGRECV;
pncb->ncb_lana_num = lana;
pncb->ncb_num = num;
pncb->ncb_buffer = (PUCHAR)buffer;
pncb->ncb_length = buflen;
in the event that (Netbios(pncb) != NRC_GOODRET)
{
printf("Netbos: NCBDGRECV fizzled: %d\n", pncb->ncb_retcode);
return pncb->ncb_retcode;
}
return NRC_GOODRET;
}
/
/Function: DatagramRecvBC
/
/Description:
/Receive a telecast datagram on the given LANA number.
/Data is duplicated into the supplied cushion. On the off chance that hEvent is not zero
/then the get call is made nonconcurrently with the supplied
/occasion handle.
/
int DatagramRecvBC(PNCB pncb, int lana, int num, scorch *buffer,
int buflen, HANDLE hEvent)
{
ZeroMemory(pncb, sizeof(NCB));
on the off chance that (hEvent)
{
pncb->ncb_command = NCBDGRECVBC | ASYNCH;
pncb->ncb_event = hEvent;
}
else
pncb->ncb_command = NCBDGRECVBC;
pncb->ncb_lana_num = lana;
pncb->ncb_num = num;
pncb->ncb_buffer = (PUCHAR)buffer;
pncb->ncb_length = buflen;
on the off chance that (Netbios(pncb) != NRC_GOODRET)
{
printf("Netbios: NCBDGRECVBC fizzled: %d\n", pncb->ncb_retcode);
return pncb->ncb_retcode;
}
return NRC_GOODRET;
}
/
/Function: principle
/
/Description:
/Initialize the NetBIOS interface, assign assets, and after that
/send or get datagrams as indicated by the client's choices.
/
int main(int argc, burn **argv)
{
LANA_ENUM lenum;
int i, j;
burn szMessage[MAX_DATAGRAM_SIZE],
szSender[NCBNAMSZ + 1];
DWORD *dwNum = NULL,
dwBytesRead,
dwErr;
ValidateArgs(argc, argv);
/
/Enumerate and reset the LANA numbers
/
on the off chance that ((dwErr = LanaEnum(&lenum)) != NRC_GOODRET)
{
printf("LanaEnum fizzled: %d\n", dwErr);
return 1;
}
on the off chance that ((dwErr = ResetAll(&lenum, (UCHAR)MAX_SESSIONS,
(UCHAR)MAX_NAMES, FALSE)) != NRC_GOODRET)
{
printf("ResetAll fizzled: %d\n", dwErr);
return 1;
}
/
/This cradle holds the name number for the NetBIOS name included
/to each LANA
/
dwNum = (DWORD *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
sizeof(DWORD) * lenum.length);
in the event that (dwNum == NULL)
{
printf("out of memory\n");
return 1;
}
/
/If we're going to work just on one LANA register the name
/just on that predetermined LANA; generally enroll it on all.
/
in the event that (bOneLana)
{
in the event that (bUniqueName)
AddName(dwOneLana, szLocalName, &dwNum[0]);
else
AddGroupName(dwOneLana, szLocalName, &dwNum[0]);
}
else
{
for(i = 0; i < lenum.length; i++)
{
in the event that (bUniqueName)
AddName(lenum.lana[i], szLocalName, &dwNum[i]);
else
AddGroupNa