The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ecube on August 12, 2010, 07:52:56 PM

Title: define addrinfo
Post by: ecube on August 12, 2010, 07:52:56 PM
I tried defining the addrinfo structure as


addrinfo STRUCT
  ai_flags         dd ?
  ai_family         dd ?
  ai_socktype dd ?
  ai_protocol dd ?
  ai_addrlen         dd ?
  ai_canonname db 1 dup (?)
  ai_addr sockaddr <>
  ai_next dd ?
addrinfo ends


for use with the getaddrinfo function, but it's not working, here's the structure http://msdn.microsoft.com/en-us/library/ms737530%28VS.85%29.aspx, the char * thing is what's throwing me off, because I don't know the size of that.
Title: Re: define addrinfo
Post by: oex on August 12, 2010, 07:55:35 PM
* is a pointer so it is DWORD sized ie ai_addr = a pointer to a sockaddr structure

ai_addr         dd   0

At least I'm pretty sure, that's how I'd read it
Title: Re: define addrinfo
Post by: ecube on August 12, 2010, 08:03:21 PM
Quote from: oex on August 12, 2010, 07:55:35 PM
* is a pointer so it is DWORD sized ie ai_addr = a pointer to a sockaddr structure

ai_addr         dd   0

At least I'm pretty sure, that's how I'd read it

yeah it doesnt matter if I assume it to be a ptr to a sockaddr structure or define it as one, would be used the same, the ai_canonname member is what's causing the issue and defining that as a byte and/or dword isn't workin :\ isn't resolving the hostname correctly.
Title: Re: define addrinfo
Post by: dedndave on August 12, 2010, 08:06:26 PM
it has to be a pointer to a string (null-terminated, i am assuming) that describes the host
Title: Re: define addrinfo
Post by: ecube on August 12, 2010, 08:07:17 PM
Quote from: dedndave on August 12, 2010, 08:06:26 PM
it has to be a pointer to a string (null-terminated, i am assuming) that describes the host

so what should the size be?
Title: Re: define addrinfo
Post by: dedndave on August 12, 2010, 08:10:14 PM
let's take a stab - lol

szHostName db 'localhost',0
.
.
.
ai_addr dd szHostName
Title: Re: define addrinfo
Post by: oex on August 12, 2010, 08:21:35 PM
er at the risk of being wrong :bg.... Does the function not allocate the null terminated string? (and yes it is null terminated I read on some linux man page)

Ah my error.... 1 in 1 out
Title: Re: define addrinfo
Post by: ecube on August 12, 2010, 08:23:31 PM
honestly I think it's the fact it's a sockaddr and not a sockaddr_in structure like I thought it was. I think my original structure was define right now I just gotta figure out how to convert a sockaddr network byte order ip to a string like I did with sockaddr_in
Title: Re: define addrinfo
Post by: dedndave on August 12, 2010, 08:24:27 PM
QuoteThe getaddrinfo function provides protocol-independent translation from an ANSI host name to an address.
Title: Re: define addrinfo
Post by: dedndave on August 12, 2010, 08:27:09 PM
in this example, it is a pointer to a string of length NI_MAXHOST, which would not include the null terminator

http://en.wikipedia.org/wiki/Getaddrinfo#Example


here's another example - he uses an empty string, 100 bytes long

http://www.logix.cz/michal/devel/various/getaddrinfo.c.xp
Title: Re: define addrinfo
Post by: ecube on August 12, 2010, 08:38:29 PM
Thanks Dave  :U
Title: Re: define addrinfo
Post by: ecube on August 12, 2010, 08:53:26 PM
InetNtop vista+ only :(

i'll figure it out though, thanks for the links.
Title: Re: define addrinfo
Post by: ecube on August 12, 2010, 09:53:22 PM
ok I got it


addrinfo STRUCT
  ai_flags     dd ?
  ai_family     dd ?
  ai_socktype dd ?
  ai_protocol dd ?
  ai_addrlen dd ?
  ai_canonname dd ?
  ai_addr dd ?
addrinfo ends


the very last value(ai_next) you figure out by using the ai_addrlen which gives the size of ai_addr. ai_addr points to a sockin_addr for ipv4 and a sockin_addrv6 or whatever for ipv6.

I used the WSAAddressToString function to convert it to a ip since it's on xp+

this is just quick example goasm code, you get the idea
invoke getaddrinfo,,,addr results
mov esi,[results]
mov esi,[esi]

mov ecx,[esi+addrinfo.ai_addrlen]
mov D[addrlenx],ecx

mov D[destinbufflen],255
invoke WSAAddressToString,[esi+addrinfo.ai_addr],[addrlenx],NULL,addr destinbuff,addr destinbufflen


Thanks for the help guys
Title: Re: define addrinfo
Post by: dedndave on August 13, 2010, 03:14:07 AM
 :U