> -----Original Message-----
> From: win32utils-devel-bounces at rubyforge.org
> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of
> Park Heesob
> Sent: Saturday, June 07, 2008 8:16 PM
> To: Development and ideas for win32utils projects
> Subject: Re: [Win32utils-devel] Unraveling a protoent struct
>
> Hi,
> ----- Original Message -----
> From: "Daniel Berger" <djberg96 at gmail.com>
> To: "Development and ideas for win32utils projects"
> <win32utils-devel at rubyforge.org>
> Sent: Sunday, June 08, 2008 1:24 AM
> Subject: [Win32utils-devel] Unraveling a protoent struct
>
>
> > I''m spacing - how do I unravel a protent struct pointer?
> >
> > require ''win32/api''
> > include Win32
> >
> > getprotobyname = API.new(''getprotobyname'',
''P'', ''P'', ''ws2_32'')
> >
> > ptr = getprotobyname.call(''tcp'')
> >
> > puts "Name: " + # ???
> > puts "Aliases: " + # ???
> > puts "Number: " + # ???
> >
> Here is a little dirty but working code:
>
> require ''win32/api''
> require "windows/msvcrt/buffer"
> require ''windows/msvcrt/string''
> include Win32
> include Windows::MSVCRT::Buffer
> include Windows::MSVCRT::String
>
> protent = "\0" * 12
> name_buf = "\0" * 256
> alias_ptr = "\0" * 256
> getprotobyname = API.new(''getprotobyname'',
''P'', ''L'', ''ws2_32'')
> ptr = getprotobyname.call(''tcp'')
> memcpy(protent,ptr,12)
> strcpy(name_buf,protent[0,4].unpack(''L'').first)
> memcpy(alias_ptr,protent[4,4].unpack(''L'').first,4)
> aliases = []
> alias_ptr.unpack("L*").each do |name|
> break if name==0
> alias_buf = "\0"*256
> strcpy(alias_buf,name)
> aliases << alias_buf.strip
> end
>
> puts "Name: #{name_buf.strip}"
> puts "Aliases: #{aliases}"
> puts "Number:
#{protent[8,4].unpack(''L'').first}"
That works, thanks!
Dan
This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.