Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Mac Address

Status
Not open for further replies.

nitroprog

Technical User
Jun 18, 2003
4
0
0
PT
Hello,

I´m a newbie in c language. I need to know if there is any way to get my mac address using a function in C language.

Thanks
 
this is from the microsft web site.
it works for me. use VC++ debug/release.

Code:
#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

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

ASTAT Adapter;

void main (void)
{
  NCB Ncb;
  UCHAR uRetCode;
  LANA_ENUM   lenum;
  int      i;

  memset( &Ncb, 0, sizeof(Ncb) );
  Ncb.ncb_command = NCBENUM;
  Ncb.ncb_buffer = (UCHAR *)&lenum;
  Ncb.ncb_length = sizeof(lenum);
  uRetCode = Netbios( &Ncb );
  printf( &quot;The NCBENUM return code is: 0x%x \n&quot;, uRetCode );

  for (i=0; i < lenum.length ;i++) { 
	memset( &Ncb, 0, sizeof(Ncb) );
	Ncb.ncb_command = NCBRESET;
	Ncb.ncb_lana_num = lenum.lana[i];
	
	uRetCode = Netbios( &Ncb );
	printf( &quot;The NCBRESET on LANA %d return code is: 0x%x \n&quot;, lenum.lana[i], uRetCode );
	
	memset( &Ncb, 0, sizeof (Ncb) );
	Ncb.ncb_command = NCBASTAT;
	Ncb.ncb_lana_num = lenum.lana[i];
	strcpy( Ncb.ncb_callname,  &quot;*               &quot; );
	Ncb.ncb_buffer = (char *) &Adapter;
	Ncb.ncb_length = sizeof(Adapter);
	
	uRetCode = Netbios( &Ncb );
	printf( &quot;The NCBASTAT on LANA %d return code is: 0x%x \n&quot;, lenum.lana[i], uRetCode );
	if ( uRetCode == 0 ) { 
	    printf ( &quot;The Ethernet Number on LANA %d is: %02x%02x%02x%02x%02x%02x\n&quot;,lenum.lana[i],
		  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] );  
	} 
  } 
}

hope this helps.



--
br: nagi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top