Cant get mac address though api on xpe

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am using the

Public Declare Function GetAdaptersInfo Lib "IPHlpApi.dll" _
(IpAdapterInfo As Any, pOutBufLen As Long) As Long

API call, which on my full system will return the mac address of the machine
in the data structure, but returns blank (as are most of the other entries)
on my embedded system.

Am i missing a component?

Cheers elvis
 
Hi,

No error code is reported, returned values (eg MacAddress, DNS Server list,
Gareway) etc come up blank. The API call itself does not fail. The full copy
of xp on the system gives all the correct information.

I am using minlogon, nforce2 network drivers (MCP), and a dhcp server. I
have network access from the machine, and ipconfig returns normal values.
Does the function call use WMI, which i am not using? From what i read it
doesnt, but you can never judge dependencies ...

ta
elvis
 
Hi Elvis,

Something is always reported. Either ERROR_SUCCESS (0) or some other value when API function return. So what is it?
What about other values are there some filled correctly when function return?

FYI:
If you need real hardware MAC value then talk to NIC driver itself and use OID_802_3_PERMANENT_ADDRESS.
All API funtion will return value reported by OID_802_3_CURRENT_ADDRESS
http://msdn.microsoft.com/library/d..._90351e04-5de8-4491-ae8e-5935ecc1b68d.xml.asp

Regards,
Slobodan
 
The following works for me, Minlogon with minimal components....

Regards,

Stuart

int GetMacAddress( PCHAR _buf, unsigned _length )
{
int result = 0;
const int ID_SIZE = 6;
const char* CALL_NAME = "* ";
ASTAT adapter;
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lenum;

::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (UCHAR*)(&lenum);
ncb.ncb_length = sizeof(lenum);
Netbios( &ncb );
//
// Look for first valid LANA number
//
for ( int i=0 ; i<lenum.length ; i++ )
{
//
// Reset Device
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lenum.lana;
Netbios( &ncb );
//
// Stat Device for identification
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lenum.lana;
strcpy( (char*)(ncb.ncb_callname), CALL_NAME );
ncb.ncb_buffer = (UCHAR*)(&adapter);
ncb.ncb_length = sizeof(adapter);
uRetCode = Netbios( &ncb );

if ( uRetCode == 0 )
{
//
// We have the MAC address.
//
::memcpy( _buf, adapter.adapt.adapter_address, ID_SIZE );
result = ID_SIZE;
break;
}
}
return (result);
}
 
Hi Stuart,

You have component "NetBIOS Driver" is your image.
Are you sure that you want this "thing" in there?

Regards,
Slobodan


Stuart Langley said:
The following works for me, Minlogon with minimal components....

Regards,

Stuart

int GetMacAddress( PCHAR _buf, unsigned _length )
{
int result = 0;
const int ID_SIZE = 6;
const char* CALL_NAME = "* ";
ASTAT adapter;
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lenum;

::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (UCHAR*)(&lenum);
ncb.ncb_length = sizeof(lenum);
Netbios( &ncb );
//
// Look for first valid LANA number
//
for ( int i=0 ; i<lenum.length ; i++ )
{
//
// Reset Device
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lenum.lana;
Netbios( &ncb );
//
// Stat Device for identification
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lenum.lana;
strcpy( (char*)(ncb.ncb_callname), CALL_NAME );
ncb.ncb_buffer = (UCHAR*)(&adapter);
ncb.ncb_length = sizeof(adapter);
uRetCode = Netbios( &ncb );

if ( uRetCode == 0 )
{
//
// We have the MAC address.
//
::memcpy( _buf, adapter.adapt.adapter_address, ID_SIZE );
result = ID_SIZE;
break;
}
}
return (result);
}

Slobodan Brcin (eMVP) said:
Hi Elvis,

Something is always reported. Either ERROR_SUCCESS (0) or some other value
when API function return. So what is it?
What about other values are there some filled correctly when function
return?

FYI:
If you need real hardware MAC value then talk to NIC driver itself and use
OID_802_3_PERMANENT_ADDRESS.
All API funtion will return value reported by OID_802_3_CURRENT_ADDRESS
http://msdn.microsoft.com/library/d..._90351e04-5de8-4491-ae8e-5935ecc1b68d.xml.asp

Regards,
Slobodan
 
Hi Slobodan,

Hmmm... not sure why I shouldn't have it? Any insight on issues it might
cause?

Regards,

Stuart

Slobodan Brcin (eMVP) said:
Hi Stuart,

You have component "NetBIOS Driver" is your image.
Are you sure that you want this "thing" in there?

Regards,
Slobodan


Stuart Langley said:
The following works for me, Minlogon with minimal components....

Regards,

Stuart

int GetMacAddress( PCHAR _buf, unsigned _length )
{
int result = 0;
const int ID_SIZE = 6;
const char* CALL_NAME = "* ";
ASTAT adapter;
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lenum;

::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (UCHAR*)(&lenum);
ncb.ncb_length = sizeof(lenum);
Netbios( &ncb );
//
// Look for first valid LANA number
//
for ( int i=0 ; i<lenum.length ; i++ )
{
//
// Reset Device
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lenum.lana;
Netbios( &ncb );
//
// Stat Device for identification
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lenum.lana;
strcpy( (char*)(ncb.ncb_callname), CALL_NAME );
ncb.ncb_buffer = (UCHAR*)(&adapter);
ncb.ncb_length = sizeof(adapter);
uRetCode = Netbios( &ncb );

if ( uRetCode == 0 )
{
//
// We have the MAC address.
//
::memcpy( _buf, adapter.adapt.adapter_address, ID_SIZE );
result = ID_SIZE;
break;
}
}
return (result);
}

Slobodan Brcin (eMVP) said:
Hi Elvis,

Something is always reported. Either ERROR_SUCCESS (0) or some other
value
when API function return. So what is it?
What about other values are there some filled correctly when function
return?

FYI:
If you need real hardware MAC value then talk to NIC driver itself and
use
OID_802_3_PERMANENT_ADDRESS.
All API funtion will return value reported by OID_802_3_CURRENT_ADDRESS
http://msdn.microsoft.com/library/d..._90351e04-5de8-4491-ae8e-5935ecc1b68d.xml.asp

Regards,
Slobodan

Hi,

No error code is reported, returned values (eg MacAddress, DNS Server
list,
Gareway) etc come up blank. The API call itself does not fail. The
full
copy
of xp on the system gives all the correct information.

I am using minlogon, nforce2 network drivers (MCP), and a dhcp server.
I
have network access from the machine, and ipconfig returns normal
values.
Does the function call use WMI, which i am not using? From what i read
it
doesnt, but you can never judge dependencies ...

ta
elvis

:

Hi Elvis,

How about giving us error value returned by GetAdaptersInfo? This
would
be a good start.

Also check if your network cable is plugged in and read trough:
http://groups.google.com/groups?hl=...a=group=microsoft.public.windowsxp.embedded.*

Regards,
Slobodan

PS:
Let us know what the problem was.

Hi,

I am using the

Public Declare Function GetAdaptersInfo Lib "IPHlpApi.dll" _
(IpAdapterInfo As Any, pOutBufLen As Long) As Long

API call, which on my full system will return the mac address of
the
machine
in the data structure, but returns blank (as are most of the other
entries)
on my embedded system.

Am i missing a component?

Cheers elvis

 
Hi Stuart,

Main rule. If you don't need some feature and you won't need it then do not use it since it might pose unnecessary security hole.

Read trough following posts there might be some answers whether this is dangerous or not:
http://groups.google.com/groups?hl=en&lr=&c2coff=1&q=netbios+security&meta=

But if you need MAC number is only reason for using this then try avoiding it.
Also you should be aware that MAC number returned by this function is MAC number currently set in software or BIOS real hardware MAC
number must be asked from driver itself.

Regards,
Slobodan

Stuart Langley said:
Hi Slobodan,

Hmmm... not sure why I shouldn't have it? Any insight on issues it might
cause?

Regards,

Stuart

Slobodan Brcin (eMVP) said:
Hi Stuart,

You have component "NetBIOS Driver" is your image.
Are you sure that you want this "thing" in there?

Regards,
Slobodan


Stuart Langley said:
The following works for me, Minlogon with minimal components....

Regards,

Stuart

int GetMacAddress( PCHAR _buf, unsigned _length )
{
int result = 0;
const int ID_SIZE = 6;
const char* CALL_NAME = "* ";
ASTAT adapter;
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lenum;

::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (UCHAR*)(&lenum);
ncb.ncb_length = sizeof(lenum);
Netbios( &ncb );
//
// Look for first valid LANA number
//
for ( int i=0 ; i<lenum.length ; i++ )
{
//
// Reset Device
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lenum.lana;
Netbios( &ncb );
//
// Stat Device for identification
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lenum.lana;
strcpy( (char*)(ncb.ncb_callname), CALL_NAME );
ncb.ncb_buffer = (UCHAR*)(&adapter);
ncb.ncb_length = sizeof(adapter);
uRetCode = Netbios( &ncb );

if ( uRetCode == 0 )
{
//
// We have the MAC address.
//
::memcpy( _buf, adapter.adapt.adapter_address, ID_SIZE );
result = ID_SIZE;
break;
}
}
return (result);
}

Hi Elvis,

Something is always reported. Either ERROR_SUCCESS (0) or some other
value
when API function return. So what is it?
What about other values are there some filled correctly when function
return?

FYI:
If you need real hardware MAC value then talk to NIC driver itself and
use
OID_802_3_PERMANENT_ADDRESS.
All API funtion will return value reported by OID_802_3_CURRENT_ADDRESS

http://msdn.microsoft.com/library/d..._90351e04-5de8-4491-ae8e-5935ecc1b68d.xml.asp
Regards,
Slobodan

Hi,

No error code is reported, returned values (eg MacAddress, DNS Server
list,
Gareway) etc come up blank. The API call itself does not fail. The
full
copy
of xp on the system gives all the correct information.

I am using minlogon, nforce2 network drivers (MCP), and a dhcp server.
I
have network access from the machine, and ipconfig returns normal
values.
Does the function call use WMI, which i am not using? From what i read
it
doesnt, but you can never judge dependencies ...

ta
elvis

:

Hi Elvis,

How about giving us error value returned by GetAdaptersInfo? This
would
be a good start.

Also check if your network cable is plugged in and read trough:
http://groups.google.com/groups?hl=...a=group=microsoft.public.windowsxp.embedded.*

Regards,
Slobodan

PS:
Let us know what the problem was.

Hi,

I am using the

Public Declare Function GetAdaptersInfo Lib "IPHlpApi.dll" _
(IpAdapterInfo As Any, pOutBufLen As Long) As Long

API call, which on my full system will return the mac address of
the
machine
in the data structure, but returns blank (as are most of the other
entries)
on my embedded system.

Am i missing a component?

Cheers elvis

 
One thing that I accidentally stumbled on just now that confirm by point:
Security Update for Windows XP Embedded with SP1 (824105)
QFE: MS03-034 - Flaw in NetBIOS Could Lead to Information Disclosure
So at least you should apply this QFE but even this does not give you any guaranties.

Regards,
Slobodan




Slobodan Brcin (eMVP) said:
Hi Stuart,

Main rule. If you don't need some feature and you won't need it then do not use it since it might pose unnecessary security hole.

Read trough following posts there might be some answers whether this is dangerous or not:
http://groups.google.com/groups?hl=en&lr=&c2coff=1&q=netbios+security&meta=

But if you need MAC number is only reason for using this then try avoiding it.
Also you should be aware that MAC number returned by this function is MAC number currently set in software or BIOS real hardware MAC
number must be asked from driver itself.

Regards,
Slobodan

Stuart Langley said:
Hi Slobodan,

Hmmm... not sure why I shouldn't have it? Any insight on issues it might
cause?

Regards,

Stuart

Slobodan Brcin (eMVP) said:
Hi Stuart,

You have component "NetBIOS Driver" is your image.
Are you sure that you want this "thing" in there?

Regards,
Slobodan


"Stuart Langley" <stuart.langley at ainsworth.com.au> wrote in message
The following works for me, Minlogon with minimal components....

Regards,

Stuart

int GetMacAddress( PCHAR _buf, unsigned _length )
{
int result = 0;
const int ID_SIZE = 6;
const char* CALL_NAME = "* ";
ASTAT adapter;
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lenum;

::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (UCHAR*)(&lenum);
ncb.ncb_length = sizeof(lenum);
Netbios( &ncb );
//
// Look for first valid LANA number
//
for ( int i=0 ; i<lenum.length ; i++ )
{
//
// Reset Device
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lenum.lana;
Netbios( &ncb );
//
// Stat Device for identification
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lenum.lana;
strcpy( (char*)(ncb.ncb_callname), CALL_NAME );
ncb.ncb_buffer = (UCHAR*)(&adapter);
ncb.ncb_length = sizeof(adapter);
uRetCode = Netbios( &ncb );

if ( uRetCode == 0 )
{
//
// We have the MAC address.
//
::memcpy( _buf, adapter.adapt.adapter_address, ID_SIZE );
result = ID_SIZE;
break;
}
}
return (result);
}

Hi Elvis,

Something is always reported. Either ERROR_SUCCESS (0) or some other
value
when API function return. So what is it?
What about other values are there some filled correctly when function
return?

FYI:
If you need real hardware MAC value then talk to NIC driver itself and
use
OID_802_3_PERMANENT_ADDRESS.
All API funtion will return value reported by OID_802_3_CURRENT_ADDRESS

http://msdn.microsoft.com/library/d..._90351e04-5de8-4491-ae8e-5935ecc1b68d.xml.asp
 
Thanks Slobodan.

Slobodan Brcin (eMVP) said:
One thing that I accidentally stumbled on just now that confirm by point:
Security Update for Windows XP Embedded with SP1 (824105)
QFE: MS03-034 - Flaw in NetBIOS Could Lead to Information Disclosure
So at least you should apply this QFE but even this does not give you
any guaranties.

Regards,
Slobodan




Slobodan Brcin (eMVP) said:
Hi Stuart,

Main rule. If you don't need some feature and you won't need it then do
not use it since it might pose unnecessary security hole.

Read trough following posts there might be some answers whether this is
dangerous or not:
http://groups.google.com/groups?hl=en&lr=&c2coff=1&q=netbios+security&meta=

But if you need MAC number is only reason for using this then try
avoiding it.
Also you should be aware that MAC number returned by this function is MAC
number currently set in software or BIOS real hardware MAC
number must be asked from driver itself.

Regards,
Slobodan

Stuart Langley said:
Hi Slobodan,

Hmmm... not sure why I shouldn't have it? Any insight on issues it
might
cause?

Regards,

Stuart

Hi Stuart,

You have component "NetBIOS Driver" is your image.
Are you sure that you want this "thing" in there?

Regards,
Slobodan


"Stuart Langley" <stuart.langley at ainsworth.com.au> wrote in
message
The following works for me, Minlogon with minimal components....

Regards,

Stuart

int GetMacAddress( PCHAR _buf, unsigned _length )
{
int result = 0;
const int ID_SIZE = 6;
const char* CALL_NAME = "* ";
ASTAT adapter;
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lenum;

::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (UCHAR*)(&lenum);
ncb.ncb_length = sizeof(lenum);
Netbios( &ncb );
//
// Look for first valid LANA number
//
for ( int i=0 ; i<lenum.length ; i++ )
{
//
// Reset Device
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lenum.lana;
Netbios( &ncb );
//
// Stat Device for identification
//
::ZeroMemory( &ncb, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lenum.lana;
strcpy( (char*)(ncb.ncb_callname), CALL_NAME );
ncb.ncb_buffer = (UCHAR*)(&adapter);
ncb.ncb_length = sizeof(adapter);
uRetCode = Netbios( &ncb );

if ( uRetCode == 0 )
{
//
// We have the MAC address.
//
::memcpy( _buf, adapter.adapt.adapter_address,
ID_SIZE );
result = ID_SIZE;
break;
}
}
return (result);
}

Hi Elvis,

Something is always reported. Either ERROR_SUCCESS (0) or some
other
value
when API function return. So what is it?
What about other values are there some filled correctly when
function
return?

FYI:
If you need real hardware MAC value then talk to NIC driver itself
and
use
OID_802_3_PERMANENT_ADDRESS.
All API funtion will return value reported by
OID_802_3_CURRENT_ADDRESS


http://msdn.microsoft.com/library/d..._90351e04-5de8-4491-ae8e-5935ecc1b68d.xml.asp
Regards,
Slobodan

Hi,

No error code is reported, returned values (eg MacAddress, DNS
Server
list,
Gareway) etc come up blank. The API call itself does not fail.
The
full
copy
of xp on the system gives all the correct information.

I am using minlogon, nforce2 network drivers (MCP), and a dhcp
server.
I
have network access from the machine, and ipconfig returns normal
values.
Does the function call use WMI, which i am not using? From what i
read
it
doesnt, but you can never judge dependencies ...

ta
elvis

:

Hi Elvis,

How about giving us error value returned by GetAdaptersInfo?
This
would
be a good start.

Also check if your network cable is plugged in and read trough:
http://groups.google.com/groups?hl=...a=group=microsoft.public.windowsxp.embedded.*

Regards,
Slobodan

PS:
Let us know what the problem was.

Hi,

I am using the

Public Declare Function GetAdaptersInfo Lib "IPHlpApi.dll" _
(IpAdapterInfo As Any, pOutBufLen As Long) As Long

API call, which on my full system will return the mac address
of
the
machine
in the data structure, but returns blank (as are most of the
other
entries)
on my embedded system.

Am i missing a component?

Cheers elvis

 
Back
Top