www.technotes.se » 2010 » September
Posted on 29-09-2010
Filed Under (C programming, Pointers in C, Programming) by Lonezor

A short discussion regarding quadruple pointers in C.

I just saw code today where a double pointer as a function argument is used. I was curious whether or not the C language supports more than the common * and ** syntax. It is indeed possible to have deeper indirections. However their use cases are not that common to say the least. Still, some algorithms with complex data structures might benefit with these constructions.

Example below:

#include <stdio.h>

int main(int argc, char* argv[])
        int value = 42;
        int* p1 = NULL;
        int* p2 = NULL;
        int* p3 = NULL;
        int* p4 = NULL;
        int**** pppp = NULL;

        p1 = (int*)&value;
        p2 = (int*)&p1;
        p3 = (int*)&p2;
        p4 = (int*)&p3;

        pppp = (int****)p4;

        printf("value: %d\n", ****pppp);

        return 0;
(0) Comments   
Posted on 29-09-2010
Filed Under (Linux, VMware, Windows, X11, xorg) by Christian

This will enable you to run VMware player in a new X server with it’s own unique screen resolution etc. Use-case example: you can run Linux and Windows within separate X server sessions simultaneously with different screen resolutions.

* Create a directory in your home directory to store your scripts:

$ mkdir ~/myscripts

Two scripts will be created. The first one will be used to start the actual X server and the second one will be used to start a program within the new X server.

* Create and edit a file called “~/myscripts/start_new_x_server” using gedit or the editor of your choice:

$ gedit ~/myscripts/start_new_x_server

* Paste the following line into the “~/myscripts/start_new_x_server” file:

xinit $* -- :1 -depth 24

Editing the file: "~/myscripts/start_new_x_server" with gedit.

Explanation of: “xinit $* — :1 -depth 24″

xinit $* — :1 -depth 24″

xinit will be started with the input parameters to the script “$*”.

“xinit $* – :1 -depth 24″

The “– :1″ part means that we want to start a new x server on X server session 1 default is 0 and is started as default when you are using a X session such as running gnome.

“xinit $* — :1 -depth 24

The “-depth 24″ parameter specifies the color depth to be used for the display. Ih this case 24 bit color depth will be used.

* Save the file and exit gedit.

We now create the second script that will invoke a program running in a new X window, in this case VMwarePlayer

* Create and edit a file called “~/myscripts/start_vmplayer_fullscreen”:

$ gedit ~/myscripts/start_vmplayer_fullscreen

* Paste the following line into the “~/myscripts/start_vmplayer_fullscreen” file:

/usr/bin/vmplayer --fullscreen <PATH TO YOUR VMPlayer .vmx file>


/usr/bin/vmplayer --fullscreen /mnt/space/vmware/winxp_30gig/winxp_30gig.vmx

Editing the file: "~/myscripts/start_vmplayer_fullscreen" with gedit.

Explanation of: “/usr/bin/vmplayer –fullscreen /mnt/space/vmware/winxp_30gig/winxp_30gig.vmx”

/usr/bin/vmplayer –fullscreen /mnt/space/vmware/winxp_30gig/winxp_30gig.vmx”

Start vmplayer from its absolute path /usr/bin/vmplayer and force it to start in fullscreen mode with the –fullscreen flag.

“/usr/bin/vmplayer –fullscreen /mnt/space/vmware/winxp_30gig/winxp_30gig.vmx
The image containing your virtual machine, in this case a 30 gig formatted image (file) containing Windows XP.

* Save the file and exit gedit.

We are almost done.

* We now need to add “~/scripts” to your PATH variable to be able to invoke the scripts independent of where you are in the file system:

$ gedit ~/.bashrc

Search for ‘PATH’ in the “~/.bashrc” file. If the string ‘PATH’ is not found in the “~/.bashrc” file then append the following line to the end of “~/.bashrc”:


If it indeed already has a PATH then append the following to the end of that file:

Before the edit:

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games

After the edit:

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:~/myscripts

Don’t close the “~/.bashrc” yet.

As a final thing to be done we need to create an alias for invoking both of these scripts.

* Append the following to the “~/.bashrc” file:

alias start_vmware_fullscreen='~/myscripts/start_new_x_serverĀ  ~/myscripts/start_vmplayer_fullscreen'

Editing the file: "~/.bashrc" with gedit.

Explanation of: “alias start_vmware_fullscreen=’~/myscripts/start_new_x_serverĀ  ~/myscripts/start_vmplayer_fullscreen’”:
This means that when you type “$ start_vmware_fullscreen” it will in fact start the script ~/myscripts/start_new_x_server and send the contents of ~/myscripts/start_vmplayer_fullscreen as input parameter to the first script.

This means that when executing:

$ start_vmware_fullscreen

the following is done:

$ xinit /usr/bin/vmplayer --fullscreen /mnt/space/vmware/winxp_30gig/winxp_30gig.vmx -- :1 -depth 24

Remember that “$*” reads the input parameters, thats why the contents of the second script replaces “$*” in the first script.

* Save and exit “~/.bashrc”.

* Reload “~/.bashrc”

$ source ~/.bashrc

* Make the file: “~/myscripts/start_new_x_server” executable.

$ chmod +x ~/myscripts/start_new_x_server

Try this out by typing:

$ start_vmware_fullscreen

You can now toggle between the different X server (one could be running linux and the other windows) by pressing:




Enjoy! /Christian

(0) Comments   
Posted on 28-09-2010
Filed Under (NAT, Networking, OpenBSD, port forward) by Lonezor

Starting from OpenBSD 4.7 a new packet filtering syntax is used. It is more generalized than before. This means that pf.conf needs to be translated to work properly. Typical use cases are NAT and port forwarding.

Example of the new syntax in /etc/pf.conf:

# Setup NAT for local ethernet network
ext_if = "vr0" # WAN net device
match out on $ext_if from nat-to ($ext_if)

# Port forwarding, HTTP traffic
pass in on $ext_if proto tcp from any to ($ext_if) port 80 rdr-to port 80

Load new configuration:

pfctl -f /etc/pf.conf
(0) Comments    Read More