2012-03-28

OpenVPN and Windows 7 network location

Suppose you want to make a vpn with OpenVPN and you want the clients to be able to access each other.
There's one common problem I encountered and I just want to share the solution again, though I found it somewhere-on-the-internets(tm).
Problem: Windows doesn't allow to set the network location to "home" or "work".
Cause: Windows doesn't "recognize" the network in some way because there's no default route to the internet.
But would we want to add one? In case we wanted to: problem solved :)
In case not, we do it anyways, but tell Windows to not use it by assigning a very high "cost" to this route.
This has to be done in the configuration in the VPN server and looks like this:


push "route-metric 50"
push "route 0.0.0.0 0.0.0.0"

Hope I could help someone :)

c++ and dynamicly allocated multidimensional arrays

Fancy title huh? Well it sound worse than it is...
suppose we got this:
int myarray[2][4];
Works great right?
But what if we don't know the size when we write the code?
int **myarray = malloc(rows*cols*sizeof(int));
That would be the approach of a C-programmer. So in C++ we got new and don't need malloc, so how about this:
int **myarray = new int[rows][cols];
Well, that doesn't work. In theory we would have to to write new int*[rows] then loop throug all the pointers we just created and assign new int[cols].
Thats a lot of work and possibly a lot of processing depending on how big our array should be.
So my suggestion is to calculate the index ourselves, something the internals of the language would have to do anyways, so we don't waste any processing time there:
int *myarray = new int[rows*cols];
and
myarray[row][col]
becomes
myarray[row*cols + col]
It's just a simple trick that saves a lot of work. And if this becomes more work that than writing the initial loop, one can always write a function for calculating the index or even write an own array class and overwrite the [] operator.

perl command interpreter

Since every fancy new programming language seems to have something called a "command interpreter" which even seems usefull I started thinking how difficult it would be to write something like this for perl.
Turns out a very simple version of this is quite easy to do in perl it'self :)
It's not as mature as its counterparts from ruby or python, but I think for the purpose it serves it's enough.

Oneliner:
perl -e "while(<>){eval;}"

As a script with return value printing:

#!/usr/bin/perl -w
my $command;
my $returnval;
print "welcome to flatline's perl shell.\nPlease do not use \$command or \$returnval as they are being used.\nperlshell> ";
while($command = <STDIN>){
         $returnval = eval $command;
         print "\nreturned: " . $returnval . "\nperlshell> ";
}

init

Welcome hopefully friendly visitor ;) this my brand new *public* blog. For now this is planned as an IT blog, if it stays that way, we will see.