C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 12-07-2007, 06:49 AM   #1
WDT
Tha 1 Sick RAT
 
Join Date: Dec 2003
Posts: 267
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
WDT is offline   Reply With Quote
Old 12-07-2007, 07:45 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 12-07-2007, 08:07 AM   #3
WDT
Tha 1 Sick RAT
 
Join Date: Dec 2003
Posts: 267
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
WDT is offline   Reply With Quote
Old 12-07-2007, 08:19 AM   #4
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,336
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
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 12-07-2007, 02:46 PM   #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)
Cactus_Hugger is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 09:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22