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.
* 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
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.
it has to be a pointer to a string (null-terminated, i am assuming) that describes the host
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?
let's take a stab - lol
szHostName db 'localhost',0
.
.
.
ai_addr dd szHostName
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
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
QuoteThe getaddrinfo function provides protocol-independent translation from an ANSI host name to an address.
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
Thanks Dave :U
InetNtop vista+ only :(
i'll figure it out though, thanks for the links.
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
:U