sendto generates SIGSEGV

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

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?

with regards,
Oliver

ssize_t writen( const void * vptr, size_t n, struct sockaddr * to)
{
        size_t          nleft = n;
        ssize_t         nwritten;
        const char      *ptr = static_cast< const char * >( vptr);
        
        struct sigaction new_sa;
        struct sigaction old_sa;
        
        new_sa.sa_handler = SIG_IGN;
        ::sigemptyset( & new_sa.sa_mask);
        new_sa.sa_flags = 0;
        ::sigaction( SIGPIPE, & new_sa, & old_sa);              

        while ( nleft > 0)
        {

                if ( ( nwritten = ::sendto( m_handle, ptr, nleft, 0, to, 
sizeof * to) 

)<=0)
                {
                        if ( errno == EINTR)
                                nwritten = 0;   // and call sendto() again
                        else if ( errno == EPIPE)
                        {
                                ::sigaction( SIGPIPE, & old_sa, 0);

                                return -1;              // write to sock with 
no readers (peer has the sock closed)

                        }
                        else
                        {
                                ::sigaction( SIGPIPE, & old_sa, 0);
                                throw; // error
                        }
                }

                nleft -= nwritten;
                ptr   += nwritten;
        }
        ::sigaction( SIGPIPE, & old_sa, 0);     // set to its previous action

        return n;
}
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux