This is most curious. Bear in mind that I've solved my initial problem with using ASCIIZ pointers into a union'ed structure, but the results are most curious as to WHY this behavior exists.
The function (Winsock is initialized):
No, it's not a function yet, this is just a test to figure things out.
When called with various host names as the hostToIP string, I get the following results:
And it all works, but the results from the third "lookup" is most curious when you access the 4 bytes of the return via a ASCIIZ string pointer, it's returning the 0's and the 1 as -1.
So, is ASC failing here? And if so, how?
P.S. Title of the post was hard to come up with, ... :confused2:
The function (Winsock is initialized):
Code:
SUB GenerateIpPort(hDialog AS DWORD, hostToIP AS STRING) LOCAL Work AS STRING LOCAL sockin AS sockaddr_in LOCAL dwHost AS hostentStru PTR LOCAL connectHost AS ASCIIZ * 256 LOCAL zStr AS ASCIIZ PTR * 5 LOCAL zWord AS DWORD PTR sockin.sin_port = htons(80) connectHost = hostToIp dwHost = GetHostByName(connectHost) IF dwHost = %NULL THEN DisplayMessage hostToIp &" = Unresolved / Bad Host Name" ELSE Work = @[email protected]_name zWord = @dwHost.h_list zStr = @zWord Work = Work &" = "& USING$("#_.#_.#_.#", _ ASC(MID$(@zStr[0],1,1)), ASC(MID$(@zStr[0],2,1)), _ ASC(MID$(@zStr[0],3,1)), ASC(MID$(@zStr[0],4,1))) Work = Work &" / "& HEX$(@dwHost.h_addr, 4) DisplayMessage Work ' this is what i was using first to get at the packed IP ' sockin.sin_addr.s = @zStr[0] sockin.sin_addr.s_addr = @@zWord zStr = inet_ntoa(sockin.sin_addr.s_addr) Work = @zStr Work = Work &" = "& USING$("#_.#_.#_.#", _ sockin.sin_addr.S_un_b.s_b1, sockin.sin_addr.S_un_b.s_b2, _ sockin.sin_addr.S_un_b.s_b3, sockin.sin_addr.S_un_b.s_b4) _ &" / "& HEX$(sockin.sin_addr.s_addr, 8) DisplayMessage Work END IF END SUB
When called with various host names as the hostToIP string, I get the following results:
Code:
' should return the proper IP address. GenerateIpPort CB.HNDL, "yahoo.com" ' yahoo.com = 69.147.114.224 / 0002 ' 69.147.114.224 = 69.147.114.224 / E0729345 ' why yes it does. ' should generate a failure to resolve. GenerateIpPort CB.HNDL, "bad.yahoo.com" ' bad.yahoo.com = Unresolved / Bad Host Name ' yep. ' this is blocked via my HOSTS file. GenerateIpPort CB.HNDL, "www.incredimail.com" ' www.incredimail.com = 127.-1.-1.-1 / 0002 ' 127.0.0.1 = 127.0.0.1 / 0100007F ' ok, the ASC is not returning character codes below 32?
So, is ASC failing here? And if so, how?
P.S. Title of the post was hard to come up with, ... :confused2:
Comment