This header document contains the capacity models for an arrangement of capacities that actualize probably the most widely recognized NetBIOS capacities, for example, identifying LANAs, including names, uprooting names, and so on. The capacities are actualized in Nbcommon.c
/*******************************************************
* MYCPLUS Sample Code - http://www.mycplus.com *
*
* This code is made accessible as a support of our *
* guests and is given entirely to the *
* motivation behind delineation. *
*
* Please guide all request to saqib at mycplus.com *
*******************************************************/
/nbcommon.h
/
#include
#include
int Recv(int lana, int lsn, singe *buffer, DWORD *len);
int Send(int lana, int lsn, singe *data, DWORD len);
int AddName(int lana, singe *name, int *num);
int DelName(int lana, singe *name);
int AddGroupName(int lana, singe *name, int *num);
int ResetAll(LANA_ENUM *lenum, UCHAR ucMaxSession,
UCHAR ucMaxName, BOOL bFirstName);
int LanaEnum(LANA_ENUM *lenum);
int Hangup(int lana, int lsn);
int Cancel(PNCB pncb);
int FormatNetbiosName(char *nbname, singe *outname);
/**************************************************/
/
/Module Name: nbcommon.c
/
/Description:
/This document contains the capacity bodies for an arrangement of
/regular NetBIOS capacities. See the portrayals for
/every capacity on what every one does. These capacities
/are utilized by alternate NetBIOS test programs so this
/record should be accumulated to question code and connected
/with the other executable projects.
/
/Compile:
/cl/c nbcommon.c
/
/Command Line Options:
/NONE - Compile to question code
/
#include
#include
#include
#include "nbcommon.h"
/
/Enumerate all LANA numbers
/
int LanaEnum(LANA_ENUM *lenum)
{
Ncb;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (PUCHAR)lenum;
ncb.ncb_length = sizeof(LANA_ENUM);
on the off chance that (Netbios(&ncb) != NRC_GOODRET)
{
printf("ERROR: Netbios: NCBENUM: %d\n", ncb.ncb_retcode);
return ncb.ncb_retcode;
}
return NRC_GOODRET;
}
/
/Reset each LANA recorded in the LANA_ENUM structure. Likewise, set
/the NetBIOS environment (max sessions, max name table size),
/and utilize the first NetBIOS name.
/
int ResetAll(LANA_ENUM *lenum, UCHAR ucMaxSession,
UCHAR ucMaxName, BOOL bFirstName)
{
Ncb;
int i;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBRESET;
ncb.ncb_callname[0] = ucMaxSession;
ncb.ncb_callname[2] = ucMaxName;
ncb.ncb_callname[3] = (UCHAR)bFirstName;
for(i = 0; i < lenum->length; i++)
{
ncb.ncb_lana_num = lenum->lana[i];
on the off chance that (Netbios(&ncb) != NRC_GOODRET)
{
printf("ERROR: Netbios: NCBRESET[%d]: %d\n",
ncb.ncb_lana_num, ncb.ncb_retcode);
return ncb.ncb_retcode;
}
}
return NRC_GOODRET;
}
/
/Add the offered name to the given LANA number. Return the name
/number for the enrolled name.
/
int AddName(int lana, roast *name, int *num)
{
Ncb;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBADDNAME;
ncb.ncb_lana_num = lana;
memset(ncb.ncb_name, " ', NCBNAMSZ);
strncpy(ncb.ncb_name, name, strlen(name));
on the off chance that (Netbios(&ncb) != NRC_GOODRET)
{
printf("ERROR: Netbios: NCBADDNAME[lana=%d;name=%s]: %d\n",
lana, name, ncb.ncb_retcode);
return ncb.ncb_retcode;
}
*num = ncb.ncb_num;
return NRC_GOODRET;
}
/
/Add the given NetBIOS gathering name to the given LANA
/number. Return the name number for the included name.
/
int AddGroupName(int lana, roast *name, int *num)
{
Ncb;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBADDGRNAME;
ncb.ncb_lana_num = lana;
memset(ncb.ncb_name, " ', NCBNAMSZ);
strncpy(ncb.ncb_name, name, strlen(name));
on the off chance that (Netbios(&ncb) != NRC_GOODRET)
{
printf("ERROR: Netbios: NCBADDGRNAME[lana=%d;name=%s]: %d\n",
lana, name, ncb.ncb_retcode);
return ncb.ncb_retcode;
}
*num = ncb.ncb_num;
return NRC_GOODRET;
}
/
/Delete the given NetBIOS name from the name table related
/with the LANA number
/
int DelName(int lana, roast *name)
{
Ncb;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBDELNAME;
ncb.ncb_lana_num = lana;
memset(ncb.ncb_name, " ', NCBNAMSZ);
strncpy(ncb.ncb_name, name, strlen(name));
on the off chance that (Netbios(&ncb) != NRC_GOODRET)
{
printf("ERROR: Netbios: NCBADDNAME[lana=%d;name=%s]: %d\n",
lana, name, ncb.ncb_retcode);
return ncb.ncb_retcode;
}
return NRC_GOODRET;
}
/
/Send len bytes from the information support on the given session (lsn)
/and lana number.
/
int Send(int lana, int lsn, roast *data, DWORD len)
{
Ncb;
int retcode;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBSEND;
ncb.ncb_buffer = (PUCHAR)data;
ncb.ncb_length = len;
ncb.ncb_lana_num = lana;
ncb.ncb_lsn = lsn;
retcode = Netbios(&ncb);
return retcode;
}
/
/Receive up to len bytes into the information support on the given session
/(lsn) and lana number.
/
int Recv(int lana, int lsn, roast *buffer, DWORD *len)
{
Ncb;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBRECV;
ncb.ncb_buffer = (PUCHAR)buffer;
ncb.ncb_length = *len;
ncb.ncb_lana_num = lana;
ncb.ncb_lsn = lsn;
on the off chance that (Netbios(&ncb) != NRC_GOODRET)
{
*len = - 1;
return ncb.ncb_retcode;
}
*len = ncb.ncb_length;
return NRC_GOODRET;
}
/
/Disconnect the given session on the given lana number
/
int Hangup(int lana, int lsn)
{
Ncb;
int retcode;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBHANGUP;
ncb.ncb_lsn = lsn;
ncb.ncb_lana_num = lana;
retcode = Netbios(&ncb);
return retcode;
}
/
/Cancel the given offbeat charge signified in the NCB
/structure parameter.
/
int Cancel(PNCB pncb)
{
Ncb;
ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBCANCEL;
ncb.ncb_buffer = (PUCHAR)pncb;
ncb.ncb_lana_num = pncb->ncb_lana_num;
in the event that (Netbios(&ncb) != NRC_GOODRET)
{
printf("ERROR: NetBIOS: NCBCANCEL: %d\n", ncb.ncb_retcode);
return ncb.ncb_retcode;
}
return NRC_GOODRET;
}
/
/Format the given NetBIOS name so it is printable. Any
/unprintable characters are supplanted by a period. The outname
/cushion is the returned string, which is thought to be in any event
/NCBNAMSZ + 1 characters long.
/
int FormatNetbiosName(char *nbname, scorch *outname)
{
int i;
strncpy(outname, nbname, NCBNAMSZ);
outname[NCBNAMSZ - 1] = '\0';
for(i = 0; i < NCBNAMSZ - 1; i++)
{
/If the character isn't printable supplant it with a "."
/
in the event that (!((outname[i] >= 32) && (outname[i] <= 126)))
outname[i] = '.';
}
return NRC_GOODRET;
}