2011-04-25 101 views
0

我有一個很大的問題!我需要你的幫助!請幫幫我!OpenSSL DTLSv1_listen:服務器無法從客戶端獲得消息

我找到了一個在因特網上實現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(); 

我創建客戶端和it've發信息給服務器。通過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

謝謝,朋友爲你嘗試幫助我!

回答

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

相關問題