25 October 2010

change realtime priority of a linux process

Get the sample program from here
[root@localhost ~]# uname -a
Linux ... 2.6.21-1.3194.fc7 #1 SMP ... GNU/Linux

# gcc -o realtime linux_realtime.c
# ./realtime
Round-robin quantum is 0 seconds, 99984800 nanoseconds
Sched getparam: current policy 0
Sched getparam: current priority 0
RR min prio: 1
RR max prio: 99
Completed test 0
Completed test 1
Completed test 2
Completed test 3
Completed test 4
Completed test 5
Completed test 6
Completed test 7
Completed test 8
Completed test 9


Reference:
http://www.helsinki.fi/atk/unix/dec_manuals/DOC_40D/APS33DTE/DOCU_003.HTM

15 October 2010

Working of traceroute

In Windows:
Windows starts out sending a ping echo request packet with a TTL of 1 to the destination, when a router encounters the packet and begins to process the request it decrements the TTL by 1. When the TTL reaches 0 the router sends back a Time to live exceeded in transit error message. Windows will then two more packets with the same TTL and records the round trip time for that router. Next the Windows client will increment the TTL by 1 reaching each router until the packet finds it final destination and the Windows client receives the echo reply.

Download sample tracert file for windows from here
C:\>tracert www.google.com

Tracing route to www.l.google.com [209.85.231.104]
over a maximum of 30 hops:

1 3 ms 2 ms 3 ms 192.168.1.1
2 66 ms 35 ms 39 ms 122.178.216.1
3 47 ms 90 ms 44 ms 122.166.32.101
4 116 ms 60 ms 49 ms 122.166.32.9
5 89 ms 103 ms 53 ms 122.175.255.29
6 57 ms 43 ms 64 ms 203.101.100.210
7 67 ms 101 ms 58 ms 72.14.216.229
8 79 ms 72 ms 38 ms 66.249.94.170
9 45 ms 35 ms 38 ms 72.14.238.90
10 39 ms 50 ms 51 ms maa03s01-in-f104.1e100.net [209.85.231.104]

Trace complete.

In Linux:
Linux starts out sending out 3 UDP packets with a TTL of 1 to the destination, when a router encounters the packet and begins to process the request it decrements the TTL by 1. When the TTL reaches 0 the router sends back a ICMP Time-to-Live Exceeded error message. Next the Linux client will increment the TTL by 1 reaching each router until the packet finds it final destination.

Since you are sending UDP packets with the destination address of the host you are concerned with, once it gets to the destination the UDP packet is wanting to connect to the port that you have sent as the destination port, since it is an uncommon port, it will most like be rejected with an ICMP Destination Unreachable (Type 3), Port Unreachable (Code 3). This ICMP message is sent back to your machine, which will understand this as being the last hop, therefore traceroute will exit, giving you the hops between you and the destination.

Download sample traceroute file for linux from here
# traceroute www.google.com
traceroute to www.google.com (209.85.231.104), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 6.246 ms 6.660 ms 10.447 ms
2 122.178.216.1 (122.178.216.1) 108.220 ms 107.885 ms 108.977 ms
3 122.166.32.101 (122.166.32.101) 107.723 ms 108.607 ms 118.167 ms
4 122.166.32.9 (122.166.32.9) 124.062 ms 124.725 ms 135.976 ms
5 122.175.255.29 (122.175.255.29) 136.151 ms 135.961 ms 136.123 ms
6 * 203.101.95.30 (203.101.95.30) 69.910 ms 71.222 ms
7 72.14.216.229 (72.14.216.229) 148.436 ms 148.394 ms 148.744 ms
8 66.249.94.170 (66.249.94.170) 148.130 ms 148.855 ms 148.582 ms
9 72.14.238.90 (72.14.238.90) 158.229 ms 158.211 ms 158.363 ms
10 * * *
...
...
29 * * *
30 * * *

Download c program to update mac address from here
gcc -o upmac upmac.c
./upmac trwin.cap trwin2.cap -i 192.168.10.101 \
-m 00:11:22:33:44:55 -n 00:55:44:33:22:11

Reference:
http://suncoastsecuritysociety.org/blog/2009/08/13/how-does-tracert-work-windows/
http://www.tek-tips.com/faqs.cfm?fid=381
http://www.exit109.com/~jeremy/news/providers/traceroute.html