<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[code, soll kompatibel gemacht werden...]]></title><description><![CDATA[<p>hey leute ich hab da erst mal bissal code...das prog is für unix, was muss ich da bei winsock usw ändern damit das auch dann unter windows läuft???<br />
cu</p>
<pre><code>/* serv.cpp  -  Minimal ssleay server for Unix

/* mangled to work with SSLeay-0.9.0b and OpenSSL 0.9.2b
   Simplified to be even more minimal*/

#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;memory.h&gt;
#include &lt;errno.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;netdb.h&gt;

#include &lt;openssl/rsa.h&gt;       /* SSLeay stuff */
#include &lt;openssl/crypto.h&gt;
#include &lt;openssl/x509.h&gt;
#include &lt;openssl/pem.h&gt;
#include &lt;openssl/ssl.h&gt;
#include &lt;openssl/err.h&gt;

/* define HOME to be dir for key and cert files... */
#define HOME &quot;./&quot;
/* Make these what you want for cert &amp; key files */
#define CERTF  HOME &quot;foo-cert.pem&quot;
#define KEYF  HOME  &quot;foo-cert.pem&quot;

#define CHK_NULL(x) if ((x)==NULL) exit (1)
#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); }

void main ()
{
  int err;
  int listen_sd;
  int sd;
  struct sockaddr_in sa_serv;
  struct sockaddr_in sa_cli;
  size_t client_len;
  SSL_CTX* ctx;
  SSL*     ssl;
  X509*    client_cert;
  char*    str;
  char     buf [4096];
  SSL_METHOD *meth;

  /* SSL preliminaries. We keep the certificate and key with the context. */

  SSL_load_error_strings();
  SSLeay_add_ssl_algorithms();
  meth = SSLv23_server_method();
  ctx = SSL_CTX_new (meth);
  if (!ctx) {
    ERR_print_errors_fp(stderr);
    exit(2);
  }

  if (SSL_CTX_use_certificate_file(ctx, CERTF, SSL_FILETYPE_PEM) &lt;= 0) {
    ERR_print_errors_fp(stderr);
    exit(3);
  }
  if (SSL_CTX_use_PrivateKey_file(ctx, KEYF, SSL_FILETYPE_PEM) &lt;= 0) {
    ERR_print_errors_fp(stderr);
    exit(4);
  }

  if (!SSL_CTX_check_private_key(ctx)) {
    fprintf(stderr,&quot;Private key does not match the certificate public key\n&quot;);
    exit(5);
  }

  /* ----------------------------------------------- */
  /* Prepare TCP socket for receiving connections */

  listen_sd = socket (AF_INET, SOCK_STREAM, 0);   CHK_ERR(listen_sd, &quot;socket&quot;);

  memset (&amp;sa_serv, '\0', sizeof(sa_serv));
  sa_serv.sin_family      = AF_INET;
  sa_serv.sin_addr.s_addr = INADDR_ANY;
  sa_serv.sin_port        = htons (1111);          /* Server Port number */

  err = bind(listen_sd, (struct sockaddr*) &amp;sa_serv,
	     sizeof (sa_serv));                   CHK_ERR(err, &quot;bind&quot;);

  /* Receive a TCP connection. */

  err = listen (listen_sd, 5);                    CHK_ERR(err, &quot;listen&quot;);

  client_len = sizeof(sa_cli);
  sd = accept (listen_sd, (struct sockaddr*) &amp;sa_cli, &amp;client_len);
  CHK_ERR(sd, &quot;accept&quot;);
  close (listen_sd);

  printf (&quot;Connection from %lx, port %x\n&quot;,
	  sa_cli.sin_addr.s_addr, sa_cli.sin_port);

  /* ----------------------------------------------- */
  /* TCP connection is ready. Do server side SSL. */

  ssl = SSL_new (ctx);                           CHK_NULL(ssl);
  SSL_set_fd (ssl, sd);
  err = SSL_accept (ssl);                        CHK_SSL(err);

  /* Get the cipher - opt */

  printf (&quot;SSL connection using %s\n&quot;, SSL_get_cipher (ssl));

  /* Get client's certificate (note: beware of dynamic allocation) - opt */

  client_cert = SSL_get_peer_certificate (ssl);
  if (client_cert != NULL) {
    printf (&quot;Client certificate:\n&quot;);

    str = X509_NAME_oneline (X509_get_subject_name (client_cert), 0, 0);
    CHK_NULL(str);
    printf (&quot;\t subject: %s\n&quot;, str);
    OPENSSL_free (str);

    str = X509_NAME_oneline (X509_get_issuer_name  (client_cert), 0, 0);
    CHK_NULL(str);
    printf (&quot;\t issuer: %s\n&quot;, str);
    OPENSSL_free (str);

    /* We could do all sorts of certificate verification stuff here before
       deallocating the certificate. */

    X509_free (client_cert);
  } else
    printf (&quot;Client does not have certificate.\n&quot;);

  /* DATA EXCHANGE - Receive message and send reply. */

  err = SSL_read (ssl, buf, sizeof(buf) - 1);                   CHK_SSL(err);
  buf[err] = '\0';
  printf (&quot;Got %d chars:'%s'\n&quot;, err, buf);

  err = SSL_write (ssl, &quot;I hear you.&quot;, strlen(&quot;I hear you.&quot;));  CHK_SSL(err);

  /* Clean up. */

  close (sd);
  SSL_free (ssl);
  SSL_CTX_free (ctx);
}
/* EOF - serv.cpp */

/* inetdserv.cpp  -  Minimal ssleay server for Unix inetd.conf
 * From /etc/inetd.conf:
 *     1111 stream tcp nowait sampo /usr/users/sampo/demo/inetdserv inetdserv
 */

#include &lt;stdio.h&gt;
#include &lt;errno.h&gt;

#include &quot;rsa.h&quot;       /* SSLeay stuff */
#include &lt;openssl/crypto.h&gt;
#include &lt;openssl/x509.h&gt;
#include &lt;openssl/pem.h&gt;
#include &lt;openssl/ssl.h&gt;
#include &lt;openssl/err.h&gt;

#define HOME &quot;/usr/users/sampo/demo/&quot;
#define CERTF HOME &quot;plain-cert.pem&quot;
#define KEYF  HOME &quot;plain-key.pem&quot;

#define CHK_NULL(x) if ((x)==NULL) exit (1)
#define CHK_ERR(err,s) if ((err)==-1) \
                         { fprintf(log, &quot;%s %d\n&quot;, (s), errno); exit(1); }
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(log); exit(2); }

void main ()
{
  int err;
  SSL_CTX* ctx;
  SSL*     ssl;
  X509*    client_cert;
  char*    str;
  char     buf [4096];
  FILE* log;

  log = fopen (&quot;/dev/console&quot;, &quot;a&quot;);                     CHK_NULL(log);
  fprintf (log, &quot;inetdserv %ld\n&quot;, (long)getpid());

  SSL_load_error_strings();
  ctx = SSL_CTX_new (); CHK_NULL(ctx);

  err = SSL_CTX_use_RSAPrivateKey_file (ctx, KEYF,  SSL_FILETYPE_PEM);
  CHK_SSL (err);

  err = SSL_CTX_use_certificate_file   (ctx, CERTF, SSL_FILETYPE_PEM);
  CHK_SSL (err);

  /* inetd has already opened the TCP connection, so we can get right
     down to business. */

  ssl = SSL_new (ctx);  CHK_NULL(ssl);
  SSL_set_fd (ssl,  fileno(stdin));
  err = SSL_accept (ssl);                                CHK_SSL(err);

  /* Get the cipher - opt */

  fprintf (log, &quot;SSL connection using %s\n&quot;, SSL_get_cipher (ssl));

  /* Get client's certificate (note: beware of dynamic allocation) - opt */

  client_cert = SSL_get_peer_certificate (ssl);
  if (client_cert != NULL) {
    fprintf (log, &quot;Client certificate:\n&quot;);

    str = X509_NAME_oneline (X509_get_subject_name (client_cert));
    CHK_NULL(str);
    fprintf (log, &quot;\t subject: %s\n&quot;, str);
    OPENSSL_free (str);

    str = X509_NAME_oneline (X509_get_issuer_name  (client_cert));
    CHK_NULL(str);
    fprintf (log, &quot;\t issuer: %s\n&quot;, str);
    OPENSSL_free (str);

    /* We could do all sorts of certificate verification stuff here before
       deallocating the certificate. */

    X509_free (client_cert);
  } else
    fprintf (log, &quot;Client doe not have certificate.\n&quot;);

  /* ------------------------------------------------- */
  /* DATA EXCHANGE: Receive message and send reply  */

  err = SSL_read (ssl, buf, sizeof(buf) - 1);  CHK_SSL(err);
  buf[err] = '\0';
  fprintf (log, &quot;Got %d chars:'%s'\n&quot;, err, buf);

  err = SSL_write (ssl, &quot;Loud and clear.&quot;, strlen(&quot;Loud and clear.&quot;));
  CHK_SSL(err);

  /* Clean up. */

  fclose (log);
  SSL_free (ssl);
  SSL_CTX_free (ctx);
}
/* EOF - inetdserv.cpp */

/* cli.cpp  -  Minimal ssleay client for Unix */

/* mangled to work with SSLeay-0.9.0b and OpenSSL 0.9.2b
   Simplified to be even more minimal*/

#include &lt;stdio.h&gt;
#include &lt;memory.h&gt;
#include &lt;errno.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;netdb.h&gt;

#include &lt;openssl/crypto.h&gt;
#include &lt;openssl/x509.h&gt;
#include &lt;openssl/pem.h&gt;
#include &lt;openssl/ssl.h&gt;
#include &lt;openssl/err.h&gt;

#define CHK_NULL(x) if ((x)==NULL) exit (1)
#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); }

void main ()
{
  int err;
  int sd;
  struct sockaddr_in sa;
  SSL_CTX* ctx;
  SSL*     ssl;
  X509*    server_cert;
  char*    str;
  char     buf [4096];
  SSL_METHOD *meth;

  SSLeay_add_ssl_algorithms();
  meth = SSLv2_client_method();
  SSL_load_error_strings();
  ctx = SSL_CTX_new (meth);                        CHK_NULL(ctx);

  CHK_SSL(err);

  /* ----------------------------------------------- */
  /* Create a socket and connect to server using normal socket calls. */

  sd = socket (AF_INET, SOCK_STREAM, 0);       CHK_ERR(sd, &quot;socket&quot;);

  memset (&amp;sa, '\0', sizeof(sa));
  sa.sin_family      = AF_INET;
  sa.sin_addr.s_addr = inet_addr (&quot;127.0.0.1&quot;);   /* Server IP */
  sa.sin_port        = htons     (1111);          /* Server Port number */

  err = connect(sd, (struct sockaddr*) &amp;sa,
		sizeof(sa));                   CHK_ERR(err, &quot;connect&quot;);

  /* ----------------------------------------------- */
  /* Now we have TCP conncetion. Start SSL negotiation. */

  ssl = SSL_new (ctx);                         CHK_NULL(ssl);    
  SSL_set_fd (ssl, sd);
  err = SSL_connect (ssl);                     CHK_SSL(err);

  /* Following two steps are optional and not required for
     data exchange to be successful. */

  /* Get the cipher - opt */

  printf (&quot;SSL connection using %s\n&quot;, SSL_get_cipher (ssl));

  /* Get server's certificate (note: beware of dynamic allocation) - opt */

  server_cert = SSL_get_peer_certificate (ssl);       CHK_NULL(server_cert);
  printf (&quot;Server certificate:\n&quot;);

  str = X509_NAME_oneline (X509_get_subject_name (server_cert),0,0);
  CHK_NULL(str);
  printf (&quot;\t subject: %s\n&quot;, str);
  OPENSSL_free (str);

  str = X509_NAME_oneline (X509_get_issuer_name  (server_cert),0,0);
  CHK_NULL(str);
  printf (&quot;\t issuer: %s\n&quot;, str);
  OPENSSL_free (str);

  /* We could do all sorts of certificate verification stuff here before
     deallocating the certificate. */

  X509_free (server_cert);

  /* --------------------------------------------------- */
  /* DATA EXCHANGE - Send a message and receive a reply. */

  err = SSL_write (ssl, &quot;Hello World!&quot;, strlen(&quot;Hello World!&quot;));  CHK_SSL(err);

  err = SSL_read (ssl, buf, sizeof(buf) - 1);                     CHK_SSL(err);
  buf[err] = '\0';
  printf (&quot;Got %d chars:'%s'\n&quot;, err, buf);
  SSL_shutdown (ssl);  /* send SSL/TLS close_notify */

  /* Clean up. */

  close (sd);
  SSL_free (ssl);
  SSL_CTX_free (ctx);
}
/* EOF - cli.cpp */
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/80287/code-soll-kompatibel-gemacht-werden</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 04:37:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/80287.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Jul 2004 19:39:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Mon, 19 Jul 2004 19:39:35 GMT]]></title><description><![CDATA[<p>hey leute ich hab da erst mal bissal code...das prog is für unix, was muss ich da bei winsock usw ändern damit das auch dann unter windows läuft???<br />
cu</p>
<pre><code>/* serv.cpp  -  Minimal ssleay server for Unix

/* mangled to work with SSLeay-0.9.0b and OpenSSL 0.9.2b
   Simplified to be even more minimal*/

#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;memory.h&gt;
#include &lt;errno.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;netdb.h&gt;

#include &lt;openssl/rsa.h&gt;       /* SSLeay stuff */
#include &lt;openssl/crypto.h&gt;
#include &lt;openssl/x509.h&gt;
#include &lt;openssl/pem.h&gt;
#include &lt;openssl/ssl.h&gt;
#include &lt;openssl/err.h&gt;

/* define HOME to be dir for key and cert files... */
#define HOME &quot;./&quot;
/* Make these what you want for cert &amp; key files */
#define CERTF  HOME &quot;foo-cert.pem&quot;
#define KEYF  HOME  &quot;foo-cert.pem&quot;

#define CHK_NULL(x) if ((x)==NULL) exit (1)
#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); }

void main ()
{
  int err;
  int listen_sd;
  int sd;
  struct sockaddr_in sa_serv;
  struct sockaddr_in sa_cli;
  size_t client_len;
  SSL_CTX* ctx;
  SSL*     ssl;
  X509*    client_cert;
  char*    str;
  char     buf [4096];
  SSL_METHOD *meth;

  /* SSL preliminaries. We keep the certificate and key with the context. */

  SSL_load_error_strings();
  SSLeay_add_ssl_algorithms();
  meth = SSLv23_server_method();
  ctx = SSL_CTX_new (meth);
  if (!ctx) {
    ERR_print_errors_fp(stderr);
    exit(2);
  }

  if (SSL_CTX_use_certificate_file(ctx, CERTF, SSL_FILETYPE_PEM) &lt;= 0) {
    ERR_print_errors_fp(stderr);
    exit(3);
  }
  if (SSL_CTX_use_PrivateKey_file(ctx, KEYF, SSL_FILETYPE_PEM) &lt;= 0) {
    ERR_print_errors_fp(stderr);
    exit(4);
  }

  if (!SSL_CTX_check_private_key(ctx)) {
    fprintf(stderr,&quot;Private key does not match the certificate public key\n&quot;);
    exit(5);
  }

  /* ----------------------------------------------- */
  /* Prepare TCP socket for receiving connections */

  listen_sd = socket (AF_INET, SOCK_STREAM, 0);   CHK_ERR(listen_sd, &quot;socket&quot;);

  memset (&amp;sa_serv, '\0', sizeof(sa_serv));
  sa_serv.sin_family      = AF_INET;
  sa_serv.sin_addr.s_addr = INADDR_ANY;
  sa_serv.sin_port        = htons (1111);          /* Server Port number */

  err = bind(listen_sd, (struct sockaddr*) &amp;sa_serv,
	     sizeof (sa_serv));                   CHK_ERR(err, &quot;bind&quot;);

  /* Receive a TCP connection. */

  err = listen (listen_sd, 5);                    CHK_ERR(err, &quot;listen&quot;);

  client_len = sizeof(sa_cli);
  sd = accept (listen_sd, (struct sockaddr*) &amp;sa_cli, &amp;client_len);
  CHK_ERR(sd, &quot;accept&quot;);
  close (listen_sd);

  printf (&quot;Connection from %lx, port %x\n&quot;,
	  sa_cli.sin_addr.s_addr, sa_cli.sin_port);

  /* ----------------------------------------------- */
  /* TCP connection is ready. Do server side SSL. */

  ssl = SSL_new (ctx);                           CHK_NULL(ssl);
  SSL_set_fd (ssl, sd);
  err = SSL_accept (ssl);                        CHK_SSL(err);

  /* Get the cipher - opt */

  printf (&quot;SSL connection using %s\n&quot;, SSL_get_cipher (ssl));

  /* Get client's certificate (note: beware of dynamic allocation) - opt */

  client_cert = SSL_get_peer_certificate (ssl);
  if (client_cert != NULL) {
    printf (&quot;Client certificate:\n&quot;);

    str = X509_NAME_oneline (X509_get_subject_name (client_cert), 0, 0);
    CHK_NULL(str);
    printf (&quot;\t subject: %s\n&quot;, str);
    OPENSSL_free (str);

    str = X509_NAME_oneline (X509_get_issuer_name  (client_cert), 0, 0);
    CHK_NULL(str);
    printf (&quot;\t issuer: %s\n&quot;, str);
    OPENSSL_free (str);

    /* We could do all sorts of certificate verification stuff here before
       deallocating the certificate. */

    X509_free (client_cert);
  } else
    printf (&quot;Client does not have certificate.\n&quot;);

  /* DATA EXCHANGE - Receive message and send reply. */

  err = SSL_read (ssl, buf, sizeof(buf) - 1);                   CHK_SSL(err);
  buf[err] = '\0';
  printf (&quot;Got %d chars:'%s'\n&quot;, err, buf);

  err = SSL_write (ssl, &quot;I hear you.&quot;, strlen(&quot;I hear you.&quot;));  CHK_SSL(err);

  /* Clean up. */

  close (sd);
  SSL_free (ssl);
  SSL_CTX_free (ctx);
}
/* EOF - serv.cpp */

/* inetdserv.cpp  -  Minimal ssleay server for Unix inetd.conf
 * From /etc/inetd.conf:
 *     1111 stream tcp nowait sampo /usr/users/sampo/demo/inetdserv inetdserv
 */

#include &lt;stdio.h&gt;
#include &lt;errno.h&gt;

#include &quot;rsa.h&quot;       /* SSLeay stuff */
#include &lt;openssl/crypto.h&gt;
#include &lt;openssl/x509.h&gt;
#include &lt;openssl/pem.h&gt;
#include &lt;openssl/ssl.h&gt;
#include &lt;openssl/err.h&gt;

#define HOME &quot;/usr/users/sampo/demo/&quot;
#define CERTF HOME &quot;plain-cert.pem&quot;
#define KEYF  HOME &quot;plain-key.pem&quot;

#define CHK_NULL(x) if ((x)==NULL) exit (1)
#define CHK_ERR(err,s) if ((err)==-1) \
                         { fprintf(log, &quot;%s %d\n&quot;, (s), errno); exit(1); }
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(log); exit(2); }

void main ()
{
  int err;
  SSL_CTX* ctx;
  SSL*     ssl;
  X509*    client_cert;
  char*    str;
  char     buf [4096];
  FILE* log;

  log = fopen (&quot;/dev/console&quot;, &quot;a&quot;);                     CHK_NULL(log);
  fprintf (log, &quot;inetdserv %ld\n&quot;, (long)getpid());

  SSL_load_error_strings();
  ctx = SSL_CTX_new (); CHK_NULL(ctx);

  err = SSL_CTX_use_RSAPrivateKey_file (ctx, KEYF,  SSL_FILETYPE_PEM);
  CHK_SSL (err);

  err = SSL_CTX_use_certificate_file   (ctx, CERTF, SSL_FILETYPE_PEM);
  CHK_SSL (err);

  /* inetd has already opened the TCP connection, so we can get right
     down to business. */

  ssl = SSL_new (ctx);  CHK_NULL(ssl);
  SSL_set_fd (ssl,  fileno(stdin));
  err = SSL_accept (ssl);                                CHK_SSL(err);

  /* Get the cipher - opt */

  fprintf (log, &quot;SSL connection using %s\n&quot;, SSL_get_cipher (ssl));

  /* Get client's certificate (note: beware of dynamic allocation) - opt */

  client_cert = SSL_get_peer_certificate (ssl);
  if (client_cert != NULL) {
    fprintf (log, &quot;Client certificate:\n&quot;);

    str = X509_NAME_oneline (X509_get_subject_name (client_cert));
    CHK_NULL(str);
    fprintf (log, &quot;\t subject: %s\n&quot;, str);
    OPENSSL_free (str);

    str = X509_NAME_oneline (X509_get_issuer_name  (client_cert));
    CHK_NULL(str);
    fprintf (log, &quot;\t issuer: %s\n&quot;, str);
    OPENSSL_free (str);

    /* We could do all sorts of certificate verification stuff here before
       deallocating the certificate. */

    X509_free (client_cert);
  } else
    fprintf (log, &quot;Client doe not have certificate.\n&quot;);

  /* ------------------------------------------------- */
  /* DATA EXCHANGE: Receive message and send reply  */

  err = SSL_read (ssl, buf, sizeof(buf) - 1);  CHK_SSL(err);
  buf[err] = '\0';
  fprintf (log, &quot;Got %d chars:'%s'\n&quot;, err, buf);

  err = SSL_write (ssl, &quot;Loud and clear.&quot;, strlen(&quot;Loud and clear.&quot;));
  CHK_SSL(err);

  /* Clean up. */

  fclose (log);
  SSL_free (ssl);
  SSL_CTX_free (ctx);
}
/* EOF - inetdserv.cpp */

/* cli.cpp  -  Minimal ssleay client for Unix */

/* mangled to work with SSLeay-0.9.0b and OpenSSL 0.9.2b
   Simplified to be even more minimal*/

#include &lt;stdio.h&gt;
#include &lt;memory.h&gt;
#include &lt;errno.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;netdb.h&gt;

#include &lt;openssl/crypto.h&gt;
#include &lt;openssl/x509.h&gt;
#include &lt;openssl/pem.h&gt;
#include &lt;openssl/ssl.h&gt;
#include &lt;openssl/err.h&gt;

#define CHK_NULL(x) if ((x)==NULL) exit (1)
#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); }

void main ()
{
  int err;
  int sd;
  struct sockaddr_in sa;
  SSL_CTX* ctx;
  SSL*     ssl;
  X509*    server_cert;
  char*    str;
  char     buf [4096];
  SSL_METHOD *meth;

  SSLeay_add_ssl_algorithms();
  meth = SSLv2_client_method();
  SSL_load_error_strings();
  ctx = SSL_CTX_new (meth);                        CHK_NULL(ctx);

  CHK_SSL(err);

  /* ----------------------------------------------- */
  /* Create a socket and connect to server using normal socket calls. */

  sd = socket (AF_INET, SOCK_STREAM, 0);       CHK_ERR(sd, &quot;socket&quot;);

  memset (&amp;sa, '\0', sizeof(sa));
  sa.sin_family      = AF_INET;
  sa.sin_addr.s_addr = inet_addr (&quot;127.0.0.1&quot;);   /* Server IP */
  sa.sin_port        = htons     (1111);          /* Server Port number */

  err = connect(sd, (struct sockaddr*) &amp;sa,
		sizeof(sa));                   CHK_ERR(err, &quot;connect&quot;);

  /* ----------------------------------------------- */
  /* Now we have TCP conncetion. Start SSL negotiation. */

  ssl = SSL_new (ctx);                         CHK_NULL(ssl);    
  SSL_set_fd (ssl, sd);
  err = SSL_connect (ssl);                     CHK_SSL(err);

  /* Following two steps are optional and not required for
     data exchange to be successful. */

  /* Get the cipher - opt */

  printf (&quot;SSL connection using %s\n&quot;, SSL_get_cipher (ssl));

  /* Get server's certificate (note: beware of dynamic allocation) - opt */

  server_cert = SSL_get_peer_certificate (ssl);       CHK_NULL(server_cert);
  printf (&quot;Server certificate:\n&quot;);

  str = X509_NAME_oneline (X509_get_subject_name (server_cert),0,0);
  CHK_NULL(str);
  printf (&quot;\t subject: %s\n&quot;, str);
  OPENSSL_free (str);

  str = X509_NAME_oneline (X509_get_issuer_name  (server_cert),0,0);
  CHK_NULL(str);
  printf (&quot;\t issuer: %s\n&quot;, str);
  OPENSSL_free (str);

  /* We could do all sorts of certificate verification stuff here before
     deallocating the certificate. */

  X509_free (server_cert);

  /* --------------------------------------------------- */
  /* DATA EXCHANGE - Send a message and receive a reply. */

  err = SSL_write (ssl, &quot;Hello World!&quot;, strlen(&quot;Hello World!&quot;));  CHK_SSL(err);

  err = SSL_read (ssl, buf, sizeof(buf) - 1);                     CHK_SSL(err);
  buf[err] = '\0';
  printf (&quot;Got %d chars:'%s'\n&quot;, err, buf);
  SSL_shutdown (ssl);  /* send SSL/TLS close_notify */

  /* Clean up. */

  close (sd);
  SSL_free (ssl);
  SSL_CTX_free (ctx);
}
/* EOF - cli.cpp */
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/564021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564021</guid><dc:creator><![CDATA[surf]]></dc:creator><pubDate>Mon, 19 Jul 2004 19:39:35 GMT</pubDate></item><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Mon, 19 Jul 2004 23:15:30 GMT]]></title><description><![CDATA[<p>Hier wird dir keiner eine fertige Lösung präsentieren. So wie es aussieht hast du den &quot;Unix-Code&quot; nicht selbst geschrieben.<br />
Wenn du nicht bereit bist, jemanden mit einer Portierung zu beauftragen (das kostet Geld), musst du den steinigen Weg gehen und den Code selbst verstehen.</p>
<p>Wenn dabei konkrete Probleme auftreten, wird dir gerne geholfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564110</guid><dc:creator><![CDATA[Christoph]]></dc:creator><pubDate>Mon, 19 Jul 2004 23:15:30 GMT</pubDate></item><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Tue, 20 Jul 2004 06:25:36 GMT]]></title><description><![CDATA[<p>cd9000 schrieb:</p>
<blockquote>
<p>Hier wird dir keiner eine fertige Lösung präsentieren. So wie es aussieht hast du den &quot;Unix-Code&quot; nicht selbst geschrieben.<br />
Wenn du nicht bereit bist, jemanden mit einer Portierung zu beauftragen (das kostet Geld), musst du den steinigen Weg gehen und den Code selbst verstehen.</p>
<p>Wenn dabei konkrete Probleme auftreten, wird dir gerne geholfen.</p>
</blockquote>
<p>das ist ein sample von openssl! ich will ja nur wissen bei welche befehlen bei winsock für linux anders sind als für windows? zb brauch man in linux den socket nicht initialisieren... verstehst?</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564145</guid><dc:creator><![CDATA[surf]]></dc:creator><pubDate>Tue, 20 Jul 2004 06:25:36 GMT</pubDate></item><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Tue, 20 Jul 2004 07:50:24 GMT]]></title><description><![CDATA[<p>moin meister ...</p>
<p>immer noch nicht weiter ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /> ich auch nicht ...</p>
<p>Zu Deinem Problem:</p>
<p>winsock.h einbinden</p>
<p>-WSAStartup<br />
-WSACleanup</p>
<p>#define HOME &quot;./&quot; ersetzen</p>
<p>ERR_print_errors_fp(stderr); sollte funktionieren wenn Du die Quelldatei mit der Funktion dem Projekt hinzufügst ( aus openSSL )<br />
listen_sd und sd sind vom Typ SOCKET.</p>
<p>close(socket) durch closesocket(socket) ersetzen.</p>
<p>der Rest aus srv.cpp sollte eigentlich übernommen werden können</p>
<p>Ich würde erstmal das SSL Zeugs vergessen und nen stino Server basteln der dann mal lauscht, danach Stück für Stück den SSL Kram übernehmen.</p>
<p>mfg<br />
RB</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564191</guid><dc:creator><![CDATA[RED-BARON]]></dc:creator><pubDate>Tue, 20 Jul 2004 07:50:24 GMT</pubDate></item><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Tue, 20 Jul 2004 09:14:33 GMT]]></title><description><![CDATA[<p>RED-BARON schrieb:</p>
<blockquote>
<p>moin meister ...</p>
<p>immer noch nicht weiter ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /> ich auch nicht ...</p>
<p>Zu Deinem Problem:</p>
<p>winsock.h einbinden</p>
<p>-WSAStartup<br />
-WSACleanup</p>
<p>#define HOME &quot;./&quot; ersetzen</p>
<p>ERR_print_errors_fp(stderr); sollte funktionieren wenn Du die Quelldatei mit der Funktion dem Projekt hinzufügst ( aus openSSL )<br />
listen_sd und sd sind vom Typ SOCKET.</p>
<p>close(socket) durch closesocket(socket) ersetzen.</p>
<p>der Rest aus srv.cpp sollte eigentlich übernommen werden können</p>
<p>Ich würde erstmal das SSL Zeugs vergessen und nen stino Server basteln der dann mal lauscht, danach Stück für Stück den SSL Kram übernehmen.</p>
<p>mfg<br />
RB</p>
</blockquote>
<p>danke erst mal...machst du auch was mit SSL? was ist ein stino Server?</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564268</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564268</guid><dc:creator><![CDATA[surf.]]></dc:creator><pubDate>Tue, 20 Jul 2004 09:14:33 GMT</pubDate></item><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Tue, 20 Jul 2004 09:23:53 GMT]]></title><description><![CDATA[<p>moin meister ...</p>
<p>jo habe ich versucht mit verschlüsselten eMails<br />
RFC 1421-1424<br />
.</p>
<p>Ein &quot;stino Server&quot; ist ein &quot;stink normaler Server&quot; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>also Socket erstellen binden hören und wenn ein Client kommt<br />
akzeptieren.</p>
<p>so wie hier:<br />
listen_sd = socket (AF_INET, SOCK_STREAM, 0); CHK_ERR(listen_sd, &quot;socket&quot;);</p>
<p>memset (&amp;sa_serv, '\0', sizeof(sa_serv));<br />
sa_serv.sin_family = AF_INET;<br />
sa_serv.sin_addr.s_addr = INADDR_ANY;<br />
sa_serv.sin_port = htons (1111); /* Server Port number */</p>
<p>err = bind(listen_sd, (struct sockaddr*) &amp;sa_serv,<br />
sizeof (sa_serv)); CHK_ERR(err, &quot;bind&quot;);</p>
<p>/* Receive a TCP connection. */</p>
<p>err = listen (listen_sd, 5); CHK_ERR(err, &quot;listen&quot;);</p>
<p>client_len = sizeof(sa_cli);<br />
sd = accept (listen_sd, (struct sockaddr*) &amp;sa_cli, &amp;client_len);<br />
CHK_ERR(sd, &quot;accept&quot;);<br />
close (listen_sd);</p>
<p>fertig.</p>
<p>Das wird erstmal nach windows portiert, was wohl keim Probleme bereiten sollte.<br />
siehe <a href="http://c-worker.ch" rel="nofollow">c-worker.ch</a></p>
<p>MfG<br />
RB</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564273</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564273</guid><dc:creator><![CDATA[RED-BARON]]></dc:creator><pubDate>Tue, 20 Jul 2004 09:23:53 GMT</pubDate></item><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Tue, 20 Jul 2004 09:30:07 GMT]]></title><description><![CDATA[<p>hi 2ter meinster;-)<br />
wie weit bist du mittn SSL verschlüsseln, funzt schon was?<br />
was ist mit dem gemeint:</p>
<pre><code class="language-cpp">err = SSL_write (ssl, &quot;I hear you.&quot;, strlen(&quot;I hear you.&quot;));  CHK_SSL(err);
</code></pre>
<p>ersetzt SSL_write das send, schon oder?<br />
cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564275</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564275</guid><dc:creator><![CDATA[surf.]]></dc:creator><pubDate>Tue, 20 Jul 2004 09:30:07 GMT</pubDate></item><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Tue, 20 Jul 2004 09:43:51 GMT]]></title><description><![CDATA[<p>moin meister ...</p>
<p>Du hast es, ich glaub es nicht ...<br />
SSL_Read steht dann für was ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>Erstmal hat der Server nix mit SSL zu tun, nach dem ein Client<br />
ankommt gibt accept einen Socket zurück und der Server hört auf zu hören.</p>
<p>Dieser neue Socket wird der SSL-Lib übergeben und ab da an wird nur noch<br />
mit den SSL-Funktionen gearbeitet. Bis auf close (sd); was ja noch ersetzt werden muß.</p>
<p>MfG<br />
RB</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564283</guid><dc:creator><![CDATA[RED-BARON]]></dc:creator><pubDate>Tue, 20 Jul 2004 09:43:51 GMT</pubDate></item><item><title><![CDATA[Reply to code, soll kompatibel gemacht werden... on Tue, 20 Jul 2004 10:19:42 GMT]]></title><description><![CDATA[<p>RED-BARON schrieb:</p>
<blockquote>
<p>moin meister ...</p>
<p>Du hast es, ich glaub es nicht ...<br />
SSL_Read steht dann für was ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>Erstmal hat der Server nix mit SSL zu tun, nach dem ein Client<br />
ankommt gibt accept einen Socket zurück und der Server hört auf zu hören.</p>
<p>Dieser neue Socket wird der SSL-Lib übergeben und ab da an wird nur noch<br />
mit den SSL-Funktionen gearbeitet. Bis auf close (sd); was ja noch ersetzt werden muß.</p>
<p>MfG<br />
RB</p>
</blockquote>
<p>ja dann is ja SSL_Read fürs emfangen? so wie recv?</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564312</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564312</guid><dc:creator><![CDATA[surf]]></dc:creator><pubDate>Tue, 20 Jul 2004 10:19:42 GMT</pubDate></item></channel></rss>