On Jan 26, 2009, at 5:24 PM, Daniel Mentz wrote:

I'm surprised that you can use accept() on UDP sockets. I checked the man pages of a Debian GNU/Linux system. They say that you can use accept() only with connection-based socket types (SOCK_STREAM, SOCK_SEQPACKET). Is this something specific to FreeBSD? Could you please provide me with more information. Maybe you could make your source code available.

Hi Daniel,
sorry for causing confusion, of course you can't use accept() with UDP. You have to create a new socket, use bind() to assign it to a specific connection and create another socket. Everything else is like handling TCP connections. Unfortunately it was too long ago that I have written the code so I hadn't had all of it in mind anymore. Probably you can use connected UDP sockets with Linux, but I'm not sure. I'm working with FreeBSD and Mac OS X which support them.

Sample UDP server code:

while (1) {
        memset((void *) &client_addr, 0, sizeof(client_addr));
                
        accfd = (int*) malloc (sizeof(int));
        *accfd = socket(AF_INET, SOCK_DGRAM, 0);
        setsockopt (*accfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
bind(*accfd, (const struct sockaddr *) &server_addr, sizeof(server_addr));

        bio = BIO_new_dgram(*accfd, BIO_NOCLOSE);
        ssl = SSL_new(ctx);

        SSL_set_bio(ssl, bio, bio);
        SSL_accept(ssl);
                
        info = (struct pass_info*) malloc (sizeof(struct pass_info));
        info->fd = *accfd;
        info->client_addr = client_addr;
        info->ssl = ssl;
                
        rc = pthread_create( &tid, NULL, connection_handle, info);
        if (rc != 0) {
                perror("pthread_create");
                exit(1);
        }
}


Regards,
Robin
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to