Now uses a goto (nasty I know) to make sure that in error cases the connection
is closed properly
Now with more vairables at top rather than in the middle;
Also has error checking on writing config
Now prints after encoding rather than before
Now auto confs gateway ip
Now with unix line endings