This is the mail archive of the cygwin mailing list for the Cygwin 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]

Re: echo "$(echo '\r')" oddity


Jan Just Keijser wrote:

> socat (http://www.dest-unreach.org/socat/) is a multi-purpose relay tool
> that can be used to connect sockets to pipes and vice versa, or terminal
> pty's to TCP sockets etc etc. I have found it a very handy tool to build
> VPN-like things in a environment where you cannot or do not want to modify
> the existing networking infrastructure.

Thanks for the tip.  It indeed does look like a very powerful program, and I am quite
glad to have it in my tool chest now.

I built socat and tried the very same commands you did, and it seems to work fine.  I
normally run a CVS build of the Cygwin DLL but I switched to 1.5.16 and it works fine
with that version as well.

$ socat -t 0.1 exec:'openssl s_server -accept 12002 -quiet -cert cacert.pem -key
privkey.pem' pipe &
[1] 3276

$ socat -d -d -t 0.1 - openssl:localhost:12002,cafile=cacert.pem,verify=1
2005/05/04 02:19:30 socat[2460] N reading from and writing to stdio
2005/05/04 02:19:30 socat[2460] N opening connection to AF=2 127.0.0.1:12002
2005/05/04 02:19:30 socat[2460] N successfully connected from local address AF=2
127.0.0.1:4335
2005/05/04 02:19:30 socat[2460] N SSL connection using DHE-RSA-AES256-SHA
2005/05/04 02:19:30 socat[2460] N starting data transfer loop with FDs [0,1] and [3,3]
hello
hello
goodbye
goodbye
2005/05/04 02:19:34 socat[2460] N socket 1 (fd 0) is at EOF
2005/05/04 02:19:34 socat[2460] N socket 2 (fd 3) is at EOF
2005/05/04 02:19:34 socat[2460] W shutdown(3, 2): Bad file descriptor
2005/05/04 02:19:34 socat[2460] N exiting with status 0

The hello and goodbye I each typed once, the second one was echoed back to me.  I then
hit ^D.  If there was any network problems I would not have expected the ssl handshake
to succeed (I used a dummy cert on both sides as you can tell.)

> this command runs fine on Linux but under Cygwin there is no output echoed
> back from the openssl s_server application. More specifically, the socat
> server process (first line) does return the output but it looks like the
> output never reaches the client - to me, that sounds like a pipe flushing
> problem or a line-termination problem.

I can't quite parse this.  You say it returns the output but it never reaches the
client?  How do you know this?  Surely this swiss army knife of socat will have enough
verbose debugging information for you to find out what's going on.

> the command that I reported yesterday:
>   echo "$(echo '\r')"
> is now working under a newly-compiled version of bash 3.0 in which I
> commented out the offending section in subst.c.

I very much doubt that this has anything to do with the above.  Pipes and sockets are
always opened in binary mode by default.  Regular files default to binary mode as well,
unless you chose 'Dos' at setup.  Even if you did, that still would result in no change
in behavior with pipes or sockets -- that is why bash had to be patched to set textmode
explicitly on the subprocess' fd, becauase unless the application asks for that it will
never be done.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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