comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Mac address with Win32 bindings.
Date: Sun, 09 Nov 2003 03:27:24 GMT
Date: 2003-11-09T03:27:24+00:00	[thread overview]
Message-ID: <wuirb.150012$Fm2.132677@attbi_s04> (raw)
In-Reply-To: 3fad244e$0$27572$626a54ce@news.free.fr

Converting the example at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netbios/netbios_1l82.asp
to Ada:

with Ada.Strings.Fixed;
with Ada.Text_IO;
with Win32.Nb30;
with Interfaces;
 use Interfaces;
with Interfaces.C;
with Ada.Unchecked_Conversion;

procedure Show_Mac_Address is

    use type Interfaces.C.unsigned_short;
    use type Interfaces.C.unsigned_char;

    package UInt_Io is
      new Ada.Text_IO.Modular_IO( Win32.UCHAR );

    type NAME_BUFFER_ARRAY is array( 0 .. 29 ) of Win32.nb30.NAME_BUFFER;

    type AStat is
      record
        adapt      : Win32.nb30.ADAPTER_STATUS;
        nameBuffer : NAME_BUFFER_ARRAY;
      end record;
    pragma Convention( C, AStat );

    type AstatAcc is access all Astat;

    function Conv is
      new Ada.Unchecked_Conversion( AstatAcc, Win32.PUCHAR );

    type Byte_Array_Type is array( Positive range <> ) of Unsigned_8;

    function Hex_Chars( Char_Data : Win32.UCHAR ) return String is
      str_buffer : String( 1 .. 32 );
      first_hash : Natural;
      last_hash  : Natural;
    begin
      UInt_Io.Put( str_buffer, Char_Data, 16 );
      first_hash := Ada.Strings.Fixed.Index( str_buffer, "#",
Ada.Strings.Forward );
      last_hash := Ada.Strings.Fixed.Index( str_buffer, "#",
Ada.Strings.Backward );
      return str_buffer( first_hash + 1 .. last_hash - 1 );
    end Hex_Chars;

    ncb       : aliased Win32.Nb30.NCB;
    Ncb_Alias : Byte_Array_Type( 1 .. ncb'Size/8 );
    for Ncb_Alias'Address use ncb'Address;
    Return_Code : Win32.UCHAR;
    Adapter   : aliased AStat;
  begin
    Ncb_Alias := ( others => 0 );
    ncb.ncb_command := Win32.Nb30.NCBRESET;
    ncb.ncb_lana_num := 0;

    Return_Code := Win32.Nb30.Netbios( ncb'UNCHECKED_ACCESS );
    Ada.Text_IO.Put( "The NCBRESET return code is: " & Hex_Chars(
Return_Code ) );
    Ada.Text_IO.New_Line;

    Ncb_Alias := ( others => 0 );
    ncb.ncb_command := Win32.Nb30.NCBASTAT;
    ncb.ncb_lana_num := 0;
    ncb.ncb_callname := ( 0 => Character'Pos('*'), others => Character'Pos('
') );
    ncb.ncb_buffer := Conv( Adapter'Access );
    ncb.ncb_length := Adapter'Size / 8;

    Return_Code := Win32.Nb30.Netbios( ncb'Unchecked_Access );

    Ada.Text_IO.Put( "The NCBASTAT return code is: " & Hex_Chars(
Return_Code ) );
    Ada.Text_IO.New_Line;

    if Return_Code = 0 then
      Ada.Text_IO.Put( "The Ethernet Number is: " );
      Ada.Text_IO.Put( Hex_Chars( Adapter.adapt.adapter_address(0) ) & "-" &
                       Hex_Chars( Adapter.adapt.adapter_address(1) ) & "-" &
                       Hex_Chars( Adapter.adapt.adapter_address(2) ) & "-" &
                       Hex_Chars( Adapter.adapt.adapter_address(3) ) & "-" &
                       Hex_Chars( Adapter.adapt.adapter_address(4) ) & "-" &
                       Hex_Chars( Adapter.adapt.adapter_address(5) ) );
      Ada.Text_IO.New_Line;
    end if;

end Show_Mac_Address;

For things to link correctly with GNAT you must specify the netabp32
library:

gnatmake Show_Mac_Address -largs -lnetapi32

I hope this helps,
Steve
(The Duck)


"Alex Xela" <xela2@free.fr> wrote in message
news:3fad244e$0$27572$626a54ce@news.free.fr...
> Hi,
>
> I 'm looking for some Ada stuff to get the Mac Address under WindowsNT/XP
> (using bindingWin32 -> function Win32.Nb30.Netbios())
>
> I tried in vain to write it, but honestly, I'm not a win32 API guru......
>
> Thanks.
>
> Alex.
>
>





  parent reply	other threads:[~2003-11-09  3:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-08 17:15 Mac address with Win32 bindings Alex Xela
2003-11-08 20:45 ` MAC " Larry Kilgallen
2003-11-08 21:37   ` Alex Xela
2003-11-09 12:10     ` Simon Wright
2003-11-09 13:48       ` chris
2003-11-09 22:43         ` Larry Kilgallen
2003-11-15 22:38         ` Fionn mac Cuimhaill
2003-11-16  3:07           ` Ada -vs- ADA (was: Re: MAC address with Win32 bindings.) Steve
2003-11-16 12:26             ` Marius Amado Alves
2003-11-16 20:11               ` Chad R. Meiners
2003-11-12 13:49   ` MAC address with Win32 bindings JrZ
2003-11-09  3:27 ` Steve [this message]
2003-11-09  8:59   ` Mac " Alex Xela
2003-11-09 10:56   ` Alex Xela
  -- strict thread matches above, loose matches on Subject: below --
2003-11-10 17:58 MAC " Beard, Frank Randolph CIV
2003-11-10 18:08 ` Stephane Richard
2003-11-11  7:08 ` Simon Wright
2003-11-11  8:25 ` Preben Randhol
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox