zhang310 2009-06-16 14:39
浏览 269
已采纳

java 调用 jni 一点不会

C++ 代码
[code="c++"]
#include
#include

#include

#include

#include

#include

#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"netapi32.lib")

void CheckIP(void)
{
WSADATA wsaData;
char name[155];
char ip;
PHOSTENT hostinfo;
if ( WSAStartup( MAKEWORD(2,0), &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (
(struct in_addr *)*hostinfo->h_addr_list);
printf(" IP地址: %s ",ip);
}
}
WSACleanup( );
}
}

int getMAC(char * mac)

{

NCB ncb;

typedef struct ASTAT

{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];

}ASTAT, *PASTAT;

ASTAT Adapter;

typedef struct _LANA_ENUM

{
UCHAR length;
UCHAR lana[MAX_LANA];

}LANA_ENUM;

LANA_ENUM lana_enum;

UCHAR uRetCode;

memset(&ncb, 0, sizeof(ncb));

memset(&lana_enum, 0, sizeof(lana_enum));

ncb.ncb_command = NCBENUM;

ncb.ncb_buffer = (unsigned char *)&lana_enum;

ncb.ncb_length = sizeof(LANA_ENUM);

uRetCode = Netbios(&ncb);

if(uRetCode != NRC_GOODRET)

return uRetCode;

for(int lana=0; lana<lana_enum.length; lana++)

{
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lana_enum.lana[lana];
uRetCode = Netbios(&ncb);

if(uRetCode == NRC_GOODRET)
break;
}
if(uRetCode != NRC_GOODRET)
return uRetCode;

memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lana_enum.lana[0];
strcpy((char*)ncb.ncb_callname, "*");
ncb.ncb_buffer = (unsigned char *)&Adapter;
ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios(&ncb);
if(uRetCode != NRC_GOODRET)

return uRetCode;

sprintf(mac,"%02X-%02X-%02X-%02X-%02X-%02X",

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]
);
return 0;

}

int main(void)
{
CheckIP();
char mac[200];

getMAC(mac);

printf(" mac地址 : %s ",mac);

return 0;
}

[/code]

谁帮助写一个 java调用 这个c++生成的 dll

程序目的 : java通过jni 调用 dll 获取客户端的 网卡 MAC

自己对这个一点没接触过....

  • 写回答

4条回答 默认 最新

  • laitaogood 2009-06-16 14:41
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding