This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Help required


I need to write some application using SSL. For that I have a code 
which first opens a socket and does something..something but even 
in this simple program its giving me errors like this
pro1.cpp:31: implicit declaration of function `int 
CHK_NULL(...)'
pro1.cpp:33: implicit declaration of function `int CHK_SSL(...)'
pro1.cpp:38: implicit declaration of function `int CHK_ERR(...)'
pro1.cpp:96: implicit declaration of function `int close(...)

what does this mean????
Hereis the code pro1.cpp

#include <stdio.h>
#include <memory.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
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, 
"socket");

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

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

   /* ----------------------------------------------- */
   /* 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 ("SSL connection using %s\n", 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 ("Server certificate:\n");

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

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

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

   /* Clean up. */

   close (sd);
   SSL_free (ssl);
   SSL_CTX_free (ctx);
}







_________________________________________________________
Click below to visit monsterindia.com and review jobs in India or 
Abroad
http://monsterindia.rediff.com/jobs


---------------------------
Shalendra Chhabra
Laboratoire Specification et Verification,
Ecole Normale Superieure De Cachan,
Pavillon Des Jardins,
Chambre n 215,
61 Avenue Du President Wilson,
Cachan Cedex
France
ph office (from 10 to 5 )
01-47-40-24-87


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]