Code goes into a loop - Openssl

This is a discussion on Code goes into a loop - Openssl ; This code just goes into a loop and keeps writing the first piece of info it reads. What am I doing wrong here? while (nread = BIO_gets(out, buf, sizeof(buf) ) ) { err = BIO_write(out,buf,nread ); } -- Brian Lavender ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Code goes into a loop

  1. Code goes into a loop

    This code just goes into a loop and keeps writing the first piece
    of info it reads. What am I doing wrong here?

    while (nread = BIO_gets(out, buf, sizeof(buf) ) )
    {
    err = BIO_write(out,buf,nread );
    }


    --
    Brian Lavender
    http://www.brie.com/brian/
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  2. Re: Code goes into a loop

    Have a closer look at the condition in the while loop and pay
    particular attention to the operator that you have used. It should be
    very obvious what you are doing wrong.

    On Jun 11, 11:54 am, br...@brie.com (Brian Lavender) wrote:
    > This code just goes into a loop and keeps writing the first piece
    > of info it reads. What am I doing wrong here?
    >
    > while (nread = BIO_gets(out, buf, sizeof(buf) ) )
    > {
    > err = BIO_write(out,buf,nread );
    >
    > }
    >
    > --
    > Brian Lavenderhttp://www.brie.com/brian/
    > __________________________________________________ ____________________
    > OpenSSL Project http://www.openssl.org
    > User Support Mailing List openssl-us...@openssl.org
    > Automated List Manager majord...@openssl.org



  3. Re: Code goes into a loop

    On Jun 11, 12:26 pm, Klarth wrote:
    > Have a closer look at the condition in the while loop and pay
    > particular attention to the operator that you have used. It should be
    > very obvious what you are doing wrong.
    >
    > On Jun 11, 11:54 am, br...@brie.com (Brian Lavender) wrote:
    >
    > > This code just goes into a loop and keeps writing the first piece
    > > of info it reads. What am I doing wrong here?

    >
    > > while (nread = BIO_gets(out, buf, sizeof(buf) ) )
    > > {
    > > err = BIO_write(out,buf,nread );

    >
    > > }

    >
    > > --
    > > Brian Lavenderhttp://www.brie.com/brian/
    > > __________________________________________________ ____________________
    > > OpenSSL Project http://www.openssl.org
    > > User Support Mailing List openssl-us...@openssl.org
    > > Automated List Manager majord...@openssl.org


    Apologies for top posting before.

  4. RE: Code goes into a loop


    > This code just goes into a loop and keeps writing the first piece
    > of info it reads. What am I doing wrong here?
    >
    > while (nread = BIO_gets(out, buf, sizeof(buf) ) )
    > {
    > err = BIO_write(out,buf,nread );
    > }


    That's precisely what it's coded to do. Get a byte, then write that byte
    out, then get that byte then write it out. (Perhaps you meant to 'gets' from
    a different 'BIO' than you 'write' to?)

    DS


    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  5. Re: Code goes into a loop

    On Tue, Jun 10, 2008 at 10:20:56PM -0700, David Schwartz wrote:
    >
    > > This code just goes into a loop and keeps writing the first piece
    > > of info it reads. What am I doing wrong here?
    > >
    > > while (nread = BIO_gets(out, buf, sizeof(buf) ) )
    > > {
    > > err = BIO_write(out,buf,nread );
    > > }

    >
    > That's precisely what it's coded to do. Get a byte, then write that byte
    > out, then get that byte then write it out. (Perhaps you meant to 'gets' from
    > a different 'BIO' than you 'write' to?)
    >


    I have been trying BIO_read, BIO_write, BIO_gets, and BIO_puts and I
    can't seem to get a simple echo server and client to work. BIO_gets is
    supposed to read a line, correct?

    Server
    while ( nread = BIO_gets(out, buf, sizeof(buf) ) )
    {
    err = BIO_write(out,buf,nread );
    }

    Client
    fgets(buf, sizeof(buf), stdin);
    {
    n = strlen(buf);
    buf[n+1] = '\0';
    p = BIO_write(bio,buf, n + 1 );
    while ( n = BIO_gets(bio, buf2,
    sizeof(buf2) ) )
    {
    printf("%s", buf2);
    }

    }


    --
    Brian Lavender
    http://www.brie.com/brian/
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  6. Re: Code goes into a loop

    On Tue, Jun 10, 2008 at 10:20:56PM -0700, David Schwartz wrote:
    >
    > > This code just goes into a loop and keeps writing the first piece
    > > of info it reads. What am I doing wrong here?
    > >
    > > while (nread = BIO_gets(out, buf, sizeof(buf) ) )
    > > {
    > > err = BIO_write(out,buf,nread );
    > > }

    >
    > That's precisely what it's coded to do. Get a byte, then write that byte
    > out, then get that byte then write it out. (Perhaps you meant to 'gets' from
    > a different 'BIO' than you 'write' to?)


    It's supposed to be a simple echo server. gets reads data until it
    reaches a carriage return, correct?

    brian
    --
    Brian Lavender
    http://www.brie.com/brian/
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  7. Re: Code goes into a loop

    On Fri, Jun 13, 2008 at 01:07:50AM -0700, Brian Lavender wrote:
    > On Tue, Jun 10, 2008 at 10:20:56PM -0700, David Schwartz wrote:
    > >
    > > > This code just goes into a loop and keeps writing the first piece
    > > > of info it reads. What am I doing wrong here?
    > > >
    > > > while (nread = BIO_gets(out, buf, sizeof(buf) ) )
    > > > {
    > > > err = BIO_write(out,buf,nread );
    > > > }

    > >
    > > That's precisely what it's coded to do. Get a byte, then write that byte
    > > out, then get that byte then write it out. (Perhaps you meant to 'gets'from
    > > a different 'BIO' than you 'write' to?)

    >
    > It's supposed to be a simple echo server. gets reads data until it
    > reaches a carriage return, correct?


    Not Echo but Ouroboros. :-) You read a buffer of stuff from out, then
    write that buffer to out, which now has a new copy of the same stuff
    to read again. The serpent has seized its own tail.

    To echo, you need to take in data from somewhere else so that it winds
    up in the BIO, then take from out and write it to somewhere else.
    Perhaps you want to read from a different BIO "in" and copy to your
    BIO "out". Like so:

    #include

    #include

    int main (int argc, char *argv[])
    {
    BIO *in, *out;
    char buf[1024];
    int nread;
    int err = 1;

    in = BIO_new_fp(stdin,BIO_NOCLOSE);
    out = BIO_new_fp(stdout,BIO_NOCLOSE);

    while ((nread = BIO_gets(in, buf, sizeof(buf))) && err > 0)
    {
    err = BIO_write(out, buf, nread);
    }
    }

    A network echo service would use sockets instead of stdin, stdout
    (unless it's meant to be run by something like inetd).

    --
    Mark H. Wood, Lead System Programmer mwood@IUPUI.Edu
    Typically when a software vendor says that a product is "intuitive" he
    means the exact opposite.


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.9 (GNU/Linux)

    iEYEARECAAYFAkhSfBwACgkQs/NR4JuTKG9ROQCgpjVzs5YO4+rnHJQQoCR6vo+i
    9SoAn1TPo8SXm29XkZXwB5qnMYem/wBv
    =/m16
    -----END PGP SIGNATURE-----


+ Reply to Thread