TODO- serial snooper

add logging (well, duh, why didn't i think of this?)
	although tee is JUST FINE too

somehow include kenmacros.h in the distribution

fix the getopts: -h and no args.

make the network socket code portable

autoconf 

----------------
STUCK

make the debug code optional? so i can run it as a daemon?
	essentially, make all the display.c shit DPRINTF level 1
		and all the other diagnostics DPRINTF level 2+
	finally, daemonize it. don't criticize it.
		fork(), etc.
	try it with sendfile? is it any faster/more responsive? if i don't need debug.

fancy formatting. 
	breaks after 8 bytes, in ascii. yes.
		non-trivial. i'd have to do it in stripUnreadables, AND make sure there's extra bytes to cover it, meaning malloc, it's gettin ugly


poll still returns with -1 data, if my pty went away
	exception? or is that just for network sockets?
	do i need to check write before writing, in bcast?
		non-trivial change. would need to put write into the poll loop

SO_REUSEADDR in socket server

----------------
BELOW THE LINE

possibly blow off all this command-line crap and use a conf file instead
	use the gtk file-parsing library . look up the name of it in my c/notes/gtk

cfmakeraw() instead of all that manual flag-setting

	and when in network/daemon mode, connect only when pty opens
		could require significant reshuffling. opens are in main right now... 

	select/poll doesn't work with ptmx's on linux. wtf?
		STUCK: find docs on devpts/ptmx interface on linux, and how it works
				or look in openssh source, for examples

	try termtest on netbsd
		STUCK: need to fix some of the includes/ifdefs/defines

make the display dynamic?
	non-trivial
	does the column width show up in any envs?
		nope, but you can ioctl or cfget for it!!!


expand to make it handle more than two
	change the command line parsing instead of -a -b, just put them as optind's
		i.e after all the dash options are done!
	either create multi-versions (array?) of the twoxxx functions, or expose them
	fix the polLoop so that it handles a read returning 0 by removing the fd!
		perhaps it needs to remvoe the OPPOSITE side's fd? why is this broken?

create a DIEUSAGE macro?

hmm. how to grow/remove the fdstruct array?

add a void * to the fdstruct, and use it for newPfd(), pollLoop(), et al

----------------
NOWHERE

			or just be lazy and stick it in common.h?
			NOPE. 
	hmm. i'm gonna have to insert this into the poll loop. dammit.
		NOWHERE: not necessary. 'tis all good w/o it.
	getpeername
		NOWHERE:  ack. no good, too slow. 
	wow! if the cable is present, i get an 0x07 back... is that predictable?
		NO. could be a good way to tell what's going on!

	test with standard terminal shit
		btw read telnet rfc's
		NOWHERE: need server shit: 
deal with the writing now.
	shall i select for write? hmm... could get tricky...
		NOWHERE: not needed, i don't think
	try it on netbsd? NOWHERE: same problem
	try the oldskool berkeley shit instead?
		it fixes the crash at basic read
		ack. that's borken too
	re-read unix book on terminals NOTHING there on ptmx?
	try putting signal handlers in NOWHERE. still broken
----------------
DONE

		ack! /usr/include/asm/ioctls.h. uses TIOCGPTN not TIOCGNAME i.e. SYSV
set up and open tty
	lift from chotplay/src/tty.c
		DONE
set up and open pty
	lift from termtest
	use only the linux version, for now anyway.
		DONE

write a simple poll/select loop to read from both/either
	there's one in sockclient/server isn't there? DONE

	try select instead
		SOLUTION! it works!
try poll...again... with & not ==
	SOLUTION: that was it! i just copied the select code, changed to poll, all's good

ack. the poll is broken. but raw reads work just fine.
	look at openssh?
		SOLUTION: just looked in orielly book. simple change

baud setting looks alllll goooodd
		ack, garbage chars, or something wrong. readcount is too long!
			SOLUTION: it includes cr/lf, AND it's not null-terminated. duh.
	get %*s going or snprintf or something
		SOLUTION: done
	do some isprint() shit. DONE
		hmm. some constipation. my while() read loop?
			SOLUTION: no while
hmm. shall i read until done, or just grab one chunk?
	look around at other code
		SOLUTION: nope. no while, just an if

start the writing/reading. 
	make sure it works, and works well.
		well, it does, dammit!
	some static var, who was talking last, so if it changes, i print that?
		cool. but... the totals don't look quite yet
			SOLUTION: sequence is important ;-)
add in the decoding/printing
	lift from xxd? ;-) at least read it
		DONE. it's not perfect, or even nice, but it works
figure out the command-line options
		two devices: a and b
			each device could be one of net/pty/tty
		ok, -a and -b. spec it as /dev/xxx:baud or host.name.domain:port
			grab code from chotplay DONE
	roll in the code (should be easy) DONE
	
	parse out the device line DONE
	regression testing DONE. 'tworks
	some way to keep track of hup's, pts's open/closed, tty's open/closed
		i.e at least print an informative message
			DONE! READ 0 if socket closed
that weird network read = 0 shit?
	can i exit if i get a read of 0? DONE
	why it dooo dat? socket closed? term server hung up?
		SOLUTION: assume so.

	test with bogus/safe terminal SERVER DONE. it works
ok, go for it: add in the network code! now i have something like net2tty
	test with the actual camera! this be it... 
		hmm. weirdness.  SEP: chotplay
		HAH! well, with two chotplays in serial, it works JUST FINE!
	add license headers
		DONE
	write an index page
		DONE

package up as a tarball and post it
	off we go to freshmeat.net
		DONE

	how to deal with that on the command line???
		SOLUTION: just port, for server mode!!
	grab from servertest? DONE
server mode! oh shit, bind(), listen(), accept() etc.
	DONE! and it works!

	i need to make it more xxd-like
		SOLUTION: simple. just assume 80 col for now, then % == 0 test
			i know i've done this before
	d-oh. my % formula is wrong
		STUCK: look it up somewhere, i've doen it before
			kcurses? sim?
			DUH. it's a simple < MAX
		tricky!
			one, i've got stripunreadables set to work on a whole block
			two, how do i know? a flag?
				SOLUTION: do the stripping in hexdump, and use a damn flag
					i had to usea pointer flag because len 0 was problematic
		problem! if i just have one or two bytes, i get nothing. oops
			SOLUTION: busted out the line print
clean up the evil i++ hack in hexDump()
	DONE

	now put the ascii in there too
	works fine for short packets but for long ones it's unreadable. 
		whoops.. looks great for long packets, but short ones are fucked
			ok, now deal with remainder issues
				DONE. a simple line - pos issue
the decode display is butt-ugly. 
	SOLUTION: nice now.
	2bytes, then space. 2 spaces at 4 byte boundaries. 
		DONE
	i need a global array, dammit.
		null-terminated, for searching. DONE
		populate it at open() time. DONE
		return name/fd in a struct DONE

		where to store it??
			global in main, for now!
		at close, free the name
			DONE
	now, update the display function to USE this fabulous information...
		need a common.c, dammit, with a lookup function
		SOLUTION: i stuck it in common.c. AND i quarantined the use of the global there too
hmm. some way to glean the socket host/port from an fd/sd?
	trash all ttyname() and replace with lookupName()
		DONE


pollLoop() is still fucked. 
	seems like poll() returns if an fd closes, but processInput wigs
		STUCK: read the docs, poll, etc. find out what's supposed to happen
			a network socket WILL return a read of 0 if it is closed
				true of other fd's too?
		create an exception handling routine that removeFd's etc
	hmm. it looks like it's trying to read from fd -1. huh?
		fix this dammit.
	processInput() only does one fd at a time. prolly not good
		not sure about bcast(), if i need to flush readers b4 writing?
			STUCK: read docs
		SOLUTION: duh. i had NDELAY on serial tty. that was stupid. ok now.
should i be using O_NDELAY on tty when i'm using select/poll?? good idea?
	 read up on this
		SOLUTION: i'm not using it, since i'm polling instead.

	right-justify the ascii on short packets
		non-trivial. would require keeping count of cols pooted out.
			i.e. with each byte sent.. hmm. maybe that's not impossible...
		DONE! wasn't too bad, but it's still a little goofy
