Planet Linux of Taiwan

02月08日

AppleBOY's Blog's face
AppleBOY's Blog


縮小 展開

[C/C++] 指標相加 = ?or 相減 = offset

最近看到網路上討論 C/C++ 題目,某公司主管給新進人員面試的 C/C++ 考題,如下:

int main(void)
{
     int *a,*b;
     a=1;
     b=1;
     printf("%d\n",a+b);
     return 0;
}

請問上面這個題目,哪裡有出問題,這是面試官問新進人員的題目之一,看也知道這程式丟到 Dev-C++ 是不會過的,*a *b 都是宣告為整數指標型態,可是在 a=1 或 b=1 在 Dev-C++ 裡面是編譯不過的,但是那寫法是沒有錯的,就像你設定 a=0 或者是 a=NULL 是一樣意思,不過最好是不要這樣寫,assignment 這樣寫不太好,可以改成 a = (int *)1; b = (int *)1; 這樣就可以順利編譯通過,再來 printf(”%d\n”,a+b); 這行錯很大,指標相加會爆炸吧,如果程式這樣寫,不把 OS 搞掛,那我還會覺得懷疑呢,正確寫法是指標加上 offset(位移),這樣才是可以正確執行的,所以我們把程式改成下面:

int main(void)
{
     int *a,*b;
     a = (int *)1;
     b = (int *)1;
     printf("%d\n",a+(int)b);
     return 0;
}

最後的執行結果是 5,(int) b 就相當於 sizeof(*b) 也等於 sizeof(int *) 答案都是四,所以就是 1+4 =5,指標是不能相加的,只能透過 offset 方式來讓指標指向不同 base,但是如果是指標相減,那就是求 offset 的意思喔,看一下底下例子

int main(void)
{
    int *a,*b;
    a = (int *)0x5566;
    b = (int *)0x5570;
    printf("%d %d %d %d %d\n", a, b, (int)a+(int)b, a+(int)b, sizeof(int *));
    printf("%d\n", a - b);
    printf("%d\n", ((int)b - (int)a)/sizeof(int *));
    return 0;
}

要算 offset 也非常容易,只要先轉成 10 進位相減在除以 sizeof(int *) 這樣就可以求出結果了,a-b 除以四其實 -2.5 取補數,所以是 -3,如果是 b-a 就是整數3了,只是位移 3 個 bit,其實觀念就是這樣,指標位址不能相加,但是指標位址可以相減 = Offset,觀念大致上是這樣,最後補上完整程式,大家可以 run 一次看看就知道了

#include "string.h"
#include "stdlib.h"
#include "stdio.h"

int main(void)
{
    int *a, *b;
    a = (int *)1;
    b = (int *)1;
    printf("%d %d %d\n", a + (int)b, (int)(a + (int)b), (int)a + (int)b);
    a = (int *)0x5566;
    b = (int *)0x5570;

    printf("%d %d %d %d %d\n", a, b, (int)a+(int)b, a+(int)b, sizeof(int *));
    printf("%d\n", a - b);
    printf("%d\n", ((int)b - (int)a)/sizeof(int *));
   
    a = (int*)0x1000;
    b = a + 3;
    printf("%d %d %p %p \n", a, b, a, b);
   
    system("pause");
    return 0;
}

Related View

[Input Style] What's Over-the-spot, on-the-spot ... etc?

Last Friday I saw an ibus issue about input style support in ibus-anthy. The maintainer, Fujiwara insist that editing in the candidate window is not "over-the-spot".

Ok, time to do literature review:
According to sun and Mozilla, preedit area is INSERTED into the inputing spot in on-the-spot, the text after the input spot WILL be pushed to the right when preedit area expend; while preedit area is PUT OVER the inputing spot in over-the-spot mode, the text after the input spot WILL NOT be pushed to the right.

Reference from IBM tells different story. Over-the-spot, as the page states, is the mode that candidate window closely followed the input spot, but the preedit string is formed in candidate window.

Java also has its own definition. Below-the-spot is the term for IBM's over-the-spot.

Summary:


After the intensive web search and discussion, we conclude that we should use some thing like "Embedded preedit in client application" to avoid confusion.

黑眼珠's face
黑眼珠


縮小 展開

openSUSE Survey 2010

http://news.opensuse.org/2010/02/07/opensuse-survey-2010-participate-now/
現在就去貢獻您的意見
讓 openSUSE 有機會更好
還可以參加抽獎喔(獎品是不多啦)

02月07日

whatup's face
whatup


縮小 展開

將 Blog 系統從Lyceum轉換到Wordpress Mu

在支持了這麼久的 Lyceum 後,最後終於受不了將 blog 系統更換成 Wordpress Mu 了。而之所以會這樣更換,是因為 Lyceum 上一個 Release 的版本是在 2008 年 6 月 4 號了,然而已經完全跟不上最新的 wordpress 。

花了一個晚上,將一些朋友的 blog 手動匯出成 xml 檔,並且再幫他們匯入到目前的 MU 上。另外還有一些小問題發生,例如原先文章中有寫到程式的部份,其中的 PHP Code 被 filter 掉,這部份的問題比較大要找時間再來修了。還有留言的部份,同一篇文章的留言好像只有匯入第一筆而已。

也順手更換了佈景主題,這次的主題有點黑暗,不過還滿喜歡目前這種帶點黑暗的感覺。

不過整體來說,wordpress mu 操作界面清楚了許多, widgets 也改成內建了,有更多的 Plugins & widgets 可以使用。所以用了新版的 Blog 軟體後,說不定比較有動力發表文章呢?!

02月06日

chihchun's face
chihchun


縮小 展開

Thinkpad 小紅點設定

Thinkpad 的小紅點在 Linux 上似乎一直沒有完善圖形化介面的設定工具。若要設定的話,常得參考一些指令設定

驅動程式預設的速度、靈敏度都太低,推一陣子手指就累了,也無法按著中鍵移動小紅點來捲動視窗。不甚好用,稍做一些設定的筆記,作為未來參考。

在 GNU/Linux Debian/Ubuntu 上有數種機制可以更改小紅點設定,若是新手使用,大概會被 sysfs, udev, hal, DeviceKit, pm-utils, xorg.conf, xinput 等術語搞得一頭霧水。你若不想弄懂這些難解術語,也不想更改 xorg.conf,最快的作法是以 sudo 在虛擬終端機執行以下指令

#!/bin/sh
# 游標速度,可調整數值。大為快,小為幔
echo -n 120 > /sys/devices/platform/i8042/serio1/speed
# 靈敏度,最高應為 255
echo -n 250 > /sys/devices/platform/i8042/serio1/sensitivity
# 按小紅點為選取,1 為啟用,0 為關閉。
echo -n 0 > /sys/devices/platform/i8042/serio1/press_to_select

xinput list-props '"TPPS/2 IBM TrackPoint"'
xinput set-int-prop '"TPPS/2 IBM TrackPoint"' 'Evdev Wheel Emulation' 8 1
xinput set-int-prop '"TPPS/2 IBM TrackPoint"' 'Evdev Wheel Emulation Button' 8 2
xinput set-int-prop '"TPPS/2 IBM TrackPoint"' "Evdev Wheel Emulation X Axis" 8 6 7
xinput set-int-prop '"TPPS/2 IBM TrackPoint"' "Evdev Wheel Emulation Y Axis" 8 4 5
xinput set-int-prop '"TPPS/2 IBM TrackPoint"' "Evdev Wheel Emulation Axes" 8 6 7 4 5
xinput list-props '"TPPS/2 IBM TrackPoint"'

這些指令可以幫你把 TrackPoint 的速度、靈敏度調高,並驅動中鍵模擬滾輪功能。頭三行 echo 指令需以 root 權限執行,你可自行調整偏好的數值。後面幾行 xinput 指令,必須在 X 視窗下執行。(意即,你不能拿到 console 下面來跑)

這些指令每次重開機或休眠後都需重新執行一次。你若嫌麻煩,目前最簡易的設定機制應該是寫成 udev rules,作法以 root 執行指令如下

# cat > /etc/udev/rules.d/90-trackpoint.rules <<EOF
# SUBSYSTEM=="serio", DRIVERS=="psmouse", ATTR{press_to_select}="0", ATTR{sensitivity}="250", ATTR{speed}="120"
DEVPATH=="/devices/platform/i8042/serio1", ATTR{press_to_select}="0", ATTR{sensitivity}="250", ATTR{speed}="120"

ACTION!="add|change", GOTO="xorg_trackpoint_end"
KERNEL!="event*", GOTO="xorg_trackpoint_end"

ENV{ID_PATH}!="platform-i8042-serio-1", GOTO="xorg_trackpoint_end"

ENV{x11_options.EmulateWheel}="1"
ENV{x11_options.EmulateWheelButton}="2"
ENV{x11_options.XAxisMapping}="6 7"
ENV{x11_options.Emulate3Buttons}="0"

LABEL="xorg_trackpoint_end"
EOF

這段程式碼,參考 ThinkWiki 網站理論上,會在你開機以及重休眠模式啟動時,自動套用小紅點速度設定與模擬滾輪設定。

實際上,因為一個已知的 #549379 udev/kernel 問題,滑鼠的速度設定無法自動套用。暫時可以先用前段的 echo/sysfs 方式解決。

這是一篇 Tip.

雨蒼的筆記本's face
雨蒼的筆記本


縮小 展開

好文一篇:Re: [問卦] 有沒有念資訊一定要討厭windows的八卦

這篇文章看了覺得寫的不錯,因此經過原作者同意後,就轉過來了。文章代碼(AID): #1BR7wzrt (Gossiping) 作者 Freak1033 (金が信念! XD) 看板 Gossiping 標題 Re: [問卦] 有沒有念資訊一定要討厭windows的八卦 時間 Sat Feb 6 04:25:29 2010───────────────────────────────────────※ 引述《HollisterCo (海鷗)》之銘言:: 身邊有些朋友念資訊的: 但是莫名其妙的就會說你怎麼還在用微軟的東西: 媽的爛死了之類的 你看linux都不會當機 也不會中毒: 用linux才屌!! 用甚麼GUI 弱者才再用: 強者都用CLI!!!!: 是不是真的打打指令就比較厲害??????? Q_Q唉呀,

02月05日

OSDC's face
OSDC


縮小 展開

[Schedule] Polyglot Programming and Web Security

Polyglot is a computer program written in a valid form of multiple
programming languages.
For example, print"Hello",0?"Ruby":"Perl","

!\n" is a Perl/Ruby polyglot program
which returns different result each languages using difference of
handling boolean value.

Applying these techniques makes five language polyglot program like as
following:
----------------------------------------------
#include/*
q="""*/
int main() {putchar('C'); if(sizeof('C')-1);
else {putchar('+'); putchar('+');}} /*=;
print'Perl'#";print'Ruby'#""";print'Python'#*/
----------------------------------------------
$ perl a.cpp
Perl
$ ruby a.cpp
Ruby
$ python a.cpp
Python
$ gcc -xc a.cpp && ./a.out
C
$ cl.exe a.cpp
$ a.exe
C++

And applying more growth of these techniques makes obfuscated program
with just only symbols
for Perl / Ruby / JavaScript and so on like as:
http://developer.cybozu.co.jp/takesako/2009/07/polyglotrejectk.html

Moreover I'll show the Perl / Ruby / PHP / JavaScript program embedded
in GIF / JPEG images.
And we can make a x86 executable code in ascii string which includes
just only symbols.

all your base32 are belong to us
http://conferences.yapcasia.org/ya2009/talk/2226

[轉載]Fedora 下安裝 PPStream

在Linux下一直沒有一個整合性佳的網路電視軟體,用過windows下的PPStream的朋友應該都會覺得很好用,其實PPStream去年出現了for Linux的版本,並不是用wine來驅動的. 因為有朋友問起,所以轉貼一篇大陸網友的安裝方法以供有需要的朋友參考.

NFS Server reason given by server: Permission denied 故障排除

NFS 服務是標準的 Server / Client 的架構,若當用戶端掛載 export 的裝置出現 NFS Server reason given by server: Permission denied 錯誤訊息時,該如何排除:

  • 確認 Server端的 NFS export狀態 (例如:有否把 Client 設定在可存取的主機清單中等)與服務是否啟動
  • 確認 Server/Client端的 portmap 服務狀態,與使用 rpcinfo -p nfs 來檢視  Server 端相關 RPC 服務狀態
  • 確認是否Server開啟了防火牆或是SELinux,沒有設立批配的規則導致 Client端無法存取
  • 檢查一下是否 /proc/fs/nfsd 沒有被掛載起來,預設系統啟動時會自動將此裝置掛載,但可能在 init 初始化時失敗或是其他原因導致掛載失敗,若在主機無法重新開機時可以暫時於 /etc/fstab 添加下列描述進行手動掛載:
    none /proc/fs/nfsd nfsd auto,defaults 0 0

02月04日

chihchun's face
chihchun


縮小 展開

Linux 上試用 TECOM WiMAX 網路卡

上個月 (2010/01) VMAX/崴邁司 在台北開台期間,舉辦了一場體驗活動。雖然興致勃勃的去申請了,不過顯然重度使用者不在 VMAX 的規劃範圍之內,因此我並沒有被選到試用。幾位朋友倒是幸運的取得試用資格。

目前 VMAX 提供的 USB WiMAX 網路卡是 TECOM 的 WM5123M-2G5. 網頁上註明只支援 Windows 作業系統。基於好奇的心理,也跟朋友借了網路卡來玩一個禮拜,在北市的古亭、公館一帶試用,上下傳速度都還不錯。

不過自己比較感興趣的是否有 Linux 的驅動程式。稍早的測試是在 Linux 上,透過 VirtualBox 跑 Windows 來連線。實際上並未能在 Linux 上直接使用該網路卡連線。

查了一下知道這款設備使用 GCT 的解決方案,應該是 GDM7205,日本的 MODACOM 也利用此晶片開發了 UD01SS/UD03SS/MW-U2510/BDSS01 等產品。其中 UD01SS 也是日本 UQ WiMAX 搭售的產品之一,在 UQ WiMAX 的產品網頁上,其實也提供 Mac OS 的驅動程式。所以你若使用 Mac OS, 或許可以在此找到可用的驅動程式。

根據我的紀錄,UD01SS 使用的 USB 產品編碼 (vendor id, product id) 為 1076:7f40 或 1076:7f00. 如果開發商/製造商連編碼都懶的改的話,八成驅動程式也可共用。;-) 只是 Connection Manager 不知道能不能讓你認證/連上不同的 ISP 就是。

至於 Linux 下的使用,經過測試已經可以利用 usb_modswitch 來將初始的 ZeroCD (含有 Windows 驅動程式) 模式改為 Network 模式。不過仍缺了連線用得工具與相關的 userland 程式,所以暫時間還是無法使用。

目前開放原碼的 WiMAX 支援,只有 Intel 釋出的 Linux WiMAX Software Stack。其中最重要的用以認證的 Supplicant 暫時還無法是開放原碼。因此若要讓開源社群使用,必要得有 Supplicant 的支援才行。

另外一點,現有 WiMAX 晶片供應商如 Beceem, GCT, Sequans, Runcom 等,據聞所使用的 Driver Software Stack 都大不相同。因此恐怕未來若要整合不同的網路卡驅動程式,會有陣過渡期。

目前社群中,除了 Intel 的驅動程式外。另外一個相對開放原碼的是 Samsung 所製造的網路卡,已有一針對 Samsung 網卡所反組譯的 madWiMAX 軟體計畫。

GCT/TECOM 疑似違反 GPL 授權

另外在追查可能的驅動程式資訊時,macpaul 告知他發現 Winodws 安裝目錄中,包含了一個神秘的 Image 檔案。疑似包含 Linux 核心與相關程式,在驅動時傳到網卡上執行。

手癢稍微追蹤了一下,發現內部的確包含了一組 linux kernel 與一組 cramfs 的 rootfs. 再往裡面翻進去發現 busybox 與一應為處理 OMA-DM 功能的私有軟體。

根據 VMAX 發給消費者的資料中,並沒有任何書面資料或電子檔說明內含 GPL 原始碼一事。相關發現已經先行發至 gpl-violations.orglegal 郵遞論壇。目前對此事件暫無進一步計畫。

Review on "Chinese Eye Tracking Study: Baidu Vs Google"

Review on "Chinese Eye Tracking Study: Baidu Vs Google"

Today I see an "interesting" post about Eye Tracking Study about Google and Baidu. "interesting" blog post. That post does make some valid points, such as reasoning in Q: What’s the difference in user experience between Baidu and Google?
and first two factors in Q: Why choose Baidu?.

However, that post has several major reasoning flaws:
1. The third factor in Q: Why choose Baidu? is misleading. Browser multi-tab viewing mode is required by all over the world, not only for Chinese.

2. The actual third factor is G.F.W. Baidu follow Chinese policy closely, and usually does show the target pages which are blocked by the firewall; Google on the other hand, does not comply as much as Baidu does, thus it's likely that the search results lead to "dead" links, which upsets ordinary end users.

3. It claims that Chinese is hard to skim through because Chinese has too many characters without space to split the meaning in comprehensible way. It even tried to emphasize this point by providing following all-uppercase, no-space paragraph:

TOTRYTOPUTINAWESTERNCONCEPTUALFRAMEWORK,IMAGINEHOW DIFFICULTITWOULDBETOSCANMEANINGFROMTHISPARAGRAPHIF OURALPHABETWASEXTENDEDTO2000CHARACTERS,PRESENTEDIN BLOCKLETTERSANDALLTHESPACESBETWEENWORDSWEREREMOVED


(To try to put in a Western conceptual framework, imagine how difficult it would be to scan meaning from this paragraph if our alphabet was extended to 2000 characters, presented in block letters and all the spaces between words were removed.)

That reason is quite silly. If that is true, Chinese would have abandon that writing system eons ago, as few can understand and willing to pass the writing through generations.

Actually, like comment 1 said, most concepts in Chinese can be represented in no more than two characters, native name seldom exceed 3 characters; European languages on the other hand, often require you to look through much more characters for a meaningful word.

Comparing display length, Chinese text looks much shorter than English, yet carries the same amount of information. Using his example:

(To try to put in a Western conceptual framework, imagine how difficult it would be to scan meaning from this paragraph if our alphabet was extended to 2000 characters, presented in block letters and all the spaces between words were removed.)

(以西方的概念架構來說,很難想像如果我們的字母增加至2000個,全以大寫顯示,移除空白的話,要怎麼讀這段文章。 )

As you can see, it doesn't even occupy half the visual area if using the same font size. Shape-eyed readers might also notice that punctuation marks provide necessary space for scanning the meaning of the paragraph. :-P

Anime "Red pig" also provides another visual comparison among major languages in the beginning. :-)

02月03日

AppleBOY's Blog's face
AppleBOY's Blog


縮小 展開

Google Chrome 支援超過 40,000 Extensions! with Greasemonkey

看到 Google Chrome Blog 發表的Google Chrome 支援超過 40,000 Extensions!,當 Google Chrome 瀏覽器剛出來的時候,造成 Web Developer 一些震撼,因為 Chrome 強調的是擁有快速的 Javascript 引擎,以及快速的啟動,Fast start-up、Fast loading、Fast search,也因此讓很多設計網站的工程師必須把 Chrome 的支援性考慮進去,但是由於剛推出的瀏覽器,沒有任何外掛功能,我本身用 FireFox 瀏覽器很多年了,FireFox 的附加元件讓許多程式設計師投入開發,也製造出很多方便的附加元件來讓大家使用,例如:FireBugGmail ManagerGreasemonkey…,然而 FireFox 最方便的就是 Greasemonkey 此附加元件,使用者可以撰寫簡單 Javascript 語言來跟指定網站進行元件控制,現在 Google 工程師聽到我們的聲音了,Google Chrome 4 加入 Greasemonkey user scripts 功能,大家可以到 userscripts.org 下載超過 40,000 script 安裝到 Chrome 瀏覽器。您可以在 blogger 使用 emoticons,大家可以去參考看看。

由於 Chrome 支援了 Greasemonkey,所以趕快把 FireFox 所安裝的 script,也安裝到 Chrome,可是我發現之前 DarkKiller 大神寫的 Wretch Album Expander 已經不能用了,所以我將它實做到 Chrome,可以從這裡下載安裝:Wretch Album Expander for Google Chrome or FireFox,平時自己偶而會看看無名小站,所以也是方便自己觀看照片,此 script 也可以安裝在 FireFox 喔。這樣大家就不用再看圖片還要一張一張慢慢點,只要負責按換頁就可以了 ^^。

來測試看看,隨便找一本無名相簿:馬甲‧小葵 ,畫面:點我觀看

Related View

rpmlint tip

This tip is very simple, I should have RTFM instead of Googling.

If you don't know the exact meaning of an error or warning message,
either use -i for displaying the detail description of error/warning message, or use -I for checking individual error message.

chihchun's face
chihchun


縮小 展開

Java JVM 的 Dual Stack/IPv6 連線問題

大約從 J2SE 1.4/1.6 開始,Sun 所釋出的 Java runtime 開始支援 IPv6 連線功能。一般的 Linux 的套件系統 也開始支援 IPv6,許多系統預設是同時開啟 IPv4/IPv6 或稱為 Dual Stack 網路功能。

基本上,鼓勵各種軟體開始移植到 IPv6 網路上是一件好事。Java runtime 若在 dual-stack 的機器上,預設走 IPv6 位址,因為 IPv6 位址可同時走 IPv4/IPv6 網路。不過問題在於,若一般的 GNU/Linux Debian, Ubuntu 系統,預設會啟動 IPv6 介面,無論你所在網路是否有 IPv6 路由。

於是,你若在 Linux 上使用一些 Java 寫成的網路軟體,如 JDownloader 等,很有可能發生軟體運作後,卻什麽地方都連不上的症狀。解決辦法一是關閉 IPv6 網路功能,一則是利用 JRE 的參數,改為預設使用 IPv4 網路。

檢查 IPv6 是否驅動

首先,你若想確認是否開啟了 IPv6 網路,可於終端機下使用此指令判斷

$ ip addr|grep inet6

若出現了 inet6 之位址,即為開啟了 IPv6 網路。

你若想快速的關閉 IPv6 功能,可以利用 root 執行 ip 指令,直接刪除 inet6 位址

/sbin/ip addr del <ipv6address>/<prefixlength> dev ethX

舊版核心

在舊版核心,IPv6 功能是以模組方式存在,妳可以透過更改 modprobe (module-init-tools) 的設定,讓系統不載入對應驅動程式。關閉的方式很簡單,請修改 /etc/modprobe.d/ 之設定,如以 root 執行以下指令

# cat > /etc/modprobe.d/00local.conf <<EOF
alias net-pf-10 off
alias ipv6 off
EOF

更改之後,重新開機即可關閉 IPv6 功能。

新版核心

在新版的 Debian/Ubuntu 中使用 2.6 核心,因為內建 IPv6 驅動程式, 你得利用開機參數 (cmdline) 關閉之。作法是修改 /etc/default/grub 檔案,更改 GRUB_CMDLINE_LINUX_DEFAULT 一行,加入 ipv6.disable=1,如

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 quiet"

修改完畢後,請用 root 執行 update-grub 後,重新開機。

JRE 參數

另外一項作法是更改 JRE 參數,你若知道啟動該軟體的 shell script 位於何處,可新增一參數如下

$ java -Djava.net.preferIPv4Stack=true Main

這樣就可以要求 JVM 預設使用 IPv4 stack.

這是一篇 Tips.

修訂紀錄 (20100207): 補充利用 iproute 關閉 ipv6 方法,說明新舊版核心處理方式。

ppc's face
ppc


縮小 展開

linux 中使用 pptp client 連線到windows vpn server 包含 mppe-128 支援

先說一下 Windows VPN ( PPTP ) Server 連線所需要的通訊協定
* 驗證身份使用 MS-CHAP V2
* 加密使用 MPPE
* 壓縮使用 MPPC

要成功建立連線,至少必須支援 MPPE 才行 ( MPPC 似乎選擇性的?? )

安裝所需軟體:
pptpclient
ppp

kernel 必須支援的選項:
CONFIG_PPP
CONFIG_PPP_ASYNC
CONFIG_PPP_MPPE

在 Gentoo 中 ppp 有一個 mppe-mppc 的 USE,如果需要啟動 MPPC 的話才要使用這個 ( not sure !)

設定 ppp
連線模式與帳號密碼
使用 CHAP 認證,修改 /etc/ppp/chap-secrets 依序輸入 "帳號、*、密碼",例如:
username_ppc52776 * password_ppc52776

peer 雛型可先用 pptp-command 建立 ( /etc/ppp/peers/sinica )
然後加入關鍵的一行設定
pty "pptp 140.109.17.129 --nolaunchpppd"
一定要有這行可以正常連線 !!
再加上給該 tunnel 的額外設定
ipparam sinica

之後可以先用
# pppd call sinica logfd 2 nodetach
看看有沒有辦法正常連線
Using interface ppp1
Connect: ppp1 --> /dev/pts/7
CHAP authentication succeeded
MPPE 128-bit stateless compression enabled
local IP address 140.109.17.146
remote IP address 140.109.17.141
這樣就表示可以了

測試成功了,往後要連線就可以用
# pon sinica
斷線用
# poff

我的設定檔:

pty "pptp 140.109.17.129 --nolaunchpppd"
lock
refuse-eap (預設會用這個做 auth, 但是現在已經都不能用了)
#require-mschap-v2 (這個要拿掉,不然會變成你要求對方也要跟你認証)
require-mppe-128
name crchang
ipparam sinica

route 設定
編輯 /etc/ppp/ip-up.d/sinica.sh
#!/bin/sh
# $1 = interface name (e.g. ppp0)
# $2 = tty device
# $3 = speed
# $4 = local IP address
# $5 = remote IP address
# $6 = ipparam (user specified parameter, see man pppd)

if [ "$6" == "sinica" ]; then
#vpn server ip 必須還是走本來的 gateway
route add -host 140.109.16.129 gw 192.168.1.10
#屬於中研院網域的 ip 走這個 ppp0 出去而非預設的 eth0
route add -net 140.109.0.0/16 dev $1
fi

ps.
在 Linux NAT 下, 若要用 PPTP 連遠端的 VPN Server,
必需加掛這兩個 pptp module
modprobe ip_nat_pptp (這個似乎不一定要?)
modprobe ip_conntrack_pptp
否則 Windows 在連線時會出現此錯誤:
錯誤 721: 遠端電腦沒有回應。請按 [其他資訊] 或搜尋這個錯
誤碼的說明及支援中心,以取得進一步的協助。
(參考來源:http://pank.org/blog/2008/09/pptp-under-linux-nat.html)

02月02日

chihchun's face
chihchun


縮小 展開

在 Linux 上移除 CNNIC 憑證

一月底開始,一些朋友開始討論 Firefox 3.6 中,將置入 CNNIC 的 CA 憑證。這件事情是去年年底,CNNIC 對 Firefox 申報納入 CNNIC 的憑證 (#476766),目前已於 3.6 版中內建 CNNIC 憑證。

目前此事已經在 Mozilla Security Policy mailing list 公開討論,在華人網路社群也引起一陣騷動。像是 AutoProxy 等社群都提出 CNNIC CA:最最最嚴重安全警告!。在原提案 #476766 中亦有人整理了一些客觀事實。

不過根據我主觀的看法,奉勸所有人盡快移除 CNNIC 相關的 CA 憑證!CNNIC 就是中國網際網路絡信息中心,是一個中國的非營利組織,提供中國網際網路的網域名稱、網段管理。

CA 憑證對於瀏覽器使用者而言,可以用來辨識特定網域是否為合法組織,部份瀏覽器功能甚至依據有否憑證,對網頁開啟進階存取權限。前提是 CA 維持善良管理人義務,嚴格管理所核發的憑證、簽章。

CNNIC 過去最大的爭議即是曾經發布過中文上網官方版軟體,名為提供中文網址導引服務,實質則包含流氓軟體的功能,主要功能是一般輔助上網軟體,但核心卻用 rootkit 技術讓你無法刪除,與木馬/病毒程式一般。雖說這只是一項前科,但是中國政府持續拿著民族主義、國家安全為藉口,實施數種網路管制,甚至滲透國外企業、政府網路,根本是合法的網路流氓。而 CNNIC 背後支持的政府組織是中華人民共和國工業和信息化部中國科學院中國科學院計算機網絡信息中心 等中國政府組織。很難說,哪一天 CNNIC 不會被控制作為攻擊工具之一。

除了 CNNIC 自行發布的 CA Cert Root 外,其實 CNNIC 也已經取得 Entrust.net 所發布的次級憑證。建議所有台灣政府單位,一律移除 CNNIC 相關憑證。

若你覺得此事關係重大,可以以投票方式附議 Bug 542689 – Please Remove “CNNIC ROOT” root certificate from NSS,提高該問題的被重視程度。

跳板風險

其實 Mozilla 先前也曾經遭遇過亂搞的安全憑證公司。原則上,任何人要申請特定網域的簽章,必須提供書面資料,證明你是該網域的擁有者。因為 SSL 憑證一個主要功能是防止釣魚網站欺騙一般消費者,若使用假冒的憑證,使用者很容易就發現網址異常。

若安全憑證公司絲毫不做基本的驗證,任何人都可以申請想仿冒的網域,然後以中間人攻擊 (MITM) 詐騙你交出個人資料。想像,你收到一封 PCHOME 的廣告,連到一個假的網站,這個網站提供了完美的 SSL 憑證,瀏覽器沒有提示你任何異常,除非你刻意去點選確認簽章,否則很自然就會上當。

Mozilla 的事件起因,是有人回報一安全憑證公司透過廣告郵件推銷新的服務。但這個憑證公司的服務卻允許你隨意購買任一網址的簽章,於是你可以購買並假冒任何網站。Eddy Nigg 寫了一份詳盡的說明,當時並做了一個驗證概念的 Mozilla.com 憑證。在事情曝光後,Mozilla 已撤除這組組憑證了。

移除 CA 憑證

驗證方法是開啟 CNNIC 的網址衛士 (使用 Entrust.net) 或 CNNIC 的 ENUM 試驗平台 (使用 CNNIC Root Cert)。若你的瀏覽器絲毫不給警告的就讓你存取,你的系統即已安裝 CNNIC 憑證。

在 GNU/Linux Debian, Ubuntu 上,系統保持一份共用的 CA 憑證,許多網頁工具如 Firefox, curl, wget, Chrome 均共用同一組設定。因此最簡便的方法便是關閉系統上有問題的憑證。

作法是以 root 在終端機內重新設定以下指令

# dpkg-reconfigure ca-certificates

找到 mozilla/Entrust.net_Secure_Server_CA.crt 一列,反選取之,選擇確認即可。或者直接編輯 /etc/ca-certificates.conf,一樣找到此行後,於該行開頭加入驚嘆號 (!),然後重新以 root 執行一次 update-ca-certificates.

另外,你也得到瀏覽器手動刪除原已匯入之憑證。注意,若該筆憑證下方有多筆簽章,你必須刪除全部簽章。見圖

按下 Delete, 重新啟動 Firefox,如此即可移除相關的 CA 憑證,其他瀏覽器需比照辦理。你若使用其他作業系統,請參考 Felix Yan 所整理之 從「受信任的根證書」裡趕走CNNIC

以下補充說明 (20100203):

許多網友認為,即使系統有此憑證,也不至於影響系統。

事實是,若有此憑證,你將被剝奪警覺的能力,像是痛得知覺消失一樣。當攻擊事件發生時,唯一可以主動提示你的 SSL 機制也可能失效。在中國網路長城的「內部網路」,網址被攔截、轉換是很平常的事件,即使你在網外,也可能在網站轉址攻擊事件大規模網頁綁架轉址發生時,變成受害者。

除了網址之外,這份憑證也可用於不同的連線服務加密認證。我並不想因為系統上存有一份無須有的 SSL 憑證,造成我日常認為經加密而安全的 SMTP/IMAP/IM 「可能」偷偷地遭到攔截、擷取資料。而我卻一無所知。

人,機器,機器人:我看 Sikuli

每次回台中,在媽媽用來跟妹妹們講 Skype 的電腦旁邊,我總是會多看那張黃色的便利貼兩眼。

上面其實很簡單的寫了 功能 > 選項設定 > 視訊設定 之類的字眼,看來應該是讓老媽記得怎麼樣打開視訊之類的。

每次看到這個,我都會想:「如果充當親友的 tech support ,不需要每回都:『你去點選右下角的 開始 ,再點選 程式集 ,再點選圈圈跟叉叉......』,能夠自動操作這些步驟,該有多夢幻啊?」

==
一家四口去高雄玩了一趟回來,打開 RSS Reader 才發現,vgod 跟另一位 Tom Yeh 弄的 Sikuli 變成最近的大熱門:
Change The World!
Sikuli帶來的意義與無限的潛力

(其實還有更熱門的科技新聞,搞得大家整天都在 唉 來 唉 去,不過那個 唉 對我來說,基本上 iHavenone, iHavenoidea, 所以 iWillnotcomment)

先把在 vgod 網誌的留言搬回來:

想要說的話太多了, 自從看到 Sikuli, 基本上腦內大爆炸, 第一次得要嘗試用 mindmap 先打草圖才能夠發文談 Sikuli 了

如果以 Client / Server 的角度思考, 傳統上, 能夠自己寫 Server 的人, 在 Client 端擁有最大的掌控權(這是有一次我聽 Jeremy Allison比較 Novell NCP 跟 SAMBA 團隊要使用微軟的 SMB 通訊協定的差別時, 他做的比較)

但是現實生活裡, 就算你是擁有十八般武藝的程式設計師, 同時掌控 Server / Client 也是可遇不可求的機緣. 以我個人以前做網管收告警(Fault Management)的經驗, 基本上我們是很賤(誤)的, 伺服器吐出來什麼樣格式的告警, 我們都得想辦法吃下來 XD

在”只能從 Client 端努力”的前提下, expect 這個基於 Tcl 的 script 處理的是文字介面, 你之前介紹過的 Chickenfoot 處理的是網頁, 現在 Sikuli 把更多可能性交給了更多人 :D

==
不過這樣 clicking monkey 就要失業啦 :p


[演進]
我以前主要用的是 expect 網管的暗黑系法術:用 expect 和 autoexpect 寫 BBS 機器人,衝上站次數,在 terminal 處理一些命令列的東西很好用(而且還有 autoexpect 可以把你的操作過程 錄 下來,變成 expect 腳本)

後來看到 vgod 介紹 ChickenfootWeb上的萬能瑞士刀: Chickenfoot,看起來處理網頁自動化操作很不錯(不過這是一個 Firefox 的延伸套件,如果你想操作的網頁只能用 IE 那就 !@#$%)

這次的 Sikuli ,直接用圖像的方式,以 Python 語法(其實好像是 Jython)來指揮電腦,基本上跟文章一開頭說的夢幻操作方式非常像呢!



vgod 有提到 Sikuli 也有類似 auto expect 的設計了:


Sikuli Script只是這一串研究的開端和基石,在這之上其實我們還做了很多東西。例如說我們已經有一個能錄製螢幕和使用者動作的程式,可以把使用者的動作自動轉換成Sikuli Script,也就是說使用者一行程式都不用寫,只要把想做的步驟做一次,程式碼和螢幕截圖就會自動產生出來讓你修改或直接使用。用這個錄製程式,我們可以輕易的在現有的GUI系統上觀看全系統的操作歷史,甚至是自動redo某一部分操作。


[應用]
稍微搜尋了一下,除了 工作自動化 之外,有網友提到可以拿來做 操作教學 ,或者 UI測試。

[功能]
我個人已經試用 Sikuli ,用來操作自己工作上會用到的一個系統,大概花了不到一個小時,就做到可以查詢我要的資料,雖然距離我的目標(輸入資料)還有點遠,不過我對 Sikuli 的第一印象是:真的很直觀!(不過我找了半天,才知道滑鼠 double click 要寫成 doubleClick ,第一個 C 要大寫!)

不曉得 Sikuli 能不能對檔案做讀寫?

以我的需求來說,我們每個月有一些固定的行程(幫客戶做系統定期保養)必須要填進工作日誌系統:客戶機器序號是固定的,但是實際到場的日期跟時間當然每個月不一定,如果我可以在一個簡單的 .txt 或是 .csv 裡面把這些資料準備好,然後讓 Sikuli 來開檔、讀檔,然後跑個迴圈,幫我登入工作日誌系統 key in ,那我只要中午吃飯的時候丟給 Sikuli 去跑就行囉!

另外, Sikuli 呼叫外部程式的 switchApp 指令,我還要研究一下怎麼叫出 Windows 上的 IE ,雖說理論上可以用圖形的方式達成,不過能夠明確用指令列的地方,我還是希望用指令就好。

[評論]
thinker 在 這並不是一個創新 這篇有提到,其實以前也有類似 Sikuli 的東東 :D

至於我自己嘛,我還是引用前面 Jeremy Allison 的角度,如果你可以跟源頭(Server端)溝通,讓你的工作更輕鬆,那你不需要用到 expect, chickenfoot, Sikuli 這一類的工具。(就算要用,我也傾向先看看能不能用 expect 這種指令列的,不行才退而看看是不是能用 chickenfoot 這種透過網頁的,最後才會用 Sikuli 這種抓螢幕硬上的)

當然,就算是備而不用,工具也是越多越好囉 :D

Cornelius' Blog's face
Cornelius' Blog


縮小 展開

Vim - glob 應用

臨時需要將一目錄下所有的檔案插入為 img tag ,所以臨時直接在 vim command line 下寫了 這樣的東西來應付:


整理了一下:

erin's face
erin


縮小 展開

New Bluetooth Object Push Profile in Android 2.0 (Eclair)

From Android developer website, they said Android 2.0 provides two new Bluetooth profiles: Object Push Profile (OPP) and Phone Book Access Profile (PBAP). Seeing is believing. Where is the meat? ha, I found they finally released their Bluetooth application source code. Therefore, I tried to verify OPP in Beagle board. :D

As usual, I read Build-from-Scratch wiki page and download code from 0xdroid project with beagle-eclair branch. LIke beagle-donut, I can use USB mouse, keyboard, mount a SD sdcard, use USB networking, and then I turn Bluetooth on. It's very easy to set up the working environment with 0xdroid.

Check Bluetooth application source code and install it in Beagleboard


cd packages/apps
git clone git://android.git.kernel.org/platform/packages/apps/Bluetooth.git
cd Bluetooth
git checkout -b eclair remotes/origin/eclair
git pull
source ../../../build/envsetup.sh
mm
adb install ../../../out/target/product/beagleboard/system/app/Bluetooth.apk


Trace related log
When we saw the log like below, it means it provides OPP service in RFCOMM channel 12 and PBAP service in RFCOMM channel 19.

I/bluedroid( 736): Starting hciattach daemon
I/bluedroid( 736): Starting bluetoothd deamon

I/bluetooth_ScoSocket.cpp( 797): Listening SCO socket...
V/BtOpp Service( 933): Service onCreate

V/BtOpp Service( 933): Starting RfcommListener in 9 seconds
V/BtOpp Service( 933): Service onStartCommand

V/BluetoothPbapService( 933): Pbap Service onCreate
V/BluetoothPbapService( 933): Starting PBAP service
V/BluetoothPbapService( 933): Pbap Service onStartCommand

D/BluetoothService( 736): Registering hfag record
D/BluetoothService( 736): Registering opush record
D/BluetoothService( 736): Registering pbap record

V/BluetoothPbapService( 933): Handler(): got msg=1
V/BluetoothPbapService( 933): Pbap Service startRfcommSocketListener
V/BluetoothPbapService( 933): Pbap Service initSocket
V/BluetoothPbapService( 933): Succeed to create listening socket on channel 19

V/BtOpp Service( 933): start RfcommListener
V/BtOpp Service( 933): RfcommListener started
I/BtOppRfcommListener( 933): Accept thread started on channel 12


Receiving and sending out data via Bluetooth

Currently, it only accepts few media types, like image, video, audio, text/plain and text/html and it should have the extension name. It cannot accept vcard and vcalendar. But we can modify few lines in 'Bluetooth/src/com/android/bluetooth/opp/Constants.java ', then it can store vcard files. One more problem, there is no matched application can view *.vcf file. I guess I can reference with previous beagle-donut code to fix it. All incoming files are stored in /sdcard/bluetooth folder. Also, there is a db file to record all Bluetooth application actions.

# cd /sdcard/bluetooth
# ls
08042009068.jpg
08042009068-1.jpg

# cd /data/data/com.android.bluetooth/databases
# ls
btopp.db
# sqlite3 btopp.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
android_metadata btopp
sqlite> select * from btopp;
1||08042009068.jpg||image/jpeg|1|00:18:C5:42:18:78|1|1|493|394450||946685154325|0
2|content://media/external/images/media/1|08042009068.jpg|/sdcard/bluetooth/08042009068.jpg|image/jpeg|1|00:18:C5:42:18:78|1|1|200|394450|394450|946685200379|1
3||olv.vcf|/sdcard/bluetooth/olv.vcf|text/x-vcard|1|00:18:C5:42:18:78|1|1|200|68|68|946685305125|2
4|file:///sdcard/bluetooth/08042009068.jpg|08042009068.jpg||image/jpeg|0|00:18:C5:42:18:78|1|2|200|394450|394450|946685368037|0
5||btopp_vcard.vcf|/sdcard/bluetooth/btopp_vcard.vcf|text/x-vcard|1|00:22:A5:B8:AD:65|1|1|496|168||946685701894|0
6||btopp_vcard.vcf|/sdcard/bluetooth/btopp_vcard.vcf|text/x-vcard|1|00:22:A5:B8:AD:65|1|1|200|168|168|946685806848|2
7||08042009068.jpg||image/jpeg|1|00:18:C5:42:18:78|1|4|490|394450||946698435289|0
8||08042009068.jpg||image/jpeg|1|00:18:C5:42:18:78|1|4|490|394450||946698501841|0
9|content://media/external/images/media/1|08042009068.jpg|/sdcard/bluetooth/08042009068.jpg|image/jpeg|1|00:18:C5:42:18:78|1|1|200|394450|394450|946698554454|1
10|content://media/external/images/media/2|08042009068-1.jpg|/sdcard/bluetooth/08042009068-1.jpg|image/jpeg|1|00:18:C5:42:18:78|1|1|200|394450|394450|946698717592|1
11|file:///sdcard/bluetooth/08042009068-1.jpg|08042009068-1.jpg||image/jpeg|0|00:22:A5:B8:AD:65|1|2|495|394450|0|946698901473|0
12|content://media/external/images/media/2|08042009068-1.jpg||image/jpeg|0|00:18:C5:42:18:78|1|2|200|394450|394450|946699019695|0


Screenshots from beagle-eclair

* Turn Bluetooth On
* Pair with Nokia N73 phone
* Receive an image from N73 to Beagle board via BT
* Send an image from Beagle board to N73 via BT

02月01日

Jollen's face
Jollen


縮小 展開

「Android Framework Introduction」講座

Android Framework 技術的重要性日漸提高,研究 Android Framework 架構或是內部結構成為一項重要的工作。明天(2/2)受邀至鴻海土城民生廠進行一場訓練課程,主題是「Android Framework Introduction」;議題雖然是「introduction」,但突然有個想法,希望能做更深入的 introduction。正好近期在整理研究資料,所以把抓出的議題也和大家分享。計畫介紹的技術主題(Features)如下: 1. Android Framework Features SystemServer & ServerThread Main Thread android.app.Activity 與 android.app.Service Android Process 模式 ServiceManager 與 getSystemService API JNI & Native Method Blocking & Long Operations VMThread & Thread Zygote...

chihchun's face
chihchun


縮小 展開

git archive 與 log 小技巧

時常,你得將手上的軟體原始碼壓起來釋出給第三方使用、測試。特別是你希望提供 daily basics/ revision basics 讓使用者取得最新版軟體的時候。

由於最近都已經只用 git,依據我自己的習慣,希望能夠在檔名中使用簡碼版次,以便未來能夠追蹤出該版次的問題。稍微問了一下友人與查了一下文件,取得 abbreviated commit hash 的作法如下

git log --pretty=format:"%h" -1

若你想將整份程式碼壓縮起來,可以使用

git archive --format zip -o filename.zip HEAD

倘若想加上日期作為檔名,請使用

git archive --format zip -o $(git log --pretty=format:"%h" -1).zip HEAD

若常常使用這個指令,有兩種作法,一是設定為 git alias. 另一則是利用 git 的 commands (verbs) 命名機制,在你的執行路徑 下,寫入一檔案名稱如 git-zip。並將上述指令加入檔案中,未來就可以使用 git zip 來產生最新版壓縮檔。

作法如
$ cat > ~/bin/git-zip
#!/bin/sh
git archive --format zip -o $(git log --pretty=format:"%h" -1).zip HEAD
$ chmod u+x ~/bin/git-zip
$ cd git-repository
$ git zip

另外,為了容易辨識版次,你也可以利用 gitattributes 在程式碼中加入 ident ($Id$) 作為標示。操作可參考 Lloyd Huang 所寫之 Howto.

這是一篇 Tip.