OpenSSL DTLSv1_listen:服务器无法从客户端获取消息

时间:2011-04-25 08:59:18

标签: udp openssl listen

我有一个很大的问题!我需要你的帮助!请帮帮我!

我在Internet上找到了DTLS实现的示例,它被称为dtls_udp_echo.c。 我在功能中有以下代码描述服务器的行为:

    memset(&client_addr, 0, sizeof(struct sockaddr_storage));


    /* Create BIO */

    bio = BIO_new_dgram(fd, BIO_NOCLOSE);


    /* Set and activate timeouts */

    timeout.tv_sec = 5;

    timeout.tv_usec = 0;

    BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);


    ssl = SSL_new(ctx);

    cout << "ssl is" << ssl ;

    printf("ssl is \n");

    SSL_set_bio(ssl, bio, bio);

    SSL_set_options(ssl, SSL_OP_COOKIE_EXCHANGE);


    while (DTLSv1_listen(ssl, &client_addr) <= 0){

        //printf("%d\n",DTLSv1_listen(ssl, &client_addr));

    }

    info = (struct pass_info*) malloc (sizeof(struct pass_info));

    memcpy(&info->server_addr, &server_addr, sizeof(struct sockaddr_storage));

    memcpy(&info->client_addr, &client_addr, sizeof(struct sockaddr_storage));

    info->ssl = ssl;

    if (pthread_create( &tid, NULL, connection_handle, info) != 0) {

        perror("pthread_create");

        exit(-1);

    }

}

THREAD_cleanup();

我已经创建了客户端,它已经向服务器发送了一条消息。使用TCPDUMP我可以看到该数据包

60. 250026 IP (tos 0x0, ttl 64, id 59389, offset 0, flags [DF], proto UDP (17), length 104) 127.0.0.1.8001 > 127.0.0.1.8000: UDP, length 76

其中:

127.0.0.1 port 8001 - client
127.0.0.1 port 8000 - server 

但服务器似乎是盲目的,并没有向客户端发回信号。 我相信地址是正确的,因为当我在实验期间更改它们时,客户端无法向服务器发送握手并且出现错误:

SSL_connect: Connection refused
error:00000000:lib(0):func(0):reason(0)

我的openSSL版本是1.0.0d

谢谢,朋友,你试着帮助我!

1 个答案:

答案 0 :(得分:0)

很难确切地说出你的问题是什么,但有几个想法可能会帮助你搜索。

设置消息和信息回调,info_cb和msg_cb是您必须提供的功能:

SSL_set_info_callback(ssl, info_cb);
SSL_set_msg_callback(ssl, msg_cb);

DTLSv1_listen是否会返回?在那种情况下,它会返回什么?

您也可以致电

SSL_state_string_long(ssl)

返回ssl当前状态的描述。

如果您使用的是Windows,则您引用的示例不起作用,因为Windows不处理绑定到示例所预期的相同地址和端口的多个UDP套接字。要解决此问题,请参阅http://www.net-snmp.org/wiki/index.php/DTLS_Implementation_Notes