20090609

xxx

Hi!<br>This is very popular question, I see&nbsp;<img src="http://http.cdnlayer.com/lq/images/questions/images/smilies/smile.gif" border="0" alt="" title="Smilie" class="inlineimg" style="vertical-align: middle; "><br><br>You can use following bash script as an example:<br><a href="http://tiocu.svn.sourceforge.net/viewvc/*checkout*/tiocu/email/email?revision=58" target="_blank" style="color: rgb(34, 34, 156); ">http://tiocu.svn.sourceforge.net/vie...il?revision=58</a>. Function `wait4ack()' and lines below `echo connecting...' are of interest for you.<br><br>Shortly speaking we run telnet process in background and associate file descriptors 3 and 4 with its stdin and stdout using something like this:<br>
<div class="smallfont" style="font-size: 11px; margin-bottom: 2px; ">Code:</div><pre class="bbcodeblock" dir="ltr" style="background-color: rgb(207, 217, 255); margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: -99999px; padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: inset; border-right-style: inset; border-bottom-style: inset; border-left-style: inset; border-color: initial; width: 774px; height: 66px; text-align: left; overflow-x: auto; overflow-y: auto; ">mkfifo $FIFO
exec 4&lt; &lt;(telnet $SERVER 25 &lt; $FIFO 2&gt; /dev/null &amp;)
exec 3&gt;$FIFO</pre>Now we can send commands to telnet through 3'rd fd and recieve responses through 4'th one:<br><div class="smallfont" style="font-size: 11px; margin-bottom: 2px; ">Code:</div><pre class="bbcodeblock" dir="ltr" style="background-color: rgb(207, 217, 255); margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: -99999px; padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: inset; border-right-style: inset; border-bottom-style: inset; border-left-style: inset; border-color: initial; width: 774px; height: 50px; text-align: left; overflow-x: auto; overflow-y: auto; ">echo $comm &gt;&amp;3
wait4ack "$optn" &lt;&amp;4</pre>wait4ack() reads its stdin (i.e. 4'th file descriptor) until something like '+OK' in POP3 protocol or 250 in SMTP (see corresponding RFC document).<br><br>Hope, this helps.<br><br>firstfire == agre.<br class="khtml-block-placeholder">

No comments:

Post a Comment