News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

define addrinfo

Started by ecube, August 12, 2010, 07:52:56 PM

Previous topic - Next topic

ecube

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.

oex

* 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
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

ecube

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.

dedndave

it has to be a pointer to a string (null-terminated, i am assuming) that describes the host

ecube

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?

dedndave

let's take a stab - lol

szHostName db 'localhost',0
.
.
.
ai_addr dd szHostName

oex

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
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

ecube

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

dedndave

QuoteThe getaddrinfo function provides protocol-independent translation from an ANSI host name to an address.

dedndave

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

ecube


ecube

InetNtop vista+ only :(

i'll figure it out though, thanks for the links.

ecube

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

dedndave