發表文章

netstat

Options: -l Display listening server sockets -a Display all sockets (default: connected) -e Display other/more information -n Don't resolve names -t Tcp sockets -u Udp sockets -w Raw sockets -x Unix sockets -r Display routing table -W Display with no column truncation -p Display PID/Program name for sockets netstat -na 顯示主機上所有已建立的連線。 netstat -an | grep :80 | sort 顯示所有 port 80 的連線,並把結果排序。 netstat -n -p|grep SYN_REC | wc -l 列出主機上有多少個 SYNC_REC,一般上這個數字應該相當低。 netstat -n -p | grep SYN_REC | sort -u 同樣是列出 SYNC_REC,但不只列出數字,而是將每個 SYNC_REC 的連線列出。 netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}' 列出發送 SYNC_REC 的所有 ip 地址。 netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n 計算每一個 ip 在主機上建立的連線數量。 netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n 列出從 TCP 或 UDP 連線到主機的 ip 的數量。 netstat -ntu | grep ESTAB | awk '...

mixed implicit and normal rules

今天要重編 kernel 時, make menuconfig 突然出現了  " mixed implicit and normal rules " 這個訊息? 奇怪的是,明明沒有動到 code , 怎麼會這樣??? 上網查了一下, Fedora 14 之後,好像就有這樣的問題!!!@@@@ 剛好前幾天從 13 --> 15, 這說明了!!!沒事不要亂更新。 這是 make 的版本問題!不清楚為何要這樣限制? 將此行           config %config: scripts_basic outputmakefile FORCE 改成          %config: scripts_basic outputmakefile FORCE 就可以了。

備份 MBR, 還原 MBR, 刪除 MBR

備份硬碟MBR # dd if=/dev/sda of=/mbr.bak bs=512 count=1 還原硬碟MBR # dd if=/mbr.bak of=/dev/sda bs=512 count=1 刪除硬碟MBR # dd if=/dev/zero of=/dev/sda bs=512 count=1

struct成員的記憶體位址alignmentt

一般來說, compiler編譯c程式時, 遇到struct時會對成員資料的位址進行alignment的動作, 以增加記憶體讀取的效率. 所以struct往往會佔有比所有資料成員大小和還要多的記憶體空間. 例如下列的struct data的記憶體大小為12. struct data {      char num;       int size;       void *ptr; }; 如果因為特殊需要, 需要節省記憶體, 則可以在程式碼中需要進行pack memory的struct前後, 採用#pragma pack來告訴compiler是否要進行pack memory的動作, 例如下列的struct packed_data的記憶體大小則為9, 不是12. #pragma pack(1) struct packed_data {       char num;       int size;       void *ptr; }; #pragma pack()

cross compile Parted

需要先有 libblkid 和 libuuid 這在 util-linux 裡就有。 Parted 很人性話的會告訴你缺啥?去哪找? wget http://www.kernel.org/pub/linux/utils/util-linux/v2.21/util-linux-2.21.2.tar.bz2 wget http://ftp.gnu.org/gnu/parted/parted-2.4.tar.gz 將所有需要的 include 和 lib 都放到同一個目錄( install 裡 )下 ------------------------------------------------------------------------------------------------ -------------------------- util-linux make distclean ./configure --host=arm-mv5sft-linux-gnueabi --prefix=`pwd`/../install --without-ncurses --disable-makeinstall-chown make -j4 install ------------------------------------------------------------------------------------------------ --disable-makeinstall-chown 是為了解決下面問題 ------------------------------------------------------------------------------------------------ make  install-exec-hook make[4]: Entering directory `/joseph/LIN/parted/util-linux-2.21.2/term-utils' chgrp tty /joseph/LIN/parted/util-linux-2.21.2/../install/bin/wall chgrp: 正在更改 ‘/joseph/LIN/parted/util-l...

tmpfs : (virtual memory)

圖片
tmpfs 是一套以使用記憶體為基礎的檔案系統。 不同於 ramdisk 的最大差別在於,ramdisk 雖也使用記憶體,但它的屬於 Block device,使用前必須先 format(mkfs), tmpfs 使用上就很方便囉.. 直接 mount 就可以使用了 要使用需確認 kernel 有沒有勾選  Virtual memory file system support (former shm fs) 可以用下面方法使用: 1. mkdir /mnt/ramfs     vi /etc/fstab     none /mnt/ramfs tmpfs defaults 0 0     mount /mnt/ramfs     沒指定大小,預設是 ram 的一半。 2. mount -t tmpfs -o size=256m none /mnt/tmpfs     256m 是 256Mb 的意思。 3.  vi /etc/fstab     tmpfs /tmp tmpfs size=100m,mode=1777 0 0     編輯 fstab 開機時可以透過 mount -a 自動載入。 Reference: http://www.ibm.com/developerworks/cn/linux/filesystem/l-fs3/                        http://wiki.debian.org.hk/w/Tmpfs

HID report descriptor

圖片
The Items on report descriptor is classified into three categories. Main Items: - Input - Output - Feature - Collection - End Collection Global Items: - Usage Page - Logical Minimum / Logical Maximum - Physical Minimum / Physical Maximum - Report Size - Report Count - Report ID - Unit - Unit Exponent - Push / Pop Local Items: - Usage, Usage Minimun / Usage Maximum - Designator Index, Designator Minimum / Designator Maximum - String Index, String Minimum / String Maximum - Delimiter - Reserved Global and Local items describe the details of the format Main Item (Input, Output, Feature) generates report field(s) of specified type, detailed by global and local items. Collection / End Collection pair defines a block of report fields - which may be nested The value of each global item is carried over to all of following lines, until new value is defined. On the other hand, value of local item is cleared, when it is applied to a major item. This table illustrates the ...