摘要: #include <stdio.h>typedef struct node_t{ struct node_t *next; char *word; int count;}*node;#define NHASH 9973 // 最好定位质数#define MULT 31 // 乘法器node bin[NHASH]; // 哈希表索引unsigned int hash(char *p){ unsigned int h = 0; for(; *p; p++) h = MULT * h + *p; return h % NHASH;}vo... 阅读全文
posted @ 2012-09-13 17:47 庄庄庄 阅读(3436) 评论(0) 推荐(0) 编辑
摘要: while(<DATA>){ $str .=$_;}print &delHtml($str);<>;sub delhtml{ my($str) = @_; my($s_pos) = 0; my($e_pos) = 0;loop: if(index($str,'<') != -1) { $s_pos = index($str,'<'); $e_pos = index($str,'>',$s_pos); if($s_pos > 0) ... 阅读全文
posted @ 2012-09-13 16:51 庄庄庄 阅读(352) 评论(0) 推荐(0) 编辑
摘要: 约定协议: 客户端发送请求:char buf[256]=文件名 服务端回复: int len=文件长度 + 文件信息 若文件不存在返回 "-1" + "file not found\n" 若文件读取错误返回 "-2" + "server error\n" 若文件为目录 "-3" + "dirtory error\n"-----------TCP协议客户端流程--------------------创建socket 根据协议族,协议类型,协议编号,向操作系统申请一个socket 阅读全文
posted @ 2012-09-12 03:36 庄庄庄 阅读(461) 评论(0) 推荐(0) 编辑
摘要: DNS无法Ping通是正常现象,为了避免恶意攻击,许多服务器都禁用了ICMP。出现该错误的原因是没开启DNS转发。对于Windows网络,如果安装了Active Directory服务,可以将工作站的DNS服务器设置为局域网内服务器的地址,即升级到支持Active Directory的主域计算机的IP地址,并在DNS服务中启用DNS转发(例如转发地址为202.96.128.143),估计这样就可以了。 阅读全文
posted @ 2012-09-07 19:22 庄庄庄 阅读(458) 评论(0) 推荐(0) 编辑
摘要: typedef uint16_t in_port_t;// Internet address. --- IPV4typedef uint32_t in_addr_t;struct in_addr{ in_addr_t s_addr;};// IPv6 addressstruct in6_addr{ union { uint8_t __u6_addr8[16]; } __in6_u;}; // Structure describing an Internet socket address --- IPV4struct sockaddr_in{ __SOCKADDR_COMM... 阅读全文
posted @ 2012-09-04 04:36 庄庄庄 阅读(356) 评论(0) 推荐(0) 编辑
摘要: /*+------------------------------------------------------------------------+| 小端存储: 低地址存放低位数据; || 例: int型数 0x12 34 56 78 || | | || ... 阅读全文
posted @ 2012-09-04 01:07 庄庄庄 阅读(249) 评论(0) 推荐(0) 编辑
摘要: #include <arpa/inet.h>#include <stdbool.h>#include <stdio.h>inline bool is_little_endian(void){ int a = 1; return *(int *)&a == a;}// hton 和 ntoh 函数的代码完全相同uint32_t my_htonl(uint32_t hl){ if(is_little_endian()) { return *((unsigned char *)&hl ) << 24 | *((unsign... 阅读全文
posted @ 2012-09-04 01:07 庄庄庄 阅读(444) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#ifdef DEBUG#define PRINT printf#else#define PRINT#endiftypedef void (*ACT)(void);static char buf[64];static int j ;static char c;int find_type(char key){ if(key >= 'a' && key <= 'z') return 1; // 小写字符 if(key >= 'A 阅读全文
posted @ 2012-09-02 19:32 庄庄庄 阅读(861) 评论(0) 推荐(0) 编辑
摘要: // gcc -test.c -lconio -lpthread#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <unistd.h>#include <string.h>#include <time.h>#include <conio.h>#include <pthread.h>void act(void *arg){ int i; for(i = 0; i<10000; i++){ gotoxy(10+(int 阅读全文
posted @ 2012-08-29 03:37 庄庄庄 阅读(166) 评论(0) 推荐(0) 编辑
摘要: ---------- MAIN.C#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <unistd.h>#include <string.h>#include <time.h>#include "queue.h" typedef struct { int a, b;} coord;void print(void *data){ coord *cc = data; printf("(%d, %d)->" 阅读全文
posted @ 2012-08-29 02:00 庄庄庄 阅读(262) 评论(0) 推荐(0) 编辑