Results 1 to 4 of 4

Thread: WSock32.DLL API

  1. #1

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Question

    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 =)



  2. #2

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Talking

    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 =(

  3. #3
    Lively Member
    Join Date
    Apr 2000
    Location
    Hell
    Posts
    89
    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.
    - Steve

    Real programmers use COPY CON PROGRAM.EXE

  4. #4

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Wink

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width