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.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,a593b847b304c715 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-09 00:57:48 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!tiscali!newsfeed1.ip.tiscali.net!proxad.net!feeder2-1.proxad.net!news2-2.free.fr!not-for-mail From: "Alex Xela" Newsgroups: comp.lang.ada References: <3fad244e$0$27572$626a54ce@news.free.fr> Subject: Re: Mac address with Win32 bindings. Date: Sun, 9 Nov 2003 09:59:38 +0100 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: <3fae018b$0$27604$626a54ce@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 09 Nov 2003 09:57:47 MET NNTP-Posting-Host: 81.56.190.34 X-Trace: 1068368267 news2-2.free.fr 27604 81.56.190.34:4402 X-Complaints-To: abuse@proxad.net Xref: archiver1.google.com comp.lang.ada:2274 Date: 2003-11-09T09:57:47+01:00 List-Id: ------------- In fact your code is very very close to mine (I was aware about the Microsoft example, and I tried also to translate this ugly language into a beautifully Ada code :-). In the both case your code and mine have a wrong the return code (0 and 35 for mine, 23 and 23 for yours) The result is independent of the compiler (ObectAda7.2.2 /Gnat3.15p) or of the OS (Windos2K/XP). There is definitively something I do not understand in this API!!!!..................... ALEX ------------- "Steve" a �crit dans le message de news:wuirb.150012$Fm2.132677@attbi_s04... > 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. > > > > > >