摘要:遇到一些重口味的客户,非得要求所有平台上按Windows API封装函数,记下备忘。根据MSDN,Windows似乎很不愿意支持ioctl和fcntl,专门弄进来一个ioctlsocket,传递的三个命令分别是FIONBIO用于设置阻塞属性,FIONREAD用于读取缓冲区未读字节数,SIOCATMARK用来测试TCP的紧急指针,网上一搜,发现Linux上也是有对应的这三个cmd,一些人甚至将这三个命令视为套接字常用命令,对于我这样的标准拥护者,就查了一下POSIX标准,发现:FIONREAD这个是文件的通用操作,用来获取可读字节,归属于ioctl函数的命令FIONBIO已经被fcntl(fd,
阅读全文
摘要:一个混音例程,多声道混音成单声道,录制下了原始声音和混音之后的声音。混音之后的声音是8kHz,16bit,带符号单声道的声音。#define ALSA_PCM_NEW_HW_PARAMS_API#include <alsa/asoundlib.h>#include <alloca.h>#include <stdio.h>void mixchannel(FILE *fp, const snd_pcm_channel_area_t *areas, unsigned int chs, snd_pcm_uframes_t offset, snd_pcm_uframe
阅读全文
摘要:用于字符串搜索的自动机实现,调用MachineCreate创建一个状态机,然后将字符流送入MachineCheck即可,代码实现:typedef void *StateMac_t;typedef struct { char c; int *map;}StateTable;typedef struct { int lastState; int curState; int tabSize; StateTable table[0];} MachineState;static int FitchUniqueList(char *buf, const char *st...
阅读全文
摘要:传说中的O(lgn)时间的快速算术算法和超大整数的取模算法。1.快速求积,a*b=a*2*b/2int fast_mul(int a, int b){ int m = 0; while(b){ if(b & 0x01){ //a*b = a+a(b-1) m += a; --b; }else{ //a*b = a*2*b/2 a <<= 1; b >>= 1; } } return m;}2.快速求...
阅读全文
摘要:IP报文内包装了一个ICMP报文,不过还是没法重组报文。想要练习重组报文似乎得直接抓链路层的包才行。#include <sys/types.h>#include <sys/socket.h>#include <sys/uio.h>#include <netdb.h>#include <linux/icmp.h>#include <linux/ip.h>#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <
阅读全文