Click here to Skip to main content
15,876,943 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Explain to me Net Bios Names! Pin
Ilamparithi24-Nov-03 20:22
Ilamparithi24-Nov-03 20:22 
GeneralRe: Explain to me Net Bios Names! Pin
BaldwinMartin24-Nov-03 20:29
BaldwinMartin24-Nov-03 20:29 
GeneralRe: Explain to me Net Bios Names! Pin
BaldwinMartin24-Nov-03 20:43
BaldwinMartin24-Nov-03 20:43 
GeneralRe: Explain to me Net Bios Names! Pin
Ilamparithi24-Nov-03 21:09
Ilamparithi24-Nov-03 21:09 
GeneralRe: Explain to me Net Bios Names! Pin
BaldwinMartin24-Nov-03 21:18
BaldwinMartin24-Nov-03 21:18 
GeneralRe: Explain to me Net Bios Names! Pin
Ilamparithi24-Nov-03 22:07
Ilamparithi24-Nov-03 22:07 
GeneralRe: Explain to me Net Bios Names! Pin
speedpacer25-Nov-03 13:20
speedpacer25-Nov-03 13:20 
GeneralRe: Explain to me Net Bios Names! Pin
BaldwinMartin25-Nov-03 15:10
BaldwinMartin25-Nov-03 15:10 
Wow! Great information! Thank is just what I needed. Microsoft White Paper 1999 shows that you must pad the NetBiosName to length of 20 excluding a \0

Show I ran nbtstat -n on my new HP and it returned the following.
Local Area Connection:
Node IpAddress: [68.116.126.8] Scope Id: []
NetBIOS Local Name Table
Name Type Status
---------------------------------------------
HP2003 <00> UNIQUE Registered
HP2003 <20> UNIQUE Registered
WORKGROUP <00> GROUP Registered
WORKGROUP <1E> GROUP Registered
WORKGROUP <1D> UNIQUE Registered
..__MSBROWSE__.<01> GROUP Registered


So what is the proper way to obtain the MAC address of a system?
may I get the MAC address by?:

In the fine codeproject article "Get MAC Address" by Ryszard Krakowiak http://www.codeproject.com/internet/getmac.asp?target=MAC
shows in part:
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff[30];
} ASTAT, * PASTAT;


CString GetMacAddress(CString sNetBiosName)
{
ASTAT Adapter;

NCB ncb;
UCHAR uRetCode;

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

uRetCode = Netbios(&ncb);

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

sNetBiosName.MakeUpper();

FillMemory(ncb.ncb_callname, NCBNAMSZ - 1, 0x20);

strcpy((char *)ncb.ncb_callname, (LPCTSTR) sNetBiosName);

ncb.ncb_callname[sNetBiosName.GetLength()] = 0x20;
ncb.ncb_callname[NCBNAMSZ] = 0x0;

ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter);

uRetCode = Netbios(&ncb);

CString sMacAddress;

if (uRetCode == 0)
{
sMacAddress.Format(_T("%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 sMacAddress;
}


where another fine article uses the GUID for obtaining the MAC address.



CString CTinyMacDlg::TryMac()
{
CString strReturn;
GUID uuid;
// In Win2k or higher, CoCreateGuid no longer returns a mac address, but UuidCreate
// Sequential does.
typedef RPC_STATUS (CALLBACK* UuidCreateSequential_t)(UUID*);
// This doesn't exist Pre win2k,
// in that case it uses CoCreateGuid (which will fail in 2k+) - mc
HMODULE hRpcrt4 = LoadLibrary("rpcrt4.dll"); // Attempt to load RPCRT4.DLL
if(hRpcrt4)
{
UuidCreateSequential_t fpUuidCreateSequential;
fpUuidCreateSequential = (UuidCreateSequential_t)
GetProcAddress(hRpcrt4, "UuidCreateSequential");
// Attempt dynamic load of UuidCreateSequential c
if(fpUuidCreateSequential)
{
// Create Sequential UUID for determination of MAC Address
fpUuidCreateSequential(&uuid);
}
else
{ // OS Doesn't support UuidCreateSequential, so fall back on CoCreateGuid
CoCreateGuid(&uuid);
}
FreeLibrary(hRpcrt4);
}
else
{ // OS Doesn't support UuidCreateSequential, so fall back on CoCreateGuid
CoCreateGuid(&uuid);
}

// Now Format The adapter address - mc
strReturn.Format("%2.2X-%2.2X-%2.2X-%2.2X-%2.2X-%2.2X",
uuid.Data4[2],
uuid.Data4[3],
uuid.Data4[4],
uuid.Data4[5],
uuid.Data4[6],
uuid.Data4[7]);
return strReturn;
}


My next question is which is thr proper way or is there another way?


Thank you so very much for your thoughful response.

Marty


Best Wishes,
ez_way
GeneralRe: Explain to me Net Bios Names! Pin
speedpacer25-Nov-03 16:21
speedpacer25-Nov-03 16:21 
GeneralRe: Explain to me Net Bios Names! Pin
BaldwinMartin25-Nov-03 16:27
BaldwinMartin25-Nov-03 16:27 
QuestionHow can I get the window handle from process id? Pin
Anonymous24-Nov-03 17:28
Anonymous24-Nov-03 17:28 
AnswerRe: How can I get the window handle from process id? Pin
John R. Shaw24-Nov-03 18:26
John R. Shaw24-Nov-03 18:26 
GeneralRe: How can I get the window handle from process id? Pin
Anonymous24-Nov-03 21:51
Anonymous24-Nov-03 21:51 
GeneralOriginal Window Procedure Pin
alex.barylski24-Nov-03 17:24
alex.barylski24-Nov-03 17:24 
GeneralRe: Original Window Procedure Pin
John R. Shaw24-Nov-03 18:05
John R. Shaw24-Nov-03 18:05 
GeneralRe: Original Window Procedure Pin
alex.barylski24-Nov-03 18:10
alex.barylski24-Nov-03 18:10 
GeneralRe: Original Window Procedure Pin
John R. Shaw24-Nov-03 18:42
John R. Shaw24-Nov-03 18:42 
GeneralRe: Original Window Procedure Pin
cmk24-Nov-03 21:57
cmk24-Nov-03 21:57 
GeneralActiveX Pin
vijisu24-Nov-03 16:26
vijisu24-Nov-03 16:26 
GeneralRe: ActiveX Pin
John R. Shaw24-Nov-03 18:36
John R. Shaw24-Nov-03 18:36 
GeneralHelp getting templates converted from a VC6 to VS.NET 2003 Pin
Anonymous24-Nov-03 15:14
Anonymous24-Nov-03 15:14 
GeneralRe: Help getting templates converted from a VC6 to VS.NET 2003 Pin
Christian Graus24-Nov-03 15:26
protectorChristian Graus24-Nov-03 15:26 
GeneralRe: Help getting templates converted from a VC6 to VS.NET 2003 Pin
Anonymous24-Nov-03 15:31
Anonymous24-Nov-03 15:31 
GeneralRe: Help getting templates converted from a VC6 to VS.NET 2003 Pin
Christian Graus24-Nov-03 15:33
protectorChristian Graus24-Nov-03 15:33 
GeneralRe: Help getting templates converted from a VC6 to VS.NET 2003 Pin
Anonymous24-Nov-03 16:17
Anonymous24-Nov-03 16:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.