取得网卡地址

byybyybyy 2003-08-22 06:18:59
win2000,vc6.0控制台做了一个获取本机网卡的小程序。遇到困难,请求帮助。我是新手

我没分了,可怜,多谢了!

源码:

#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>

typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;

ASTAT Adapter;

void main (void)
{
NCB ncb;
UCHAR uRetCode;
char NetName[50];

memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0;

uRetCode = Netbios( &ncb );
printf( "The NCBRESET return code is: 0x%x \n", uRetCode );

memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0;

strcpy( ncb.ncb_callname, "* " );
ncb.ncb_buffer = (char *)&Adapter;
ncb.ncb_length = sizeof(Adapter);

uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}



错误信息:


--------------------Configuration: getmac - Win32 Debug--------------------
Compiling...
getmac.cpp
D:\vc\getmac\getmac.cpp(33) : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char [16]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\vc\getmac\getmac.cpp(34) : error C2440: '=' : cannot convert from 'char *' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Creating browse info file...

getmac.exe - 2 error(s), 0 warning(s)
...全文
60 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kbwan 2003-08-23
  • 打赏
  • 举报
回复
只是strcpy这个函数的参数问题,
换一下参数类型,
如果不行的话就用sprintf吧。

我是这样用的:strcpy((char *)ncb.ncb_callname, (LPCTSTR) sNetBiosName);
cattydid 2003-08-23
  • 打赏
  • 举报
回复
#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>

#include <Nb30.h>//要加这个头文件

typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;

ASTAT Adapter;

void main()
{
NCB ncb;
UCHAR uRetCode;
char NetName[50];

memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0;

uRetCode = Netbios( &ncb );
printf( "The NCBRESET return code is: 0x%x \n", uRetCode );

memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0;

//改成酱子--〉
memset( &ncb.ncb_callname, 0, sizeof(NCBNAMSZ) );//
ncb.ncb_callname[0]='*';//
ncb.ncb_buffer = (unsigned char *)&Adapter;//
//<--
ncb.ncb_length = sizeof(Adapter);

uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}
最后被忘了还要链一个库文件:netapi32.lib
singlehero 2003-08-23
  • 打赏
  • 举报
回复
经过调试发现楼上的代码里的char NetName[50]好象多余。
删除后就可以了。调试环境:win2000p+vc++6.0
xtmzl 2003-08-23
  • 打赏
  • 举报
回复
#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#pragma comment(lib,"netapi32.lib")
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;

ASTAT Adapter;

void main (void)
{
NCB ncb;
UCHAR uRetCode;
char NetName[50];

memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0;

uRetCode = Netbios( &ncb );
printf( "The NCBRESET return code is: 0x%x \n", uRetCode );

memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0;

strcpy((char*) ncb.ncb_callname, "*" );
ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter);

uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}

这样就ok了

18,356

社区成员

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

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