2008年11月30日 星期日

static/dynamic library, "file" comman usage

Refer from https://www.cs.utk.edu/help/doku.php?id=compile:c

Compile Phase:

# gcc -c hello.c

Dynamic Linking:

# gcc -o hello hello.o
# ls -lh hello
-rwx------ 1 user group 12K Sep 18 18:35 hello
# file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
for GNU/Linux 2.2.0, dynamically linked (uses shared libs), not stripped

Static Linking:

# gcc -static -o hello hello.o
# ls -lh hello
# -rwx------ 1 user group 465K Sep 18 18:38 hello
# file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
for GNU/Linux 2.2.0, statically linked, not stripped

2008年11月27日 星期四

How to interpret the tcpdump header

15:19:03.018317 IP (tos 0x0, ttl 63, id 27496, offset 0, flags [DF], proto TCP (6), length 62) 140.113.102.165.44298 > 192.168.2.107.46877: P, cksum 0x0180 (correct), 1:11(10) ack 12 win 365
0x0000: 4500 003e 6b68 4000 3f06 1a28 8c71 66a5 E..>kh@.?..(.qf.
0x0010: c0a8 026b ad0a b71d 6183 1a2f 7d66 3155 ...k....a../}f1U
0x0020: 8018 016d 0180 0000 0101 080a 8c57 7f5a ...m.........W.Z
0x0030: a044 62e7 6865 6c6c 6f77 6f72 6c64 .Db.helloworld

15:19:03.018317 ==> timestamp
IP (tos 0x0, ttl 63, id 27496, offset 0, flags [DF], proto TCP (6), length 62)
==> ip header
tos 0x0 ==> tos value 0x0
ttl 63 ==> ttl value is 63
id 27496==> ip id is 27496
offset 0 ==> offset is 0
flags [DF] ==> IP flag don't flagment
proto TCP (6) ==> trasnport protocol is tcp (6)
length 62) ==> ip length is 62 (include ip header)

140.113.102.165.44298 > 192.168.2.107.46877
==> source ip/port from 140.113.102.165.44298 to destination ip/port 192.168.2.107.46877

: P, cksum 0x0180 (correct), 1:11(10) ack 12 win 365
:P ==> TCP flag, PUSH flag is on, ACK will not show, S indicate SYN, F indicate FIN, R indicate RST
cksum 0x0180 (correct) ==> tcp check sum is 0x0180, validate it is correct
1:11(10) ==> sequence number diff is from 1:11 total 10 bytes
ack 12 ==> the data had been received is 12-1 bytes, next expected bytes is 12th byte
win 365 ==>
The sender can receive max data size next time.

0101 080a 8c57 7f5a a044 62e7
01 => no operation, nop
01 => no operation, nop
08 => timestamp
0a => 10 bytes (in the tomestamp option, 8 bytes for data)
8c57 7f5a => Timestamp value, 2354544474
a044 62e7 => Timestamp echo reply, 2688836327






2008年11月20日 星期四

Linux Command - fdisk, File system management

>> partition the hard drive, list all the partition tables
# fdisk -l

>> Enter specified partions, press p to display all the partions
# fdisk /dev/sda

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000dda97

Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 1044 8185117+ 8e Linux LVM ==> LVM is a Linux Volumn Manager, Can support RAID architecture

>> format the file system
# mke2fs

>> physically mount the file system
# mount /dev/hdc1 /vm

Linux System - File Systems.. LVM management

# ls -la /dev/rootvg/
/dev/rootvg/LogVol00 -> /dev/mapper/rootvg-LogVol00
/dev/rootvg/LogVol01 -> /dev/mapper/rootvg-LogVol01
/dev/rootvg/LogVolVM01 -> /dev/mapper/rootvg-LogVolVM01

# ls -la /dev/mapper/
total 0
control
rootvg-LogVol00
rootvg-LogVol01
rootvg-LogVolVM01

# lvdisplay /dev/rootvg/LogVol00
--- Logical volume ---
LV Name /dev/rootvg/LogVol00
VG Name rootvg
LV UUID SYotdp-V3oQ-Gc5p-wDjv-txyz-Q09p-7cgsXz
LV Write Access read/write
LV Status available
# open 1
LV Size 200.00 GB
Current LE 6400
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0

# lvdisplay /dev/rootvg/LogVol01
--- Logical volume ---
LV Name /dev/rootvg/LogVol01
VG Name rootvg
LV UUID 8MT67X-WpcY-Nyw3-MA57-jKKn-ryq6-9dMWcD
LV Write Access read/write
LV Status available
# open 1
LV Size 1.94 GB
Current LE 62
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1

# lvdisplay /dev/rootvg/LogVolVM01
--- Logical volume ---
LV Name /dev/rootvg/LogVolVM01
VG Name rootvg
LV UUID e9LYTF-yFRz-RdC1-KC8q-wAN1-2UiM-8dILP5
LV Write Access read/write
LV Status available
# open 0
LV Size 50.00 GB
Current LE 1600
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:2


How to enlarge an exsiting partition, here is my experience.
1. First umount the file system
# umount /vm

2. Then use lvextend to extend the logical volumn to the specified volumn size
# lvextend -L80G /dev/rootvg/LogVolVM01

3. Then run the e2fsck to check the new file system
# e2fsck -f /dev/rootvg/LogVolVM01

4. Use resize2fs to reorgnize the new logical volumn
# resize2fs /dev/rootvg/LogVolVM01

5. mount the logical volumn to the file sytem
# mount /dev/rootvg/LogVolVM01 /vm

http://www.kume.idv.tw/read-226.html

首先,我要說明一下。我用的是Fedora Code 5。所以我以下所用到的指令,全部都有。不需要download 與build任何東西。

第一件事就是載入LVM所需要的module
% modprobe dm-mod ==> 我的不work, 可能是沒有module

接著就是找出partiton中的VG(Volume Group),以我的狀況為例,我將硬碟以usb連接到電腦後,由dmesg可以知道有 /dev/sda1, /dev/sda2兩個patitons,在以 fdisk -l /dev/sda 可以知道/dev/sda2是LVM格式。接著,我就執行:
% pvscan ==> Fedora Rescue disc 沒有包含這個程式
PV /dev/sda2 VG VolGroup00 lvm2 [18.50 GB / 32.00 MB free]
Total: 1 [18.50 GB] / in use: 1 [18.50 GB] / in no VG: 0 [0 ]

從以上結果,我可以知道我有一個VG,叫做VolGroup00,他的PV(Physical Volume)是 /dev/sda2

接著我就執行:
% vgchange -ay VolGroup00 ==>我測試是不用加VolGroup00 參數, 只要% cgchange -ay 就會在/dev/ 下面產生一個VolGroup00 folder, 並且在這個目錄下產生該有的device(其實是link到/dev /mapper下)。
% ls /dev/VolGroup00/
LogVol00 LogVol01

這時候vgchange會在/dev下產生一個VolGroup00的目錄,並且在這個目錄下產生該有的device(其實是link到/dev /mapper下)。然後我利用 ls就可以知道VolGroup00這個VG下有兩個LV(Logical Volume)。分別是LogVol00 與 LogVol01。然後我只要mount我要的就可以了。
% mkdir /mnt/usb
% mount /dev/VolGroup00/LogVol00 /mnt/usb/ ==> 在/dev/VolGroup00/ folder下面會有兩個file, 分別表示LVM的2個檔案, 包含有 /dev/VolGroup00/LogVol00, /dev/VolGroup00/LogVol01, 這裡的例子是將第一個LVM mount 到/mnt/usb 這個logic folder 下, 然後就可以直接存取 /mnt/usb 這個路徑去抓LVM 1的data了


Q. How to rescue the HD with LVM file system?
A.
1. Insert the Fedora disc 1, enter rescue mode.
2. Issue the following commands to find the LVM partitions
# lvm vgscan
# lvm vgchange -ay
# lvm lvs

// e2fsck -y==>all questions response "yes", -c==>fix bad block file system
# e2fsck -y -c /dev/VolGroup00/LogVol00
# e2fsck -y -c /dev/VolGroup00/LogVol01

2008年11月18日 星期二

kamailio doesn't forward the ACK

UAC
1. Receive 200 OK
SIP/2.0 200 OK
| INFO3 | cb_rcv2xx (id=2)^M
| INFO1 | cb_nict_kill_transaction (id=2)^M
| INFO4 | sipevent evt: method called!

2. Send ACK

3. Receive 200 OK again
| INFO1 | 2xx restransmission receveid.^M
| INFO1 | Message sent:
4. Send ACK again
| INFO1 | ACK restransmission sent.

2008年11月17日 星期一

SIP Register with authentication required (using eXosip2)

->Send Register

->Receive SIP/2.0 407 Proxy Authentication Required with header
Proxy-Authenticate: Digest realm="W.X.Y.Z", nonce="YYYY0992000000046dd64e657218e5a77472ae059c69XXXX"

->Send Register with header
Proxy-Authorization: Digest username="XXXXX", realm="W.X.Y.Z", nonce="YYYY0992000000046dd64e657218e5a77472ae059c69XXXX", uri="sip:W.X.Y.Z", response="ZZZZe5d430141e984ff50fa560bWWWW", algorithm=MD5 ==>1st try

->Receive SIP/2.0 407 Proxy Authentication Required with header
Proxy-Authenticate: Digest realm="W.X.Y.Z", nonce="YYYY0992000000046dd64e657218e5a77472ae059c69XXXX"

->Send Register with header
Proxy-Authorization: Digest username="XXXXX", realm="W.X.Y.Z", nonce="YYYY0992000000046dd64e657218e5a77472ae059c69XXXX", uri="sip:W.X.Y.Z", response="ZZZZe5d430141e984ff50fa560bWWWW", algorithm=MD5 ==>2nd try

->Receive SIP/2.0 407 Proxy Authentication Required with header
Proxy-Authenticate: Digest realm="W.X.Y.Z", nonce="YYYY0992000000046dd64e657218e5a77472ae059c69XXXX"

->Send Register with header
Proxy-Authorization: Digest username="XXXXX", realm="W.X.Y.Z", nonce="YYYY0992000000046dd64e657218e5a77472ae059c69XXXX", uri="sip:W.X.Y.Z", response="ZZZZe5d430141e984ff50fa560bWWWW", algorithm=MD5 ==>3rd try

->Receive SIP/2.0 407 Proxy Authentication Required with header
Proxy-Authenticate: Digest realm="W.X.Y.Z", nonce="YYYY0992000000046dd64e657218e5a77472ae059c69XXXX"

2008年11月16日 星期日

echo/warning/error messages in the bash shell

Reference from the kamailio source, scripts/kamdbctl.base
mdbg() {
if [ "0$VERBOSE" -ne 0 ] ; then
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e "\033[1m$1\033[0m"
else
echo "$1"
fi
fi
}

mwarn() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;32m'"\033[1mWARNING: $1\033[0m"
else
echo "** WARNING: $1"
fi
}

minfo() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;33m'"\033[1mINFO: $1\033[0m"
else
echo "** INFO: $1"
fi
}

mecho() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e "\033[1m$1\033[0m"
else
echo "$1"
fi
}

merr() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;31m'"\033[1mERROR: $1\033[0m"
else
echo "** ERROR: $1"
fi
}