Posts Tagged ‘tricks’

Pipes Example Code For Linux Process Synchronizaion

Pipe is a buffer of fixed size written by one related process and read by another related process. where related process means, parent and child process.
Usage : int pipe(int fildes[2])
creates a pipe and returns two file descriptors, fildes[0] and fildes[1] for reading and writing.
mutual exclusion is handled by operating system, ie only one process at a time can read or write to pipe. If one process is reading or writing on pipe other process will wait.
processes sharing the pipe must have same parent in common and are unaware of each other’s existence

Pipe example

main()
{
int n;
int   pipefd[2];
char buff[100];
if (pipe(pipefd) < 0)       // create a pipe
perror(“pipe error”);
printf(“read fd = %d, writefd = %d\n”, pipefd[0], pipefd[1]);
if (write(pipefd[1], “hello world\n”, 12) !=12) // write to pipe
perror(“write error”);
if ((n=read(pipefd[0], buff, sizeof(buff))) <=0) //read from pipe
perror(“read error”);
write(1, buff, n );   /* write to stdout */
close(pipefd[0]);
close(pipefd[1]);
exit(0);
}
Result:
read fd = 3, writefd = 4
hello world
default FD for any process under Linux is from 0, 1 and 2 ie for STDIN, STDOUT and STRERR, whatever new descriptors are created will be assigned FD greater than 2. So read FD for pipe is 3 and write FD for Pipe is 4.
Number of View :1376

Tags: , ,

No Comments


How To Capture X Protocol Traffic Using Wireshark On Windows XP?

This is an experiment about use wireshark to capture X protocol traffic

Google and the wireshark manual/wiki give no hints (ie. How do you capture DISPLAY=:0.0 traffic ?). Setting wireshark to capture “local” (127.0.0.1) or “any” devices captured nothing. The remote X11
server
doesn’t support XRandR so it’s no help.

If you set DISPLAY=localhost:0 then the client will use TCP on the
loopback interface and wireshark can capture that. Of course your X
server can’t be running with “-nolisten tcp”, which is default in many
installations. thanks to Xcb thread discussion

Challenges
I want to capture localhost traffic on Windows Xp machine with Wireshark, and it fails.
Did google on it about Is there a way to get wireshark to capture packets sent from/to localhost on Windows?
Got this info from WIKI Loopback capture setup
Which says I need to install Loopback adapter and steps here for Microsoft: How to install the Microsoft Loopback adapter in Windows XP

This method did not help much expect able to capture only ARP packets,

Capturing local traffic on Windows XP Route method
> route add 155.132.130.129 mask 255.255.255.255 155.132.130.1 metric 1
where 155.132.130.129 is your local IP, and 155.132.130.1 that of your default gateway. You must have “Advanced TCP/IP Settings > Automatic metric” disabled! What it does is basically force each packet intended for localhost to go out to the default gateway first, from which it will come back again. Of course this means you see each packet twice.

===Not directly, but if you are on a network with a gateway, you can use the
command-line ROUTE command to redirect the packets through the gateway, which will bounce the packets back at your machine so Ethereal/Wireshark can capture them.  You can use comview tool. It can fullfil your wish. Wireshark does not use IM driver but it uses protocol driver.

Still digging on How To Capture X Protocol Traffic Using Wireshark On Windows XP?

Number of View :1175

Tags: , , ,

No Comments


How To Capture X Protocol Traffic Using Wireshark On Windows XP

This is an experiment about use wireshark to capture X protocol traffic

Google and the wireshark manual/wiki give no hints (ie. How do you capture DISPLAY=:0.0 traffic ?). Setting wireshark to capture “local” (127.0.0.1) or “any” devices captured nothing. The remote X11
server
doesn’t support XRandR so it’s no help.

If you set DISPLAY=localhost:0 then the client will use TCP on the
loopback interface and wireshark can capture that. Of course your X
server can’t be running with “-nolisten tcp”, which is default in many
installations. thanks to Xcb thread discussion

Challenges
I want to capture localhost traffic on Windows Xp machine with Wireshark, and it fails.
Did google on it about Is there a way to get wireshark to capture packets sent from/to localhost on Windows?
Got this info from WIKI Loopback capture setup
Which says I need to install Loopback adapter and steps here for Microsoft: How to install the Microsoft Loopback adapter in Windows XP

This method did not help much expect able to capture only ARP packets,

Capturing local traffic on Windows XP Route method
> route add 155.132.130.129 mask 255.255.255.255 155.132.130.1 metric 1
where 155.132.130.129 is your local IP, and 155.132.130.1 that of your default gateway. You must have “Advanced TCP/IP Settings > Automatic metric” disabled! What it does is basically force each packet intended for localhost to go out to the default gateway first, from which it will come back again. Of course this means you see each packet twice.

===Not directly, but if you are on a network with a gateway, you can use the
command-line ROUTE command to redirect the packets through the gateway, which will bounce the packets back at your machine so Ethereal/Wireshark can capture them.  You can use comview tool. It can fullfil your wish. Wireshark does not use IM driver but it uses protocol driver.

Still digging on How To Capture X Protocol Traffic Using Wireshark On Windows XP?

Number of View :2039

Tags: , , ,

No Comments



SetPageWidth
Content Protected Using Blog Protector By: PcDrome.

Mahol Dot Org is Stephen Fry proof thanks to caching by WP Super Cache