Hi,

 

I tried with some different logic in the else part to get the dump of the
error returned by Bio_do_connect() API, but no luck. File is getting created
but nothing is getting written over there.

else

          {

             FILE * pFile1; 

             char mystring [500];

             pFile1 = fopen ("result.txt","a"); 

             if (pFile1!=NULL)

             {

                ERR_print_errors_fp(stderr);

                if ( fgets (mystring , 500 , stderr) != NULL )

                {

                       fputs (mystring, pFile);

                }

                fclose(pFile1);

             }

             cout << " The Bio_do_connect failed" << endl;

             break;

          }

 

And also tried this one, but no luck.

else

          {

             FILE * pFile1; 

             char mystring [500];

             pFile1 = fopen ("result.txt","a"); 

             if (pFile1!=NULL)

             {

                ERR_print_errors_fp(stderr);

                fgets (mystring , 500 , stderr);

                fputs (mystring, pFile);

                fclose(pFile1);

             }

             cout << " The Bio_do_connect failed" << endl;

             break;

          }

 

Could you please have a look and help me here. I am not able to proceed
further.

 

Thanks

Akanksha Shukla.

 

From: owner-openssl-us...@openssl.org
[mailto:owner-openssl-us...@openssl.org] On Behalf Of Akanksha Shukla
Sent: Saturday, October 29, 2011 11:47 PM
To: openssl-users@openssl.org
Subject: RE: Open SSL API's Support For IPv6.

 

Hi Michael,

 

Sorry for the confusion caused but the whole code sequence is like this:

 

int retryCounter = 0;

while(retryCounter < CONNECT_MAX_TRY)

{

     int retVal = BIO_do_connect(conn);

     if(retVal <= 0)

     {

          if(BIO_should_retry(conn))

          {

               retryCounter++;

               sleep(CONNECT_SLEEP_INTERVAL);

               FILE * pFile;

               pFile = fopen ("result_retry.txt","a");

               if (pFile!=NULL)

               {

                   ERR_print_errors_fp(pFile);

                   fclose(pFile);

               }

               continue;

          }

          else

          {

             FILE * pFile1; 

             pFile1 = fopen ("result.txt","a"); 

             if (pFile1!=NULL)

             {

                ERR_print_errors_fp(pFile1);

                fclose(pFile1);

             }

             cout << " The Bio_do_connect failed" << endl;

             break;

          }

      }

      else

      {

         cout << " The Bio_do_connect passes" << endl;

         break;

      }

}

 

The retry counter is meant for Bio_should_retry() API and it should try for
10 times as the value of CONNECT_MAX_TRY is set to 10. But in this case, the
Bio_should_retry() API is passed, hence value of retry counter is not
incremented and control goes to the else part where I am trying to print the
error in file. The break statement is else part will cause the control to
move out of the while loop and hence the Bio_do_connect failed gets printed
for one time only.

 

But problem is that in the file "result.txt", nothing is getting dumped as I
explained you in the earlier mails also. But when I use fputs, I can see
output in the file. So, please suggest here what mistake I am making in
writing the error to the file.

 

Any help would be really appreciable here as I am getting struck in IPv4
only case, while I wanted to have such logic which could have serve my
purpose for both IPv4 as well as IPV6.

 

Thanks

Akanksha Shukla.

 

-----Original Message-----
From: owner-openssl-us...@openssl.org
[mailto:owner-openssl-us...@openssl.org] On Behalf Of Michael S. Zick
Sent: Wednesday, October 26, 2011 2:26 AM
To: openssl-users@openssl.org
Subject: Re: Open SSL API's Support For IPv6.

 

On Tue October 25 2011, Akanksha Shukla wrote:

> Hi Stephen,

> 

>  

> 

> I added debug code as:

> 

>  

> 

> int retryCounter = 0;

> 

> while(retryCounter < CONNECT_MAX_TRY)

> 

> {

> 

>     int retVal = BIO_do_connect(conn);

> 

>     if(retVal <= 0)

> 

>     {

> 

>          if(BIO_should_retry(conn))

> 

>          {

> 

>               retryCounter++;

> 

>               sleep(CONNECT_SLEEP_INTERVAL);

> 

>               FILE * pFile;

> 

>               pFile = fopen ("result_retry.txt","a");

> 

>               if (pFile!=NULL)

> 

>               {

> 

>                    ERR_print_errors_fp(pFile);

> 

>               }

> 

>               continue;

> 

>         }

> 

>         else

> 

>         {

> 

>             

> 

>       FILE * pFile1;

> 

>                 pFile1 = fopen ("result.txt","a");

> 

>                 if (pFile1!=NULL)

> 

>                 {

> 

>                     ERR_print_errors_fp(pFile1);

> 

>                  }

> 

>                 cout << " The Bio_do_connect failed" << endl;

> 

>  

> 

>         }

> 

>    }

> 

> }

> 

>  

> 

> After execution of program, I saw that only "result.txt" file is getting

> created and not the "result_retry.txt" file which clarifies that the retry

> logic is working fine. Problem comes when retry counter reaches its max

> value and Bio_do_connect() gets failed. Though my understanding might be

> wrong here. 

> 

>  

> 

> But the main problem which I encountered today is that nothing is being

> written in the file "result.txt" and I am also hoping that I am using the

> ERR_print_errors_fp() function in correct way. The file is blank. Then
just

> to make sure that pFile1 handle returned as Not NULL and we are entering

> inside the if check, I added statement

> 

> If(pfile1! = NULL)

> 

> {

> 

>      fputs ("fopen example",pFile);

> 

>      //ERR_print_errors_fp(pFile1);

> 

> }

> 

>  

> 

> And this time, I could see that "fopen example" is being written to

> result.txt file successfully.

> 

>  

> 

> So, could you please suggest what mistake I am doing here that SSL errors

> are not being getting written in file and also any other suggestions to
try

> out.  

> 

 

Q? How many times do you intend to open that file inside of the

while loop without ever flushing or closing it?

 

Mike 

>  

> 

> Thanks

> 

> Akanksha Shukla.

> 

>  

> 

> -----Original Message-----

> From: owner-openssl-us...@openssl.org

> [mailto:owner-openssl-us...@openssl.org] On Behalf Of Dr. Stephen Henson

> Sent: Tuesday, October 25, 2011 4:34 AM

> To: openssl-users@openssl.org

> Subject: Re: Open SSL API's Support For IPv6.

> 

>  

> 

> On Sun, Oct 23, 2011, Akanksha Shukla wrote:

> 

>  

> 

> > Hi Stephen,

> 

> > 

> 

> >  

> 

> > 

> 

> > I tried with retry logic as well (though earlier it was also same), but

> same

> 

> > result.

> 

> > 

> 

> >  

> 

> > 

> 

> > int retryCounter = 0;

> 

> > 

> 

> > while(retryCounter < CONNECT_MAX_TRY)

> 

> > 

> 

> > {

> 

> > 

> 

> >     int retVal = BIO_do_connect(conn);

> 

> > 

> 

> >     if(retVal <= 0)

> 

> > 

> 

> >     {

> 

> > 

> 

> >          if(BIO_should_retry(conn))

> 

> > 

> 

> >          {

> 

> > 

> 

> >               retryCounter++;

> 

> > 

> 

> >               sleep(CONNECT_SLEEP_INTERVAL);

> 

> > 

> 

> >               continue;

> 

> > 

> 

> >         }

> 

> > 

> 

> >         else

> 

> > 

> 

> >         {

> 

> > 

> 

> >             cout << " The Bio_do_connect failed" << endl;

> 

> > 

> 

> >  

> 

> > 

> 

> >         }

> 

> > 

> 

> >    }

> 

> > 

> 

> > }

> 

> > 

> 

> >  

> 

> > 

> 

> > Just wanted to let you know that this piece of code is same at time when
I

> 

> > used BIO_new_connect() followed by BIO_set_nbio() and Bio_do_connect()

> with

> 

> > similar code mentioned above, then things were working fine. This time

> 

> > rather than using Bio_new_connect(), I used socket(), connect() and

> 

> > Bio_new_socket() API call followed by bio_set_nbio() and
Bio_do_connect()

> 

> > (as suggested by you), then things started failing.

> 

> > 

> 

> >  

> 

> > 

> 

> > Please let me know if you have any suggestions or help me in pointing
out

> 

> > the issue.

> 

> > 

> 

> >  

> 

>  

> 

> Try adding some more debugging code to see if it actually does retry and

> also

> 

> if it fails call the OpenSSL ERR library to print out any useful message.

> For

> 

> example ERR_print_errors_fp(stderr);

> 

>  

> 

> Steve.

> 

> --

> 

> Dr Stephen N. Henson. OpenSSL project core developer.

> 

> Commercial tech support now available see: http://www.openssl.org

> 

> ______________________________________________________________________

> 

> OpenSSL Project                                 http://www.openssl.org

> 

> User Support Mailing List                    openssl-users@openssl.org

> 

> Automated List Manager                           majord...@openssl.org

> 

> 

 

 

______________________________________________________________________

OpenSSL Project                                 http://www.openssl.org

User Support Mailing List                    openssl-users@openssl.org

Automated List Manager                           majord...@openssl.org

Reply via email to