09 2012 档案
摘要:find / *.h -name|xargs grep 结构体名这个方法并不是很凑效。。。万能的gdb 法:int main(void){ type var; return 0;}gcc -g a.cgdb a.outb mainrp varset print pretty onp var p main::v
阅读全文
摘要:char *strchr(const char *str, int c); // 从前到后扫描,返回str中第一次包含字符c的地址,如果没有返回NULL;char *strrchr(const char *str, int c); // 从后到前扫描,。。。。。。。。。。。。。。。。size_t strspn(const char *str, const char *set); //str开始连续的字符出现在set中的个数size_tstrcspn(const char *str, const char *set); //str开始连续的字符不出现在set中的个数char *strpbrk(c
阅读全文
摘要:http://bbs.chinaunix.net/thread-3772418-1-1.htmlint(**p)(int *); 如何使用p?强转之。。。----------------------函数就是个地址,如何传参数取决于你赋予它的类型:#include <stdio.h>#include <stdlib.h>double f1(double x){ printf("%s:%f\n",__FUNCTION__,x); return x;}void *f2(void *a1, void *a2, void *a3){ printf("
阅读全文
摘要:应该说内存地址连续第访问, cache命中率会高一些,那么swap(&a[j],&a[j+1]) 应该更快,而且要快得多#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <string.h>#include <time.h>#include <unistd.h>#include <sys/time.h>void init(int *num, size_t len){ int i; for(i = 0; i<le
阅读全文
摘要:原文:http://oyjh1986.blog.163.com/blog/static/1960160762011830476639/Unix IO模型/IO复用select及epoll/存储映射IO mmap2011-09-30 17:34:06|分类:Linux操作系统|字号订阅 据Unix网络编程,Unix主要有阻塞IO、非阻塞IO、信号驱动IO、IO复用、异步IO;前五种都是同步,只有最后一种才是异步IO。1、 先贴上Unix网络编程的几张大图: 同步IO和异步IO的区别就在于:数据拷贝的时候进程是否阻塞! 阻塞IO和非阻塞IO的区别就在于:应用程序的调用是否立即返回!阻塞IO:从图中
阅读全文
摘要:原文:http://www.phreedom.org/research/tinype/Tiny PETranslations:português brasileiroCreating the smallest possible PE executableThis work was inspired by the Tiny PEchallengeby Gil Dabah. The object of the challenge was to write the smallest PE file that downloads a file from the Internet and ex
阅读全文
摘要:---------- SUB_FUN.C#include "mul_cp.h"extern char *src_addr, *dest_addr;static char *sub_bar(int gain, int all, char *buf, int len, int num){ int block = len/num; if(len % num != 0) block += 1; int i; for(i = 0; i<block; i++) if(i <= block * gain /all) buf[i] = ...
阅读全文
摘要:http://www.ibm.com/developerworks/cn/linux/l-ipc/part5/index2.html系统调用mmap()通过映射一个普通文件实现共享内存。系统V则是通过映射特殊文件系统shm中的文件实现进程间的共享内存通信。也就是说,每个共享内存区域对应特殊文件系统shm中的一个文件(这是通过shmid_kernel结构联系起来的),后面还将阐述。1、系统V共享内存原理进程间需要共享的数据被放在一个叫做IPC共享内存区域的地方,所有需要访问该共享区域的进程都要把该共享区域映射到本进程的地址空间中去。系统V共享内存通过shmget获得或创建一个IPC共享内存区域,
阅读全文
摘要:http://www.ibm.com/developerworks/cn/linux/l-ipc/part5/index1.html采用共享内存通信的一个显而易见的好处是效率高,因为进程可以直接读写内存,而不需要任何数据的拷贝。对于像管道和消息队列等通信方式,则需要在内核和用户空间进行四次的数据拷贝,而共享内存则只拷贝两次数据[1]:一次从输入文件到共享内存区,另一次从共享内存区到输出文件。实际上,进程之间在共享内存时,并不总是读写少量数据后就解除映射,有新的通信时,再重新建立共享内存区域。而是保持共享区域,直到通信完毕为止,这样,数据内容一直保存在共享内存中,并没有写回文件。共享内存中的内容
阅读全文
摘要:#include <stdio.h>#include <stdlib.h>void parse_arg(const int argc, const char **argv, const char **src, char const **dest, int *num){ if(argc != 4){ fprintf(stderr, "%s <number> <src_filename> <dest_filename>\n", argv[0]); exit(1); } *num = atoi(argv[1]); *sr
阅读全文
摘要:printf 显示彩色字符已经不新鲜了,今天发现居然可以控制光标!以前想实现gotoxy, 隐藏光标,下载了ncurse库,现在发现这有点杀鸡用牛刀了。转一个:linux 隐藏显示终端光标一、使用shell 的 echo 命令实现。 echo -ne <ctrl+v><ESC>[?25l&<60;&<60;&<60; 隐藏光标 echo -ne <ctrl+v><ESC>[?25h&<60; 显示光标 l,h为字母, <ctrl+v>是按下ctrl键不放,然后按下V, <E
阅读全文
摘要:我们知道free一个内存两次,会Abortedchar *p = malloc(100);free(p);free(p);今天发现了又一个Aborted(栈粉碎崩溃):这个错误stack smashing detected 的定位,void test(void){ char buf[100] memcpy(buf, "aaaa",200);}
阅读全文
摘要:先回答当n=2的情形,一句话回答:当要通过一个函数来改变 指针变量的值 的时候,就必须把这个指针变量的地址 作为实参,传递给函数;这个时候,这个函数所接收到的变量 当然就是 二重指针!典型的例子有:long int strtol(const char *nptr, char **endptr, int base);char *p;char *str = "200/300"int n = strtol(str, &p, 10);这第二个参数就是要把指针变量p的赋值为字符'/'所在的地址;还有char *strtok_r(char *str, const
阅读全文
摘要:只能是取成员运算符优先级 高于 取地址运算符优先级其实仔细想一下,如果不这样就乱套了。。。#include <stdio.h>typedef struct data_t{ int a;}data_t;int main(int argc, char* argv[]){ data_t data; data_t *p = &data; printf("取地址 %p\n", &data.a); printf("取地址 %p\n", &(data.a)); printf("取地址 %p\n", &p-
阅读全文
摘要:#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...
阅读全文
摘要: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) ...
阅读全文
摘要:约定协议: 客户端发送请求:char buf[256]=文件名 服务端回复: int len=文件长度 + 文件信息 若文件不存在返回 "-1" + "file not found\n" 若文件读取错误返回 "-2" + "server error\n" 若文件为目录 "-3" + "dirtory error\n"-----------TCP协议客户端流程--------------------创建socket 根据协议族,协议类型,协议编号,向操作系统申请一个socket
阅读全文
摘要:DNS无法Ping通是正常现象,为了避免恶意攻击,许多服务器都禁用了ICMP。出现该错误的原因是没开启DNS转发。对于Windows网络,如果安装了Active Directory服务,可以将工作站的DNS服务器设置为局域网内服务器的地址,即升级到支持Active Directory的主域计算机的IP地址,并在DNS服务中启用DNS转发(例如转发地址为202.96.128.143),估计这样就可以了。
阅读全文
摘要: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...
阅读全文
摘要:#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...
阅读全文
摘要:/*+------------------------------------------------------------------------+| 小端存储: 低地址存放低位数据; || 例: int型数 0x12 34 56 78 || | | || ...
阅读全文
摘要:#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
阅读全文