From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a593b847b304c715 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-08 19:27:24 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!xmission!hammer.uoregon.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!attbi_s04.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <3fad244e$0$27572$626a54ce@news.free.fr> Subject: Re: Mac address with Win32 bindings. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: NNTP-Posting-Host: 12.211.58.135 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s04 1068348444 12.211.58.135 (Sun, 09 Nov 2003 03:27:24 GMT) NNTP-Posting-Date: Sun, 09 Nov 2003 03:27:24 GMT Organization: Comcast Online Date: Sun, 09 Nov 2003 03:27:24 GMT Xref: archiver1.google.com comp.lang.ada:2268 Date: 2003-11-09T03:27:24+00:00 List-Id: 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" 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. > >