Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > invalid conversion from `int*' to `socklen_t*'

Reply
Thread Tools

invalid conversion from `int*' to `socklen_t*'

 
 
Abhijit Bhadra
Guest
Posts: n/a
 
      11-29-2004
Hi ,
I am using gcc version 3.3.2. While compiling this code
struct sockaddr_in *CBaseSocket::GetSocketName()
{
socklen_t iLen;
cCriticalSocket.Lock();
// Do we have a socket?
if (sSocket == INVALID_SOCKET)
{
cCriticalSocket.Unlock();
return(NULL);
};
cCriticalSocket.Unlock();

iLen = sizeof(struct sockaddr_in);
if (!::getsockname(sSocket, (struct sockaddr *) &sTAddr, &iLen))
return(&sTAddr);

return(NULL);
};

I am getting this error while compiling :

"invalid conversion from `int*' to `socklen_t*'"

Can anyone help me to get rid of this error message ?

Thanks,
Abhijit
 
Reply With Quote
 
 
 
 
Surendra Singhi
Guest
Posts: n/a
 
      11-29-2004
Abhijit Bhadra wrote:

> Hi ,
> I am using gcc version 3.3.2. While compiling this code
> struct sockaddr_in *CBaseSocket::GetSocketName()
> {
> socklen_t iLen;
> cCriticalSocket.Lock();
> // Do we have a socket?
> if (sSocket == INVALID_SOCKET)
> {
> cCriticalSocket.Unlock();
> return(NULL);
> };
> cCriticalSocket.Unlock();
>
> iLen = sizeof(struct sockaddr_in);
> if (!::getsockname(sSocket, (struct sockaddr *) &sTAddr, &iLen))
> return(&sTAddr);
>
> return(NULL);
> };
>
> I am getting this error while compiling :
>
> "invalid conversion from `int*' to `socklen_t*'"
>
> Can anyone help me to get rid of this error message ?
>
> Thanks,
> Abhijit


I feel the error is in your &ilen parameter. You should probably type
cast it. Look into man getsockname and its parameters. You should use
the proper variable type which in this case is socklen_t.
And also please give the line number or better point to the line with
the likely cause of error when you are posting code with errors in it.

--
Surendra Singhi

www.public.asu.edu/~sksinghi
 
Reply With Quote
 
 
 
 
JayXie
Guest
Posts: n/a
 
      11-29-2004
Surendra Singhi <(E-Mail Removed)> writes:

> I feel the error is in your &ilen parameter. You should probably type
> cast it. Look into man getsockname and its parameters. You should use
> the proper variable type which in this case is socklen_t.
> And also please give the line number or better point to the line with
> the likely cause of error when you are posting code with errors in it.


But if the error is in the &iLen parameter, the error message should be
"invalid conversion form 'socklen_t *' to 'int *'" not "invalid
conversion from `int*' to `socklen_t*'".
 
Reply With Quote
 
Surendra Singhi
Guest
Posts: n/a
 
      11-29-2004
JayXie wrote:

> Surendra Singhi <(E-Mail Removed)> writes:
>
>
>>I feel the error is in your &ilen parameter. You should probably type
>>cast it. Look into man getsockname and its parameters. You should use
>>the proper variable type which in this case is socklen_t.
>>And also please give the line number or better point to the line with
>>the likely cause of error when you are posting code with errors in it.

>
>
> But if the error is in the &iLen parameter, the error message should be
> "invalid conversion form 'socklen_t *' to 'int *'" not "invalid
> conversion from `int*' to `socklen_t*'".


My mistake, I got confused by the OP's using prefix "i" i.e., iLen, I
thought he was passing address of an integer..

--
Surendra Singhi

www.public.asu.edu/~sksinghi
 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      11-29-2004

"Abhijit Bhadra" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi ,
> I am using gcc version 3.3.2. While compiling this code
> struct sockaddr_in *CBaseSocket::GetSocketName()
> {
> socklen_t iLen;
> cCriticalSocket.Lock();
> // Do we have a socket?
> if (sSocket == INVALID_SOCKET)
> {
> cCriticalSocket.Unlock();
> return(NULL);
> };
> cCriticalSocket.Unlock();
>
> iLen = sizeof(struct sockaddr_in);
> if (!::getsockname(sSocket, (struct sockaddr *) &sTAddr, &iLen))
> return(&sTAddr);
>
> return(NULL);
> };
>
> I am getting this error while compiling :
>
> "invalid conversion from `int*' to `socklen_t*'"
>
> Can anyone help me to get rid of this error message ?
>
> Thanks,
> Abhijit


You shouldn't need it, but you might try casting &iLen as (socklen_t*), just
to see if it works.

(Are you getting any other errors? For example, are you getting an error
that "socklen_t" is not defined? That might also cause this error. Just
guessing, though.)

One other note: there's no reason for all those "struct" specifiers
scattered in your code. That looks like some old C code, not C++. Remove
them. The struct specifier is only needed for the original declaration of
the object, not when referring to objects of that type (or pointers to such
objects). So wherever you have "struct sockaddr", replace it with just
"sockaddr".

-Howard



 
Reply With Quote
 
Stephan Br?nnimann
Guest
Posts: n/a
 
      11-30-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Abhijit Bhadra) wrote in message news:<(E-Mail Removed). com>...
> Hi ,
> I am using gcc version 3.3.2. While compiling this code
> struct sockaddr_in *CBaseSocket::GetSocketName()
> {
> socklen_t iLen;
> cCriticalSocket.Lock();
> // Do we have a socket?
> if (sSocket == INVALID_SOCKET)
> {
> cCriticalSocket.Unlock();
> return(NULL);
> };
> cCriticalSocket.Unlock();
>
> iLen = sizeof(struct sockaddr_in);
> if (!::getsockname(sSocket, (struct sockaddr *) &sTAddr, &iLen))
> return(&sTAddr);
>
> return(NULL);
> };
>
> I am getting this error while compiling :
>
> "invalid conversion from `int*' to `socklen_t*'"
>
> Can anyone help me to get rid of this error message ?
>
> Thanks,
> Abhijit



Once you've `sockaddr_in' defined it should work:

try.cc
======

#include <sys/socket.h>
#include <netdb.h>

sockaddr_in* GetSocketName()
{
static struct sockaddr_in sTAddr;

int sSocket;
socklen_t iLen;
iLen = sizeof(struct sockaddr_in);

if (!::getsockname(sSocket, (struct sockaddr *) &sTAddr, &iLen)) {
return(&sTAddr);
}

return 0;
};

Compiles without any error:
g++-3.3 -g -Wall -c -o try.o try.cc

regards,
Stephan Brönnimann
(E-Mail Removed)
Open source rating and billing engine for communication networks.
 
Reply With Quote
 
Dave O'Hearn
Guest
Posts: n/a
 
      11-30-2004
(E-Mail Removed) (Abhijit Bhadra) wrote:
> struct sockaddr_in *CBaseSocket::GetSocketName()
> {
> socklen_t iLen;
> cCriticalSocket.Lock();
>
> if (sSocket == INVALID_SOCKET)
> {
> cCriticalSocket.Unlock();
> return(NULL);
> };
> cCriticalSocket.Unlock();
>
> iLen = sizeof(struct sockaddr_in);
> if (!::getsockname(sSocket, (struct sockaddr *) &sTAddr, &iLen))
> return(&sTAddr);
>
> return(NULL);
> };


You shouldn't need that semi-colon on the end.

What platform is this being written for? WinSock has no socklen_t, and
POSIX has no INVALID_SOCKET. It looks like the code was ported from
WinSock to POSIX, and still contains artifacts of WinSock.

My guess is, somewhere your code has this line,

#define socklet_t int

This is causing your 'iLen' variable to actually be an int, instead of
socklen_t. First, change it to a typedef. If it was a typedef, the
compiler would have given you a much more accurate error message.
Then, either delete it, or conditionally do it only on Windows.

HTH.

--
Dave O'Hearn
 
Reply With Quote
 
Dave O'Hearn
Guest
Posts: n/a
 
      12-01-2004
(E-Mail Removed) (Dave O'Hearn) wrote:
> #define socklet_t int


That was a typo. It should say,

#define socklen_t int

Again, it would've been much better as,

typedef int socklen_t;

--
Dave O'Hearn
 
Reply With Quote
 
Abhijit Bhadra
Guest
Posts: n/a
 
      12-01-2004
Thanks Dave .
It worked .

(E-Mail Removed) (Dave O'Hearn) wrote in message news:<(E-Mail Removed). com>...
> (E-Mail Removed) (Dave O'Hearn) wrote:
> > #define socklet_t int

>
> That was a typo. It should say,
>
> #define socklen_t int
>
> Again, it would've been much better as,
>
> typedef int socklen_t;

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid character in base-64 string and invalid postback or callba kevin ASP .Net 0 01-16-2008 09:39 PM
How do fix: "Wrong number of arguments" / "invalid propert assignment"/ "Invalid argument" Java Guy Javascript 1 10-15-2006 08:41 PM
How do fix: "Wrong number of arguments" / "invalid propert assignment"/ "Invalid argument" Java Guy Java 1 10-15-2006 08:31 PM
Invalid URI: There is an invalid sequence in the string. Error!! Patrick.O.Ige ASP .Net 1 07-02-2006 11:21 AM
invalid@invalid.org Hank Sniadoch Computer Information 1 08-20-2004 11:24 AM



Advertisments