PDA

Click to See Complete Forum and Search --> : WSock32.DLL API


ExciteMouse
Jul 14th, 2000, 05:31 PM
Hello.
I am having a problem with this API instruction:

Private Declare Function inet_ntoa Lib "wsock32.dll" (ByVal inn As Long) As Long

(this function is used to convert a unsigned long ip address to a string i.e. 24.34.25.23)

As you can see the varible passed to the wsock32.dll is declared as LONG.

I have a legit IP address: 3582069972

this number, however, is not LONG... it is double.

when i try to pass this number to the above function i get overflow errors.

How can i pass this large number to the 'inet_ntoa' without getting overflow errors?

thanks =)

ExciteMouse
Jul 14th, 2000, 10:23 PM
ok i figured it out (fianally)
if you have a double number... what i suggest doing is converting that number to hex.


3582069972 = 0xd5820cd4

then for every hex value get the ascii value

d5 = 213
82 = 130
0c = 12
d4 = 212

then just place a period between each returned number:
213.103.12.212

once again. the windows API lets me down =(

Stevie-O
Jul 17th, 2000, 08:19 AM
erm...of course the Windows API did let you down.
You broke the API contract.

This is the proper declaration for the inet_ntoa function:

char FAR * inet_ntoa(struct in_addr in);

This is what you have:

Private Declare Function inet_ntoa Lib "wsock32.dll" (ByVal inn As Long) As Long

a 'Long' is NOT a 'struct in_addr'.

'struct in_addr' is:

struct in_addr {
union {
struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
struct { u_short s_w1,s_w2; } S_un_w;
u_long S_addr;
} S_un;
};

Notice that S_addr is an UNSIGNED Long. Try it; 3582069972 is a perfectly valid unsigned 32-bit value. You're using a signed 32-bit data type, which CAN'T hold that value.

ExciteMouse
Jul 17th, 2000, 04:41 PM
ok .. not the windows API but visual basic and their damn varible declorations =)

you cant specify between SIGNED and UNSIGNED with vb
im sure there is someway, but why not make it an option.

i.e.
dim INN as ULONG

oh well