The skeleton of a man in the middle

Intermediation

Placing yourself in the middle comes in handy in all sorts of situations. The following skeleton of Tcl code is fully functional and easily extended. I've used it in one form or another for many years now:

socket -server accept listeningPort

proc accept {client addr port} {
    if {[catch {socket -async destHost destPort} server]} then {
        shutdown $client
    } else {
        fconfigure $client -blocking 0 -buffering none -translation binary
        fconfigure $server -blocking 0 -buffering none -translation binary
        fileevent  $client readable [list glue $client $server]
        fileevent  $server readable [list glue $server $client]
    }
}

proc glue {src dst} {
    if {[catch {puts -nonewline $dst [read $src]}] ||
        [eof $src] || [eof $dst]} then {
        shutdown $src $dst
    }
}

proc shutdown {args} {
    foreach sock $args {catch {close $sock}}
}

vwait forever

It's possible to get even more mileage out of it. With just another couple of lines you can bridge SSL coming and/or going.

I love Tcl's event-driven I/O.


—Michael A. Cleverly

Comments:

  1. judidepositviapulsa wrote (at Mon, 07 Sep 2020, 03:11):

https://linkvaov9bet.net/v9b/profile.php?id=15359 https://carnavalslot.com/cs/profile.php?id=13163 https://game-zombie.net/forum/profile.php?id=5711 http://nilinreading.com/home.php?mod=space&uid=56098&do=profile&from=space https://bonqdaso.com/bds/profile.php?id=12281 https://www.zhaoyuanedu.com/home.php?mod=space&uid=7558 https://celadonhcm.com/cct/profile.php?id=14198 http://forum.mountec.net/home.php?mod=space&uid=44743 http://friend-feed.com/user/judidepositviapulsa/ https://disqus.com/by/judidepositviapulsa/ https://www.pbase.com/profile/judidepositviapulsa

  1. darumabet wrote (at Mon, 16 Nov 2020, 20:45):

http://magentoexpertforum.com/member.php/70454-darumabet https://ourblogginglife.com/community/profile/darumabet/ https://seed.stat.nus.edu.sg/index.php/forum/profile/2480-darumabet https://www.quibblo.com/user/darumabet https://www.inprnt.com/profile/darumabet/ https://www.santagrand.com/user/profile/142139 https://letterboxd.com/darumabet/ http://forum.wyrobynaturalne.eu/member.php?action=profile&uid=245662 http://revistas.uned.es/index.php/REEC/user/viewPublicProfile/1408205 http://xngzhan.com/space-uid-3402579.html

  1. darumabet wrote (at Thu, 26 Nov 2020, 23:32):

https://www.biofuelsforum.com/members/50583-darumabet https://www.gunforums.net/forums/members/117915.html http://wamoja.com/community/profile/darumabet/ http://damkwan.com/index.php?action=profile;area=summary;u=253865 https://www.campercommunity.com/forum/members/darumabet.html?simple=1#aboutme https://www.tetongravity.com/community/profile/darumabet/ https://clyp.it/user/bucy5jwx https://www.chilterntraveller.co.uk/members/darumabet/ http://bbs.junpinzhi.com/home.php?mod=space&uid=200992 http://www.interleads.net/classifieds/user/profile/220021

  1. lillian_harper wrote (at Mon, 23 May 2022, 01:04):

Shortcut keys help in giving an easier and faster way to navigate and execute commands in computer software. If you want to know more about keyboard shortcuts , you can click on this link.

Permanent URL for this post: http://blog.cleverly.com/permalinks/285.html