Help me I want to convert ip address to decimal number

I want to convert ip address to decimal number and reconvert it.

Examples : If i get 203.107.160.32 ---> 3412828192. but if i get 3412828159 ---> 203.107.144.0

Thank you

Comments

  • [b][red]This message was edited by stober at 2002-9-23 5:29:31[/red][/b][hr]
    : I want to convert ip address to decimal number and reconvert it.
    :
    : Examples : If i get 203.107.160.32 ---> 3412828192. but if i get 3412828159 ---> 203.107.144.0
    :
    : Thank you
    :

    If you are trying to do socket stuff:
    char *host = "203.107.160.32";
    SOCKADDR_IN addr;
    addr.sin_family = AF_INET;
    addr.sin_port = port;
    addr.sin_addr.s_addr = inet_addr(host);



  • : [b][red]This message was edited by stober at 2002-9-23 5:29:31[/red][/b][hr]
    : : I want to convert ip address to decimal number and reconvert it.
    : :
    : : Examples : If i get 203.107.160.32 ---> 3412828192. but if i get 3412828159 ---> 203.107.144.0
    : :
    : : Thank you
    : :
    :
    : If you are trying to do socket stuff:
    : char *host = "203.107.160.32";
    : SOCKADDR_IN addr;
    : addr.sin_family = AF_INET;
    : addr.sin_port = port;
    : addr.sin_addr.s_addr = inet_addr(host);
    :
    :
    :
    :

    This may look awful but it works :)

    DWORD dwIPAddr = 0;
    CHAR szIPAddr[16] = { 0 };

    // Dottet IP to number
    dwIPAddr = inet_addr("192.168.1.1");

    // Back to dottet form
    strcpy (szIPAddr, inet_ntoa(*((struct in_addr *)&dwIPAddr)));
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories