/////////////////////////////////////////////////////////////////////////////
//
// network.cpp : Contains network relation API functions wrappers.
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "network.h"
#include "PBUtils.h"
#include <stdio.h>

PBUTILS_API bool __stdcall GetMacAddress( LPSTR szAddress )
{
	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;

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

    uRetCode = Netbios( &ncb );
    if ( uRetCode == 0 )
    {
        sprintf( szAddress, "%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] );
    }
	return (uRetCode == 0);
}
