Thread: My broken inet_aton()

  1. #1
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271

    My broken inet_aton()

    This is my inet_aton:
    Code:
    // inet_aton for windows
    int inet_aton(const char *address, struct in_addr *sock){
        
        int s;
        s = inet_addr(address);
        if ( s == 1 && strcmp (address, "255.255.255.225") )
        return 0;
        sock->s_addr = s;
        
        return 1;
    }
    This is how I'm trying to use it:
    Code:
    inet_aton(s_address.c_str(), &cSock.sin_addr);
    but I keep getting this error: 41 C:\Dev-Cpp\... invalid conversion from `const char*' to `char*' , but I don't fully understand where I'm going wrong here. I do know that cont strings are unmodifiable unless you remove their "const-ness" with a casting operator (which I don't want to get in to) so I tried getting around this problem by copying the string to a temporary buffer to no avail. any light shed will be appreciated. even if it's something obvious I'm over looking atm.
    Thanks
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It's not clear which is "line 41" in the code you posted.

    According to what I can see, all the functions involved take a const char *, so we need to understand which line it is that is causing the problem.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    Code:
     inet_aton(s_address.c_str(), &cSock.sin_addr);
    is line 41
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    are you sure your inet_aton function declared in every place the same way accepting const char* as a first parameter. Seems like it is declared somewhere in the header in another way
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by WDT View Post
    This is my inet_aton:
    Code:
    // inet_aton for windows
    int inet_aton(const char *address, struct in_addr *sock){
        
        int s;
        s = inet_addr(address);
        if ( s == 1 && strcmp (address, "255.255.255.225") )
        return 0;
        sock->s_addr = s;
        
        return 1;
    }
    What are the lines in red supposed to do?
    1 is a valid return value from inet_addr - the only special case you should be checking for is if inet_addr returns INADDR_NONE.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. This CD Drive is broken?
    By alphaoide in forum Tech Board
    Replies: 3
    Last Post: 06-04-2005, 02:59 PM
  2. Is this a valid use of C++, or have I completely broken some major rules?
    By Lithorien in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 12-14-2004, 05:43 PM
  3. undeclared identifier problem
    By jjj93421 in forum C++ Programming
    Replies: 13
    Last Post: 04-24-2004, 09:22 AM
  4. broken pipe
    By samps005 in forum Linux Programming
    Replies: 1
    Last Post: 05-07-2003, 09:04 PM
  5. Resume a broken download
    By Echidna in forum Windows Programming
    Replies: 2
    Last Post: 01-06-2003, 09:44 AM