I have a problem with the result of gethostbyname: First I call gethostname: invoke gethostname, ADDR Buffer, 255 then I pass the hostname to gethostbyname: invoke gethostbyname, ADDR Buffer Gethostbyname returns a hostent structure. I use the h_list member of this structure to get all the available IPs of the machine. This results in 2 correct ip addresses (local & internet), and some weird ip address,, that doesn't belong to my computer. I asked someone else to run the program and he got the same results with even more bogus IPs. What's wrong with it? btw the enumeration of the addresses stops when a dword value of 0 is found. Thomas
Posted on 2000-11-28 15:51:00 by Thomas
Have you got your current code somewhere? Im looking for .asm code on how to get the multiple IP's... I can only access the first one and I've been looking for code on how to access the second and onwards ones.... Maybe Ill be able to answer your q once I can get that out of the way... sorry that it aint an answer for you James
Posted on 2000-11-28 16:50:00 by James
Here you go YourProcedure proc LOCAL HostName[256]:BYTE ;Storage for hostname ; --- Get host name --- invoke gethostname, ADDR HostName, 256 ; --- Retrieve hostent structure from hostname --- invoke gethostbyname, ADDR HostName mov ebx, eax ; --- ebx points to a hostent structure --- assume ebx:ptr hostent mov eax, .h_list assume ebx:nothing ; --- eax now holds the offset of the h_list member --- mov ebx, ; --- ebx = pointer to the first entry in 0-term. ip list --- .WHILE TRUE ;scan trough list for all IP's mov eax, .BREAK .IF eax==0 ;stop if null-terminator reached ;===== HERE eax holds the next IP ===== ;do something with it, like: ;invoke inet_ntoa, eax ;to make a string add ebx, 4 ;go to next entry .ENDW ret ;fini YourProcedure endp
Posted on 2000-11-28 17:01:00 by Thomas
assume ebx:ptr hostent = assume ebx ptr hostent
Posted on 2000-11-28 17:03:00 by Thomas
he, he, he.... whenever you put the : with a "p" you get a happy face like this: :p he, he, he :p :p :p :p
Posted on 2000-11-28 23:10:00 by cyberben
This Always confuses me... mov        eax, .h_list ok this copies the offset? isn't an offset like a pointer.. ok. so how is it when I do this. mov        ebx, I get a pointer from an offset. I am confused.. I see this often, but have yet to fully understand it. I know what a pointer is and use it all the time..I would have thought that .h_list would have given me a pointer to that data. I really need to unsderstand whats going on here.. if anyone could explain. still new to asm.
Posted on 2000-11-29 02:39:00 by tudisco
Actually, I got confused by it too and I guess this solved my problem. mov eax, .h_list This copies value from an offset, not the offset (pointer) itself (according to the disassembler this assembles as mov eax,). My problem was that the value of eax points to a null-terminated array of pointers. That's why I put in the: mov ebx, And that's the problem, ebx now holds a pointer to the first IP, not a pointer to an IP list. My comments in the code were false anyway because I didn't noticed this. The hostent structure is defined as: struct hostent { char FAR * h_name; char FAR * FAR * h_aliases; short h_addrtype; short h_length; char FAR * FAR * h_addr_list; }; h_addr_list (or h_list in windows.inc) is a char FAR * FAR *, and I treated it as a char FAR*. I'll try to correct my source code and post the right code. Thomas
Posted on 2000-11-29 13:33:00 by Thomas
It works fine now, here's the code: (it's a procedure to fill a combo box in a dialog with ip's) FillListWithHOSTIPs proc uses ebx hWnd:DWORD, Item:DWORD LOCAL HostName[256]:BYTE ; --- Clear combobox items --- invoke SendDlgItemMessage, hWnd, Item, CB_RESETCONTENT, NULL, NULL ; --- Get hostname --- invoke gethostname, ADDR HostName, 256 ; --- Get hostent from hostname --- invoke gethostbyname, ADDR HostName mov ebx, eax ; --- ebx is now ptr to hostent struct --- assume ebx: ptr hostent mov eax, .h_list assume ebx: nothing mov ebx, eax ; --- ebx is now a pointer to an array of pointers to IP's 8-) --- .WHILE TRUE ; --- get next pointer from array in eax --- mov eax, ; --- break if null terminator --- .BREAK .IF eax==0 ; --- get IP from pointer to IP --- mov eax, ; --- convert to string --- invoke inet_ntoa, eax ; --- add to list --- invoke SendDlgItemMessage, hWnd, Item, CB_ADDSTRING, NULL, eax ; --- next pointer --- add ebx, 4 .ENDW ret FillListWithHOSTIPs endp
Posted on 2000-11-29 13:45:00 by Thomas
Makes much more sense now thomas.. Thanks for the heavily commented example. thanks, :) Jason
Posted on 2000-11-29 21:08:00 by tudisco
Nice work! Geez I didnt even get the chance to help... James BTW Ive used your new code already!
Posted on 2000-11-30 04:22:00 by James
It works ok now but I still wonder why the h_list member is a double pointer. Wouldn't it be easier if it was just an array of IP's? I guess it has to do with the variable lengths of IPs (ie different types of IPs). Thomas
Posted on 2000-11-30 12:49:00 by Thomas