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 <stdio.h> #include <openssl/bio.h> 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 [EMAIL PROTECTED] Typically when a software vendor says that a product is "intuitive" he means the exact opposite.
pgpqBeVFub079.pgp
Description: PGP signature