Chinaunix

标题: 请教一个Openssl的问题,着急。。。。 [打印本页]

作者: Hecate_Eos    时间: 2010-09-09 20:10
标题: 请教一个Openssl的问题,着急。。。。
下面的是服务器端的监听程序:
GError* error = NULL;
  int sock,s;
  BIO *sbio, *bbio, *acpt;
  SSL_CTX *ctx;
  SSL *ssl;

  /* Build our SSL context*/
  ctx=initialize_ctx("./cert/servercert.pem",
                "./cert/serverkey.pem",PASSWORD);
  // load_dh_params(ctx,DHFILE);

     sbio = BIO_new_ssl (ctx,0);
     BIO_get_ssl(sbio, &ssl);
     if (!ssl)
     {
           g_printerr("Can't locate SSL pointer\n");
           return -1;
     }
      /* Don't want any retries */
     SSL_set_mode (ssl, SSL_MODE_AUTO_RETRY);
     /* Create the buffering BIO */
     bbio = BIO_new (BIO_f_buffer ());
     /* Add to chain */
     sbio = BIO_push (bbio, sbio);
     gchar* port = g_strdup_printf ("%d", listen_port);
     acpt=BIO_new_accept (port);
     g_free (port);
     
     /* By doing this when a new connection is established
     * we automatically have sbio inserted into it. The
     * BIO chain is now 'swallowed' by the accept BIO and
     * will be freed when the accept BIO is freed.
     */
     BIO_set_accept_bios (acpt,sbio);
//      BIO_set_accept_port(acpt, "*:54999");
     /* Setup accept BIO */
     if (BIO_do_accept (acpt) <= 0)
     {
           fprintf(stderr, "Error setting up accept BIO\n");
           ERR_print_errors_fp(stderr);
           return -1;
     }
     
     while (1)
     {
           /* Now wait for incoming connection */
           if (BIO_do_accept (acpt) <= 0)
           {
                 fprintf(stderr, "Error in connection\n");
                 ERR_print_errors_fp(stderr);
                 return -1;
           }
           BIO * c_sbio = BIO_pop (acpt); /* c_sbio may be is the childe of sbio ??*/
           if( !g_thread_create((GThreadFunc)minp_response, c_sbio, FALSE, &error) )
           {
                 g_printerr("协议分析线程\n");
           }      
  }
  BIO_free_all (acpt);
  SSL_CTX_free (ctx);
  g_thread_exit(0);
这上面是用BIO改后的程序,原来用的是SSL。客户端能连原来的,但是改后就不能连了。“拒绝连接”。
我想问题可能是上面服务器端的问题。我用 netstat -tlp ,查看到,服务器端正在监听端口,本地地址是"localhost:4999",请各位大侠帮忙看看,有什么问题
[此贴被hecate_eos在2010-09-9 3:50 PM重新编辑]




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2