473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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
Jul 22 '05 #1
8 17706
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
Jul 22 '05 #2
Surendra Singhi <ef*******@netscape.net> 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*'".
Jul 22 '05 #3
JayXie wrote:
Surendra Singhi <ef*******@netscape.net> 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
Jul 22 '05 #4

"Abhijit Bhadra" <ab************@ca.com> wrote in message
news:67**************************@posting.google.c 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

Jul 22 '05 #5
ab************@ca.com (Abhijit Bhadra) wrote in message news:<67**************************@posting.google. 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
br****@osb-systems.com
Open source rating and billing engine for communication networks.
Jul 22 '05 #6
ab************@ca.com (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
Jul 22 '05 #7
da******@pobox.com (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
Jul 22 '05 #8
Thanks Dave .
It worked .

da******@pobox.com (Dave O'Hearn) wrote in message news:<3e**************************@posting.google. com>...
da******@pobox.com (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;

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
6
by: Thomas Barth | last post by:
Hi, I'm new to windows programming and still reading a book about windows-programming with C++. I copied the following code from the book into my ide (Eclipse/CDT) to comprehend the code, but two...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
12
by: Yarco | last post by:
when doing fork in a loop: while(1) { tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len); if (tmp_sd == -1) { perror("accept"); exit(0); } //check client ip
11
by: Martin Jørgensen | last post by:
Hi, I'm using this alloc_mem-function: - - - - - - - - - - - - - - - - - - - - - - - - void *alloc_mem (size_t num_elems, size_t elem_size, char *filename, int line, size_t *total_mem) {
2
by: tkirankumar | last post by:
Hi all, uname -a SunOS cbmrsd1a1 5.10 Generic_118833-17 sun4us sparc FJSV,GPUZC-M g++ -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/specs Configured with:...
3
by: fazulu deen | last post by:
Hi all, For the following code : file_ptr = fopen("pass_fail.txt", "a"); // error line 393 fdisplay(file_ptr, "Test Passed"); fclose(file_ptr);
1
by: Nozdormu | last post by:
Hi guys, I have a quick question. The language I'm using is C. The question I'm tackling: Write a program that (1) defines a 1D array with ten int elements, and (2) sets the values of the...
0
by: shekharban | last post by:
Hi, Below is the raw socket program for sending routing header in ipv6 domain. My source address is fe80::21d:9ff:fe17:58c7 and destination address is fe80::21d:9ff:fe17:5d0e in the below...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.