2004-08-29

wget用法 GNU Wget 1.9+cvs-dev-200404081407

归类于: Tech — chenxq @ 07:17:04

嗯,下载少林七十二绝技
注意,要先建好72magic目录
D:\wget>wget -nd -np -nH -r -k -p -E http://www.shaolin.org.cn/asp/lec_chapter.asp?LecID=54 –directory-prefix=72magic

D:\wget>wget –help
GNU Wget 1.9+cvs-dev-200404081407, a non-interactive network retriever.
Usage: wget [OPTION]… [URL]…

Mandatory arguments to long options are mandatory for short options too.

Startup:
  -V,  –version           display the version of Wget and exit.
  -h,  –help              print this help.
  -b,  –background        go to background after startup.
  -e,  –execute=COMMAND   execute a `.wgetrc’-style command.

Logging and input file:
  -o,  –output-file=FILE    log messages to FILE.
  -a,  –append-output=FILE  append messages to FILE.
  -d,  –debug               print lots of debugging information.
  -q,  –quiet               quiet (no output).
  -v,  –verbose             be verbose (this is the default).
  -nv, –no-verbose          turn off verboseness, without being quiet.
  -i,  –input-file=FILE     download URLs found in FILE.
  -F,  –force-html          treat input file as HTML.
  -B,  –base=URL            prepends URL to relative links in -F -i file.

Download:
  -t,  –tries=NUMBER            set number of retries to NUMBER (0 unlimits).
       –retry-connrefused       retry even if connection is refused.
  -O,  –output-document=FILE    write documents to FILE.
  -nc, –no-clobber              skip downloads that would download to
                                 existing files.
  -c,  –continue                resume getting a partially-downloaded file.
       –progress=TYPE           select progress gauge type.
  -N,  –timestamping            don’t re-retrieve files unless newer than
                                 local.
  -S,  –server-response         print server response.
       –spider                  don’t download anything.
  -T,  –timeout=SECONDS         set all timeout values to SECONDS.
       –dns-timeout=SECS        set the DNS lookup timeout to SECS.
       –connect-timeout=SECS    set the connect timeout to SECS.
       –read-timeout=SECS       set the read timeout to SECS.
  -w,  –wait=SECONDS            wait SECONDS between retrievals.
       –waitretry=SECONDS       wait 1..SECONDS between retries of a retrieval.

       –random-wait             wait from 0…2*WAIT secs between retrievals.
  -Y,  –proxy                   explicitly turn on proxy.
       –no-proxy                explicitly turn off proxy.
  -Q,  –quota=NUMBER            set retrieval quota to NUMBER.
       –bind-address=ADDRESS    bind to ADDRESS (hostname or IP) on local host.

       –limit-rate=RATE         limit download rate to RATE.
       –no-dns-cache            disable caching DNS lookups.
       –restrict-file-names=OS  restrict chars in file names to ones OS allows.

Directories:
  -nd, –no-directories           don’t create directories.
  -x,  –force-directories        force creation of directories.
  -nH, –no-host-directories      don’t create host directories.
       –protocol-directories     use protocol name in directories.
  -P,  –directory-prefix=PREFIX  save files to PREFIX/…
       –cut-dirs=NUMBER          ignore NUMBER remote directory components.

HTTP options:
       –http-user=USER        set http user to USER.
       –http-passwd=PASS      set http password to PASS.
       –no-cache              disallow server-cached data.
  -E,  –html-extension        save HTML documents with `.html’ extension.
       –ignore-length         ignore `Content-Length’ header field.
       –header=STRING         insert STRING among the headers.
       –proxy-user=USER       set USER as proxy username.
       –proxy-passwd=PASS     set PASS as proxy password.
       –referer=URL           include `Referer: URL’ header in HTTP request.
       –save-headers          save the HTTP headers to file.
  -U,  –user-agent=AGENT      identify as AGENT instead of Wget/VERSION.
       –no-http-keep-alive    disable HTTP keep-alive (persistent connections).

       –no-cookies            don’t use cookies.
       –load-cookies=FILE     load cookies from FILE before session.
       –save-cookies=FILE     save cookies to FILE after session.
       –keep-session-cookies  load and save session (non-permanent) cookies.
       –post-data=STRING      use the POST method; send STRING as the data.
       –post-file=FILE        use the POST method; send contents of FILE.

HTTPS (SSL) options:
       –sslcertfile=FILE    optional client certificate.
       –sslcertkey=KEYFILE  optional keyfile for this certificate.
       –egd-file=FILE       file name of the EGD socket.
       –sslcadir=DIR        dir where hash list of CA’s are stored.
       –sslcafile=FILE      file with bundle of CA’s.
       –sslcerttype=0/1     Client-Cert type 0=PEM (default) / 1=ASN1 (DER).
       –sslcheckcert=0/1    Check the server cert against given CA.
       –sslprotocol=0-3     choose SSL protocol; 0=automatic,
                             1=SSLv2 2=SSLv3 3=TLSv1.

FTP options:
       –no-remove-listing     don’t remove `.listing’ files.
       –no-glob               turn off FTP file name globbing.
       –passive-ftp           use the "passive" transfer mode.
       –retr-symlinks         when recursing, get linked-to files (not dir).
       –preserve-permissions  preserve remote file permissions.

Recursive download:
  -r,  –recursive          specify recursive download.
  -l,  –level=NUMBER       maximum recursion depth (inf or 0 for infinite).
       –delete-after       delete files locally after downloading them.
  -k,  –convert-links      make links in downloaded HTML point to local files.
  -K,  –backup-converted   before converting file X, back up as X.orig.
  -m,  –mirror             shortcut option equivalent to -r -N -l inf -nr.
  -p,  –page-requisites    get all images, etc. needed to display HTML page.
       –strict-comments    turn on strict (SGML) handling of HTML comments.

Recursive accept/reject:
  -A,  –accept=LIST               comma-separated list of accepted extensions.
  -R,  –reject=LIST               comma-separated list of rejected extensions.
  -D,  –domains=LIST              comma-separated list of accepted domains.
       –exclude-domains=LIST      comma-separated list of rejected domains.
       –follow-ftp                follow FTP links from HTML documents.
       –follow-tags=LIST          comma-separated list of followed HTML tags.
       –ignore-tags=LIST          comma-separated list of ignored HTML tags.
  -H,  –span-hosts                go to foreign hosts when recursive.
  -L,  –relative                  follow relative links only.
  -I,  –include-directories=LIST  list of allowed directories.
  -X,  –exclude-directories=LIST  list of excluded directories.
  -np, –no-parent                 don’t ascend to the parent directory.

Mail bug reports and suggestions to <bug-wget@gnu.org>.

2004-08-21

《从开始到现在》――张信哲

归类于: — chenxq @ 17:46:24

/*
你真的忘得了你的初恋情人吗
假如 有一天
你遇到了跟他长得一模一样的人
他真的就是他吗 还有可能吗
这是命运的宽容 还是
另一次不怀好意的玩笑
*/

如果这最后的结局
为何我还忘不了你
时间改变了我们 告别了单纯
难道我就这样过我的一生
我的吻注定吻不到最爱的人
为你等 从一开始盼到现在
也同样落的不可能
难道爱情可以转交给别人
但命运注定留不住我爱的人
我不能 我怎么会愿意承认
你是我不该爱的人

如果再见是为了再分
失去才算是永恒
一次新的记忆为何还要再生
如果重逢也无法继续 失去才算是永恒
难道我就这样过我的一生
我的吻注定吻不到最爱的人
为你等 从一开始盼到现在
也同样落的不可能
难道爱情可以转交给别人
但命运注定留不住我爱的人
我不能 我怎么会愿意承认
你是我不该爱的人
拿什么作证
从未想过爱一个人
需要那么残忍才证明爱的深
惩罚我的认真 是我太过天真
难道我就这样过我的一生
我的吻注定吻不到最爱的人
为你等 从一开始盼到现在
也同样落的不可能
难道爱情可以转交给别人
但命运注定留不住我爱的人
我不能我怎么会愿意承认
你是我爱错了的人

寻秦记,一滴蜜糖的故事 zz from 寻秦记

归类于: 读万卷书 — chenxq @ 17:41:41

项少龙沙哑著声音,缓缓道:「有个旅客在沙漠里走著,忽然後面出现了一群饿狼,追
著他来要群起而噬。」

    众人为之愕然,同时也大感兴趣,想不到他忽然会说起故事来。就像庄周好以寓言来演
绎思想般。

    项少龙的声音在寂静的夜空里震荡著,份外有一种难言的诡秘和感染力,尤其内容正是
有关秘不可测的生死问题。

    只听他以非常缓慢的节奏续道:「他大吃一惊,拚命狂奔,为生命而奋斗。」

    郭秀儿「啊」一声叫了起来道:「在沙漠怎跑得快过饿狼,他定要死啦!」

    众人为之莞尔,却没有答话,因为都想听下去,连李园都不例外。不过当他看到纪嫣然
闭上美目那又乖又专心的俏样儿,禁不住妒火狂燃。

    项少龙微微一笑道:「不用慌!就在饿狼快追上他时,他见到前面有口不知有多深的
井,不顾一切跳了进去。」

    赵雅松了一口气道:「那口井定是有水的,是吗?」

    项少龙望往下面的小溪流,摇头道:「不但没有水,还有很多毒蛇,见到有食物送上门
来,昂首吐舌,热切引项以待。」

    今次轮到纪嫣然「啊」的一声叫了起来,睁开美目,别过娇躯来,看著他道:「那怎办
才好呢?不若回过头来和饿狼捕斗好了,毒蛇比狼可怕多了。」韩闯笑道:「女孩子都是怕
蛇的,纪小姐亦不例外。」

    项少龙望往纪嫣然,柔声道:「他大惊失神下,胡乱伸手想去抓到点甚麽可以救命的东
西,想不到竟天从人愿,给他抓到了一棵在井中间横伸出来的小树,把他稳在半空处。」众
人都没有作声,知道这故事仍有下文。

    赵雅的眼睛亮了起来,在这一刻,她的心中只有这个比李园更特别难测的豪汉。

    项少龙道:「於是乎上有饿狼,下有毒蛇,不过那人虽陷身在进退两难的绝境,但暂时
总仍是安全的。」

    众人开始有点明白过来。项少龙说的正是人的写照,试问在生死之间,谁不是进退两难
呢?

    只听他说下去道:「就在他松了一口气的时刻,奇怪的异响传入他的耳内。他骇然循声
望去,魂飞魄散地发觉有一群大老鼠正以尖利的牙齿咬著树根,这救命的树已是时日无多
了。」郭秀儿和赵致同时惊呼起来。

    项少龙深深瞧著纪嫣然,像只说给她一个人听似的道:「就在这生死一瞬的时刻,他看
到了眼前树叶上有一滴蜜糖,於是他忘记了上面的饿狼,下面的毒蛇,也忘掉了快要给老鼠
咬断的小树,闭上眼睛,伸出舌头,全心全意去舐尝那滴蜜糖。」

    小桥上静得没有半点声息,只有溪水流过的淙淙细响。

    项少龙伸了个懒腰道:「对老子来说,那滴蜜糖就是生命的意义!」

[zz]悬崖上的古老共和国圣马力诺San Marino

归类于: 行万里路 — chenxq @ 17:34:35

悬崖上的古老共和国圣马力诺San Marino 

——————————————————————————–

● 欧阳兴义(图文)

  站在蒂塔诺峰顶古堡的城墙上,脚下是野蔓乱藤的百丈悬崖,这仅有61平方公里的石灰岩小山,便是世界最小,又最古老的袖珍共和国――圣马力诺。

别小看它小,圣马力诺独立、自由、中立的信念赢得了世界的尊敬,美国总统林肯曾代表美国人民为圣马力诺向上帝祈求保佑,林肯说:你虽小,却是有史以来最受人尊敬的国家。

  春寒料峭,亚得里亚海上空云层的间隙,疏懒地透射出微弱的晨光。

  意大利滨海城市里米尼(Rimini)以西22公里,平地突兀而起,几乎是垂直上下,一片700米高的石灰岩悬崖绝壁,迎着东方大海的朝阳,染上了玫瑰色的霞光。

  悬崖绝壁的天际线上,延绵着城垛城墙,三座小山峰各有一座石堡塔楼,这仅有61平方公里,2万5000人口的石灰岩小山,便是世界最小,又最古老的袖珍共和国圣马力诺(San Marino)。

  圣马力诺与安道尔、摩纳哥、凡蒂冈、列支敦士登同称世界五小国,因没有出海口,是意大利境内的国中之国。又因其小,国徽上三座山峰的三座古堡上有三根白羽毛,因而又被称为口袋小国、三羽之国。

  紫红色的豪华巴士,清晨从里米尼火车站出发,穿越绿色园林和红瓦农舍,左右盘旋上山,仅45分钟车程,来到738米蒂塔诺峰(Titano)下的圣马力诺古城门外。

马力诺的石雕无处不在

  进入1361年建的石城门,到处都能看到一位手持石槌的慈祥老人马力诺的雕像,举目石屋、石墙、石城、石堡、石栏、石像,石造的政府大楼、银行、教堂、邮局、博物馆等一应俱全,不愧是石匠与石岩的国度。

  圣马力诺的行政中心是位于自由广场的政府大楼,1894年落成的大楼前,有白色的自由女神雕像,三层大楼顶上再建有带城堞的钟楼,大钟之上是三圣人像。楼侧一角的马力诺青铜像和许愿灯下,刻有“拯救你的共和国,马力诺,自由的奠基人”的铭文。

  绿衣、红裤、黑帽、白羽毛,彩装的城堡卫队正午换班后,便可购票进入政府大楼。入门处挂有许多徽章盾牌和中世纪守城的弓弩,二楼议政大厅的一面墙壁是幅巨大的壁画,画着天使飞翔,金色光环中的圣马力诺和他荫护的子民一起在天国中。

  圣马力诺的历史长达1600多年:公元3世纪石匠马力诺受雇于里米尼的港口建筑,因躲避专制统治者的迫害,逃到蒂塔诺山的石洞居住,采石为生。他虔诚传教,为贫病苦疾者禁食祈福,收留各地受迫害者,逐渐形成石匠公社,大众奉为圣人。

  后改信天主教的罗马贵族将蒂塔诺山赠给马力诺,马力诺逝世后,石匠公社逐渐形成城市共和国的政治体制,并建造城堡城墙,以保护自己的独立自由生活。

不扩展领土也不并入意大利

为纪念创始人,国名及首都市镇都命名圣马力诺,每200人选出一名议员,议员选出两名执政官执行法律管理国家。现存最早的法律是1295年手写的法规,最早有文献纪录姓名的是1244年的执政官。1463年结束了圣马力诺人最后一场战争,即使以后拿破仑和希特勒都要赠送里米尼作出海口,圣马力诺都加以拒绝,坚守自己原有的领土至今,也没有在19世纪的意大利统一潮中并入意大利。

邮票与旅游之国

  它又坚持“自由之舟”的传统,收容寻求庇护的各方人士,二次世界大战之初收留的难民,多达国民总数的八倍。独立、自由、中立的信念赢得了世界的尊敬,美国总统林肯代表美国人民为圣马力诺向上帝祈求保佑,林肯说:你虽小,却是有史以来最受人尊敬的国家。

  蒂塔诺山上,完全中世纪城堡外貌的首都圣马力诺市,每年接待300多万各国游客,约是国民总数的150倍。市内几乎都是与旅游相关的商店和旅馆,政府出版及派发包括中文在内的各语文旅游指南,市内也有一家广东餐馆。

  国家博物馆、邮票博物馆、美术馆、珍奇博物馆、蜡像馆、中世纪酷刑博物馆、武器博物馆等分布在各区狭窄的石块山坡道路上。方形教堂保存着马力诺的遗骨。

  但人们最感兴趣的,还是其国家象征的三座古堡塔楼,和完整的中世纪城墙。1371年途经的一位红衣主教兴奋地描述:“城市耸立在大山之上,山顶竖立着三座堡垒”。世界最小国之一的圣马力诺,与世界最大国之一的中国,多次共同发行以蒂塔诺山古堡城墙和万里长城为图的两国纪念邮票。

  发行邮票钱币是国家的主要收入来源之一,圣马力诺邮票是世界集邮者之爱,连邮票一同印刷的一体明信片,原来是圣马力诺邮政的发明。

山洞监狱里没有罪犯

  高贵艳红的“仙客来”是圣马力诺国花,作为经济命脉的旅游业也带动了陶瓷、酿酒等工业,国内有欧洲最大的铝制品厂,也有葡萄、橄榄、小麦、玉米等农业。国民无须缴税,免费教育、医疗,平均国民年收入1万7000美元。没有军队,仅有城堡卫队和从意大利聘来几十名宪警。一间能容六人的山洞监狱,因没有罪犯,已多年没有使用。

  持自由、民主、独立、中立的信念而不武装设防,小而美,屹立世界强国之林,施行民主共和制千多年而不亡,圣马力诺不能不说是人类的奇迹。

  站在蒂塔诺峰顶古堡的城墙上,脚下是满挂野蔓乱藤的百丈悬崖,远眺山脚下起伏的丘陵,再远一望平川的绿色田野,天边一线是亚得里亚大海。在雄奇险峻的绝壁夹缝中,一堆一簇艳黄的颜色,是山顶骄阳劲风下盛开的野山菊,展现了顽强无比的生命力。

bik->xvid avi

归类于: Tech — chenxq @ 17:33:20

工具:RadVideo,K-Lite Codec Pack,Media Player Classic
        打开RadVideo,然后选中bik文件(注意不要双击),点击Convert a file,然后
就在新窗口直接点击Convert。下一步在Video Compression这个窗口,Compressor那里选择
合适的编码器比如xvid。不要着急OK,选Configure,在Xvid Configuration窗口,Target
quantizer那里选8.0(兼顾文件大小与画面质量),点击右边的calc。新的Xvid Configura
tion窗口里面Audio Format选MP3-CBR,Container Format选AVI-OpenDML,把时间算出来,
把每秒帧数填上(时间要看Bink Conventor窗口里的统计数据自己算,帧/s可以直接看统计
数据)。然后OK,再OK,再OK,就开始压了,稍微nb一点的机器压100M的bik,几分钟就完
事了。
        装K-Lite Codec Pack的时候,记得把Xvid Encoding选上。
        用Media Player Classic看看效果。

以上办法只是我自己试的……-_-b

dul@smth写的pcap.h pcap.c

归类于: Tech — chenxq @ 17:31:25

#include "/usr/include/sys/types.h"
#include "/usr/include/net/ethernet.h"
#include <stdio.h>
#include <pcap.h>
#include <string.h>

#define ETH_TYPE_IP 8
#define ETH_TYPE_ARP 1544
#define IP_TYPE_TCP 6
#define IP_TYPE_UDP 17
#define IP_TYPE_ICMP 1

struct my_eth_head
{
u_int8_t dest_addr[6];
u_int8_t src_addr[6];
u_int16_t type;
};

struct my_arp_head
{
  u_int16_t hard_type;
  u_int16_t prot_type;
  u_int8_t hard_size;
  u_int8_t prot_size;
  u_int16_t op;
  u_int8_t src_eth_addr[6];
  u_int8_t src_ip_addr[4];
  u_int8_t dest_eth_addr[6];
  u_int8_t dest_ip_addr[4];
};
struct my_ip_head
{
unsigned length:4;
unsigned version:4;
u_int8_t TOS;
        u_int16_t total_length;
        u_int16_t identification;
        unsigned flag1:1;
        unsigned flag2:1;
        unsigned flag3:1;
        unsigned fragment_offset:13;
u_int8_t TTL;
u_int8_t protocol;
u_int16_t checksum;
u_int8_t src_addr[4];
u_int8_t dest_addr[4];
void * options;
};

struct my_tcp_head
{
u_int16_t src_port;
u_int16_t dest_port;
u_int32_t seq;
u_int32_t ack;
unsigned head_length:4;
unsigned reserved:6;
unsigned URG:1;
unsigned ACK:1;
unsigned PSH:1;
unsigned RST:1;
unsigned SYN:1;
unsigned FIN:1;
u_int16_t win;
u_int16_t checksum;
u_int16_t urgent_pointer;
void * options;
};

struct my_udp_head
{
u_int16_t src_port;
u_int16_t dest_port;
u_int16_t length;
u_int16_t checksum;
};

struct my_icmp_head
{
u_int8_t type;
u_int8_t code;
u_int16_t checksum;
        void * content;
}; 

/*
**show the protocal address,port and the length of a package
**ICMP TCP UDP ARP
**compile method: g++ filter.cpp -lpcap -o filter
**dul@smth
*/

#include "my_pcap.h"

pcap_t * get_pcap_handle();
void print_packet (const u_char * packet , struct pcap_pkthdr *header);

int main(int argc , char * argv[])
{
pcap_t * handle; // Session handle
struct pcap_pkthdr header; // The header that pcap gives us
const u_char *packet; // The actual packet

char flag;

handle = get_pcap_handle();

printf("This program show all packets you can get from you network\n");
printf("Only for ethernet. Press Crl+C to quit\n");
printf("Press any key to begain\n");

scanf("%c",&flag);

while(1)
{
        //get resource
packet = pcap_next(handle, &header);

//printf infomations
print_packet(packet,&header);
}

}

pcap_t * get_pcap_handle()
{
pcap_t * handle; // Session handle
char *dev; // The device to sniff on 
char errbuf[PCAP_ERRBUF_SIZE]; // Error string 
struct bpf_program filter; // The compiled filter 
char filter_str[] = ""; // The filter expression 
bpf_u_int32 mask; // Our netmask 
bpf_u_int32 net; // Our IP 

// Define the device 
dev = pcap_lookupdev(errbuf);
printf("Found device:%s\n",dev);
// Find the properties for the device 
pcap_lookupnet(dev, &net, &mask, errbuf);
// Open the session in promiscuous mode 
handle = pcap_open_live(dev, BUFSIZ, 1, 0, errbuf);
// Compile and apply the filter 
pcap_compile(handle, &filter, NULL , 1 , 0);
pcap_setfilter(handle, &filter);

return handle;
}

void print_packet( const u_char * packet , struct pcap_pkthdr * header)
{
        //eth
struct my_eth_head * eth;
eth = (struct my_eth_head *)malloc(sizeof(struct my_eth_head));
memcpy(eth,packet,14);

switch(eth->type)
{
case ETH_TYPE_IP:{
//ip
struct my_ip_head * ip;
ip = (struct my_ip_head *)malloc(sizeof(struct my_ip_head));
memcpy(ip,(packet + 14),20);
//check 
if(ip->version != 4)
{
        printf("unknown ip version:%d\n",ip->version);
return;
}

//add other checks here

//mayby there is options here,so the ip header is more than 20
if(ip->length <=5)
ip->options=NULL;
else
{
        ip->options = malloc(ip->length*4-20);
memcpy(ip->options,packet+34,ip->length*4-20);
}

switch(ip->protocol)
{
case IP_TYPE_TCP:{
//tcp
struct my_tcp_head * tcp;
       tcp = (struct my_tcp_head *)malloc(sizeof(struct my_tcp_head));
memcpy(tcp,(packet + 14 + ip->length*4),20);

if(tcp->head_length <= 5)
tcp->options = NULL;
else
{
        tcp->options = malloc(tcp->head_length*4-20);
memcpy(tcp->options,packet+14+ip->length*4,tcp->head_length*4-20);
}
/////////////////////////////////////////////////////////////////
//print the type of tcp packet
printf("%d.%d.%d.%d:%d %s",ip->src_addr[0],
ip->src_addr[1],ip->src_addr[2],ip->src_addr[3],
ntohs(tcp->src_port),"tcp");

                 printf(" -> %d.%d.%d.%d:%d ",
ip->dest_addr[0],ip->dest_addr[1],ip->dest_addr[2],
ip->dest_addr[3],ntohs(tcp->dest_port));

printf("seq:%u ack:%u win:%u ",ntohl(tcp->seq),ntohl(tcp->ack),
        ntohs(tcp->win));
if(tcp->ACK)
        printf("ACK ");
if(tcp->SYN)
        printf("S ");
if(tcp->FIN)
        printf("FIN ");
printf("length:%d\n",header->len);
////////////////////////////////////////////////////////////////
break;}

case IP_TYPE_UDP:{
struct my_udp_head * udp;
udp = (struct my_udp_head *)malloc(sizeof(struct my_udp_head));
memcpy(udp,(packet + 14 + ip->length*4),20);

/////////////////////////////////////////////////////////////////
//print the type of udp packet

printf("%d.%d.%d.%d:%d %s",ip->src_addr[0],
ip->src_addr[1],ip->src_addr[2],ip->src_addr[3],
ntohs(udp->src_port),"udp");

                 printf(" -> %d.%d.%d.%d:%d ",
ip->dest_addr[0],ip->dest_addr[1],ip->dest_addr[2],
ip->dest_addr[3],ntohs(udp->dest_port));

//TODO:DNS
printf("length:%d\n",header->len);

///////////////////////////////////////////////////////////////
break;}
case IP_TYPE_ICMP:{
        struct my_icmp_head * icmp;
icmp = (struct my_icmp_head *)malloc(sizeof(struct my_icmp_head));
memcpy(icmp,(packet + 14 +ip->length*4),4);

//TODO:get content according to the type and code
icmp->content = NULL;

printf("%d.%d.%d.%d",ip->src_addr[0],ip->src_addr[1],
ip->src_addr[2],ip->src_addr[3]);

printf(" -> %d.%d.%d.%d ICMP ",ip->dest_addr[0],ip->dest_addr[1],
ip->dest_addr[2],ip->dest_addr[3]);

switch(icmp->type)
{
///////////////////////////////////////////////////////////////
//print the type of icmp message
case 0:
if(icmp->code == 0)
printf("echo reply");
else
printf("Unknown query type:0 code:%d",icmp->code);
break;
case 3:
switch(icmp->code)
{
case 0:printf("network unreachable");break;
case 1:printf("host unreachable");break;
case 2:printf("protocol unreachable");break;
case 3:printf("port unreachable");break;
case 4:printf("fragment needed but don’t-fragment bit set");break;
case 5:printf("source route failed");break;
case 6:printf("destination network unknown");break;
case 7:printf("destination host unknown");break;
case 8:printf("source host isolated(obsolete)");break;
case 9:printf("destination network administratively prohibited");break;
case 10:printf("destination host administratively prohibited");break;
case 11:printf("network unreachable for TOS");break;
case 12:printf("host unreachable for TOS");break;
case 13:printf("communication administratively prohibited by filtering");break;
case 14:printf("host precedence violation");break;
case 15:printf("precedence cutoff in effect");break;
default:printf("Unknown error type:3 code:%d",icmp->code);break;
}
break;
case 4:
if(icmp->code == 0)
printf("source quench(elementary flow control)");
else
printf("Unknown query type:4 code:%d",icmp->code);
break;
case 5:
switch(icmp->code)
{
case 0:printf("redirect for network");break;
case 1:printf("redirect for host");break;
case 2:printf("redirect for type-of-service and network");break;
case 3:printf("redirect for type-of-service and host");break;
default:printf("Unknown error type:5 code:%d",icmp->code);break;
}
break;
case 8:
if(icmp->code == 0)
printf("echo request");
else
printf("Unknown query type:8 code:%d",icmp->code);
break;
case 9:
if(icmp->code == 0)
printf("router advertisement");
else
printf("Unknown query type:9 code:%d",icmp->code);
break;
case 10:
if(icmp->code == 0)
printf("router solicitation");
else
printf("Unknown query type:10 code:%d",icmp->code);
break;
case 11:
if(icmp->code == 0)
printf("time-to-live equals 0 during transit");
else if(icmp->code == 1)
printf("time-to-live equals 0 during reassembly");
else
printf("Unknown error type:11 code:%d",icmp->code);
break;
case 12:
if(icmp->code == 0)
printf("ip header bad");
else if(icmp->code == 1)
printf("required option missing");
else
printf("Unknown error type:12 code:%d",icmp->code);
break;
case 13:
if(icmp->code == 0)
printf("timestamp request");
else
printf("Unknown query type:13 code:%d",icmp->code);
break;
case 14:
if(icmp->code == 0)
printf("timestamp reply");
else
printf("Unknown query type:14 code:%d",icmp->code);
break;
case 15:
if(icmp->code == 0)
printf("information request");
else
printf("Unknown query type:15 code:%d",icmp->code);
break;
case 16:
if(icmp->code == 0)
printf("information reply");
else
printf("Unknown query type:16 code:%d",icmp->code);
break;
case 17:
if(icmp->code == 0)
printf("address mask request");
else
printf("Unknown query type:17 code:%d",icmp->code);
break;
case 18:
if(icmp->code == 0)
printf("address mask replay");
else
printf("Unknown query type:18 code:%d",icmp->code);
break;
default:
printf("Unknown type type:%d code:%d",icmp->type,icmp->code);
break;

///////////////////////////////////////////////////////////////
}

printf(" length:%d\n",header->len);
break;}
default:
        printf("%d.%d.%d.%d -> %d.%d.%d.%d Unknow IP protocol:%x\n",
       ip->src_addr[0],ip->src_addr[1],ip->src_addr[2],ip->src_addr[3],
       ip->dest_addr[0],ip->dest_addr[1],ip->dest_addr[2],
       ip->dest_addr[3],ip->protocol);
break;
}
break;}
case ETH_TYPE_ARP:{
        struct my_arp_head * arp;
arp = (struct my_arp_head *)malloc(sizeof(struct my_arp_head));
memcpy(arp,(packet + 14),28);

///////////////////////////////////////////////////////////////////////
//print the type of arp packet
printf("%x:%x:%x:%x:%x:%x %x:%x:%x:%x:%x:%x ",
eth->src_addr[0],eth->src_addr[1],eth->src_addr[2],
eth->src_addr[3],eth->src_addr[4],eth->src_addr[5],
eth->dest_addr[0],eth->dest_addr[1],eth->dest_addr[2],
eth->dest_addr[3],eth->dest_addr[4],eth->dest_addr[5]);
if(ntohs(arp->hard_type)!=1||ntohs(arp->prot_type)!=0×0800||
        arp->hard_size!=6||arp->prot_size!=4)
        {
        printf("Unkown arp packet hard type:%d prot type:%d hard"
" size:%d prot size:%d\n",ntohs(arp->hard_type),
ntohs(arp->prot_type),arp->hard_size,arp->prot_size);
        return;
}
        switch(ntohs(arp->op))
{
case 1:
printf("arp request who-has %d.%d.%d.%d tell %d.%d.%d.%d",
       arp->dest_ip_addr[0],arp->dest_ip_addr[1],
       arp->dest_ip_addr[2],arp->dest_ip_addr[3],
       arp->src_ip_addr[0],arp->src_ip_addr[1],
       arp->src_ip_addr[2],arp->src_ip_addr[3]);
        break;
case 2:
        printf("arp reply %d.%d.%d.%d is %x:%x:%x:%x:%x:%x",
       arp->src_ip_addr[0],arp->src_ip_addr[1],
       arp->src_ip_addr[2],arp->src_ip_addr[3],
       arp->src_eth_addr[0],arp->src_eth_addr[1],
       arp->src_eth_addr[2],arp->src_eth_addr[3],
       arp->src_eth_addr[4],arp->src_eth_addr[5]);
        break;
case 3:
        printf("rarp request who-has %x:%x:%x:%x:%x:%x tell %d.%d.%d.%d",
       arp->dest_eth_addr[0],arp->dest_eth_addr[1],
       arp->dest_eth_addr[2],arp->dest_eth_addr[3],
       arp->dest_eth_addr[4],arp->dest_eth_addr[5],
       arp->src_ip_addr[0],arp->src_ip_addr[1],
       arp->src_ip_addr[2],arp->src_ip_addr[3]);
        break;
case 4:
        printf("rarp reply %x:%x:%x:%x:%x:%x is %d.%d.%d.%d",
       arp->src_eth_addr[0],arp->src_eth_addr[1],
       arp->src_eth_addr[2],arp->src_eth_addr[3],
       arp->src_eth_addr[4],arp->src_eth_addr[5],
       arp->src_ip_addr[0],arp->src_ip_addr[1],
       arp->src_ip_addr[2],arp->src_ip_addr[3]);
        break;
default:
        printf("Unknown arp packet op:%d",ntohs(arp->op));
break;
}

printf(" length:%d\n",header->len);
///////////////////////////////////////////////////////////////////////
break;}
default:
        printf("%x:%x:%x:%x:%x:%x %x:%x:%x:%x:%x:%x unknown eth type"
"(802.1x most posseble):%x\n",
eth->src_addr[0],eth->src_addr[1],eth->src_addr[2],
eth->src_addr[3],eth->src_addr[4],eth->src_addr[5],
eth->dest_addr[0],eth->dest_addr[1],eth->dest_addr[2],
eth->dest_addr[3],eth->dest_addr[4],eth->dest_addr[5],eth->type);
        break;
}
}

2004-08-11

道法自然

归类于: 惊蛰 — chenxq @ 04:46:07

刚才和某人MSN聊天,谈到苦闷的生活,忽然想起一个故事,就是不见此花,此花与世界同寂灭的故事

登录 | 访问数236847 | 水木BLOG | 水木社区 | 关于我们 | Blog论坛 | 法律声明 | 隐私权保护 | 京ICP证050249号
水木社区Blog系统是基于KBS系统WordPress MU架构的