Re: sendto generates SIGSEGV

From: Glynn Clements (glynn.clements@virgin.net)
Date: Sun Jul 29 2001 - 17:07:53 EST


Oliver Kowalke wrote:

> I've written an c++ class which wrappes a socket.. With function writen()
> you can write to an TCP and UDP socket ( TCP : pointer to stuct sockaddr ==
> NULL; UDP : pointer to struct sockaddr != NULL). If I use this function
> with TCP sockets all works. If I call this function for an UDP socket it
> generates an SIGSEGV signal.
> What is wrong?

Some comments:

1. The last parameter to sendto() should be the size of the
protocol-specific socket address, e.g. "sizeof struct sockaddr_in" for
an IPv4 address.

2. This code won't handle a non-blocking socket correctly.

3. There isn't much point in implementing a writen() function for UDP
sockets; packet boundaries are significant for UDP.

As to why it's raising SIGSEGV, maybe it's due to the arguments being
passed in. Certainly, invalid values for ptr or n will cause a
segfault. Try using a debugger.

-- 
Glynn Clements <glynn.clements@virgin.net>
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org



This archive was generated by hypermail 2b29 : Tue Jul 31 2001 - 21:01:01 EST