我有个大问题!我需要你的帮助!请帮帮我!
我在因特网上找到了一个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
谢谢你,朋友,你想帮我!
发布于 2011-05-29 07:38:25
很难确切地说出你的问题是什么,但是有几个想法可能会帮助你搜索。
设置消息和信息回调,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。
https://stackoverflow.com/questions/5776819
复制相似问题