各位老大:谁有netbios协议的例子程序.发一个给小弟,急用.

yuanlin13 2004-12-03 04:49:39
各位老大,用IPX/netbios和tcp/ip的netbios的使用有什么不同的地方吗?
...全文
126 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanlin13 2004-12-06
  • 打赏
  • 举报
回复
在没有现成的服务器和客户端的例子.
oyljerry 2004-12-03
  • 打赏
  • 举报
回复
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <nb30.h>

int Recv(int lana, int lsn, char *buffer, WORD *len);
int Send(int lana, int lsn, char *data, WORD len);
int AddName(int lana, char *name, int *num);
int DelName(int lana, char *name);
int AddGroupName(int lana, char *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, char *outname);

int LanaEnum(LANA_ENUM *lenum)
{
NCB ncb;

ZeroMemory(&ncb, sizeof(NCB));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (PUCHAR)lenum;
ncb.ncb_length = sizeof(LANA_ENUM);

if (Netbios(&ncb) != NRC_GOODRET)
{
printf("ERROR: Netbios: NCBENUM: %d\n", ncb.ncb_retcode);
return ncb.ncb_retcode;
}
return NRC_GOODRET;
}

//
// Reset each LANA listed in the LANA_ENUM structure. Also, set
// the NetBIOS environment (max sessions, max name table size),
// and use the first NetBIOS name.
//
int ResetAll(LANA_ENUM *lenum, UCHAR ucMaxSession,
UCHAR ucMaxName, BOOL bFirstName)
{
NCB 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];
if (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 given name to the given LANA number. Return the name
// number for the registered name.
//
int AddName(int lana, char *name, int *num)
{
NCB 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));

if (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 group name to the given LANA
// number. Return the name number for the added name.
//
int AddGroupName(int lana, char *name, int *num)
{
NCB 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));

if (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 associated
// with the LANA number
//
int DelName(int lana, char *name)
{
NCB 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));

if (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;
}
kingzai 2004-12-03
  • 打赏
  • 举报
回复
http://www.homenethelp.com/web/faq/network-netbeui.asp
Caps77 2004-12-03
  • 打赏
  • 举报
回复
《windows网络编程技术》第一章
yuanlin13 2004-12-03
  • 打赏
  • 举报
回复
e_mail:yuanlin13@tom.com

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧