How to Get Network Interface Number (NIC)? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to Get Network Interface Number (NIC)?

zovestazovesta Posts: 10Member
Hii...

I would like to know how can i get the NIC number ?

i've tried the following code but it isn't what i am looking for...it gives me a string of {CCC-CCCCC-CCC}...which i doubt it's the right NIC number as i've tried it on a PC with no NIC & it gave me the same string... & i've tried it on two different PC's with NIC but i still got the same results!!
i am usingg VC++ 6

/***********************************************************/
#include "Winuser.h"
#include "Nb30.h"

struct
{
ADAPTER_STATUS AdapterStatus;
NAME_BUFFER NameBuffer;
} NcbBuffer;

UCHAR ret_code = 1;
NCB ncb;

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

// ncb.ncb_command = NCBASTAT;

ncb.ncb_num = NCBASTAT;
ncb.ncb_buffer = (PUCHAR)&NcbBuffer;
ncb.ncb_length = sizeof( NcbBuffer );
memset( ncb.ncb_callname, ' ', NCBNAMSZ - 1 );
ncb.ncb_callname[ NCBNAMSZ -1 ] = 0;
ncb.ncb_callname[ 0 ] = '*';
ret_code = Netbios( &ncb );
char s[ 256 ] = "";

for (int i = 0; i<sizeo(NcbBuffer.AdapterStatus.adapter_address ) /
sizeof(NcbBuffer.AdapterStatus.adapter_address[ 0 ] ); i++ )

sprintf( s+strlen(s), "%02X-",
NcbBuffer.AdapterStatus.adapter_address[ i ] );
s[ strlen( s ) - 1 ] = '';
MessageBox(s, "Ethernet address", MB_OK );

/***********************************************************/

Is there any better way that i can use to get the NIC number directly?

Thanx for ur help:)

Zovesta


Comments

  • DB1DB1 Posts: 1,142Member
    [b][red]This message was edited by DB1 at 2003-5-7 1:28:38[/red][/b][hr]
    : Hii...
    :
    : I would like to know how can i get the NIC number ?
    :
    : i've tried the following code but it isn't what i am looking for...it gives me a string of {CCC-CCCCC-CCC}...which i doubt it's the right NIC number as i've tried it on a PC with no NIC & it gave me the same string... & i've tried it on two different PC's with NIC but i still got the same results!!
    : i am usingg VC++ 6
    :
    : /***********************************************************/
    : #include "Winuser.h"
    : #include "Nb30.h"
    :
    : struct
    : {
    : ADAPTER_STATUS AdapterStatus;
    : NAME_BUFFER NameBuffer;
    : } NcbBuffer;
    :
    : UCHAR ret_code = 1;
    : NCB ncb;
    :
    : memset( &ncb, 0, sizeof( ncb ) );
    : ncb.ncb_command = NCBRESET;
    : ret_code = Netbios( &ncb );
    :
    : // ncb.ncb_command = NCBASTAT;
    :
    : ncb.ncb_num = NCBASTAT;
    : ncb.ncb_buffer = (PUCHAR)&NcbBuffer;
    : ncb.ncb_length = sizeof( NcbBuffer );
    : memset( ncb.ncb_callname, ' ', NCBNAMSZ - 1 );
    : ncb.ncb_callname[ NCBNAMSZ -1 ] = 0;
    : ncb.ncb_callname[ 0 ] = '*';
    : ret_code = Netbios( &ncb );
    : char s[ 256 ] = "";
    :
    : for (int i = 0; iadapter_address[ 0 ],
    AdapterStatus->adapter_address[ 1 ],
    AdapterStatus->adapter_address[ 2 ],
    AdapterStatus->adapter_address[ 3 ],
    AdapterStatus->adapter_address[ 4 ],
    AdapterStatus->adapter_address[ 5 ] );
    AfxMessageBox( NIC );

    #ifdef DISPLAY_BUFFER
    NameBuffer = ( NAME_BUFFER * ) ( AdapterStatus + 1 );

    for( i = 0; i < AdapterStatus->name_count; i++ )
    {
    Temp.Format( "%.*s
    ", NCBNAMSZ, NameBuffer[ i ].name );
    Buffer.Insert( Buffer.GetLength(), Temp );
    }
    if( AdapterStatus->name_count )
    AfxMessageBox( Buffer );
    #endif
    }
    break;
    default:
    CString ReturnCode;
    ReturnCode.Format( "Got 0x%.2x from Netbios()", ncb.ncb_retcode );
    AfxMessageBox( ReturnCode );
    break;
    }

    free( AdapterStatus );

    }[/code]

    Hope this helps!



    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]



Sign In or Register to comment.