- 浏览: 1477816 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (691)
- linux (207)
- shell (33)
- java (42)
- 其他 (22)
- javascript (33)
- cloud (16)
- python (33)
- c (48)
- sql (12)
- 工具 (6)
- 缓存 (16)
- ubuntu (7)
- perl (3)
- lua (2)
- 超级有用 (2)
- 服务器 (2)
- mac (22)
- nginx (34)
- php (2)
- 内核 (2)
- gdb (13)
- ICTCLAS (2)
- mac android (0)
- unix (1)
- android (1)
- vim (1)
- epoll (1)
- ios (21)
- mysql (3)
- systemtap (1)
- 算法 (2)
- 汇编 (2)
- arm (3)
- 我的数据结构 (8)
- websocket (12)
- hadoop (5)
- thrift (2)
- hbase (1)
- graphviz (1)
- redis (1)
- raspberry (2)
- qemu (31)
- opencv (4)
- socket (1)
- opengl (1)
- ibeacons (1)
- emacs (6)
- openstack (24)
- docker (1)
- webrtc (11)
- angularjs (2)
- neutron (23)
- jslinux (18)
- 网络 (13)
- tap (9)
- tensorflow (8)
- nlu (4)
- asm.js (5)
- sip (3)
- xl2tp (5)
- conda (1)
- emscripten (6)
- ffmpeg (10)
- srt (1)
- wasm (5)
- bert (3)
- kaldi (4)
- 知识图谱 (1)
最新评论
-
wahahachuang8:
我喜欢代码简洁易读,服务稳定的推送服务,前段时间研究了一下go ...
websocket的helloworld -
q114687576:
http://www.blue-zero.com/WebSoc ...
websocket的helloworld -
zhaoyanzimm:
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
nginx的helloworld模块的helloworld -
haoningabc:
leebyte 写道太NB了,期待早日用上Killinux!么 ...
qemu+emacs+gdb调试内核 -
leebyte:
太NB了,期待早日用上Killinux!
qemu+emacs+gdb调试内核
tapper.c
#include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <linux/if.h> #include <linux/if_tun.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/select.h> #include <err.h> #include <arpa/inet.h> /* inet_addr() & co. */ #include <netinet/in.h> /* INET_ADDRSTRLEN */ /* for uint16_t */ #include <stdint.h> #define ERR_CANT_TAP 1 #define ERR_OPEN_ERR 2 #define ERR_READ_ERR 3 #define ERR_WRITE_ERR 4 static int primary_fd; /* a copy of the filedescriptor for tap device */ static int enable_tuntap_headers = 0; /* CLI option - will we permit tuntap protocol headers */ static int enable_tapper_headers = 0; /* CLI option - will we enable tapper's headers */ static int enable_verbose = 0; /* CLI option - print out extra debug info on stderr */ //static const char DEFAULT_IP[] = "10.0.2.2"; static const char DEFAULT_IP[] = "10.0.2.1"; static const char DEFAULT_NETMASK[] = "255.255.0.0"; #define VERBOSE(x, ...) if(enable_verbose >= 1) { warnx("NOTE: " x, ##__VA_ARGS__); } #define DEBUG(x, ...) if(enable_verbose >= 2) { warnx("DEBUG: " x, ##__VA_ARGS__); } /* following function creates a tap device */ /* it also returns device name in 'newdev' */ int createTap(char *newdev, int bufferlen) { struct ifreq ifr; int fd=open("/dev/net/tun", O_RDWR); /* open the tap device */ if(fd<0) /* handle error */ err(ERR_CANT_TAP, "Could not create a TAP device"); memset(&ifr, 0, sizeof(ifr)); /* initialize the structure specifying data about net device */ ifr.ifr_flags=IFF_TAP; /* we want a tap device, not a tun device */ if(!enable_tuntap_headers) /* by default we won't include tuntap driver's headers */ ifr.ifr_flags|=IFF_NO_PI; if((ioctl(fd, TUNSETIFF, (void*)&ifr))<0) /* tell our device what we want it to do */ { close(fd); /* if we failed close and abort */ err(ERR_CANT_TAP, "Could not create a TAP device because of ioctl()"); } strncpy(newdev, ifr.ifr_name, bufferlen-1); /* return the generated device name */ newdev[bufferlen-1] = '\0'; return fd; } /* when we exit we want to clean up */ void atex(void) { close(primary_fd); /* close the tap network device */ } /* usage */ void usage(void) { printf("usage:\n" "\n" " ./tapper [--tuntap-headers] [--tapper-headers]" " [--ip-address %s] [--netmask %s] [--randomize-ip]" " [-v] [stdinfile stdoutfile]\n" "\n", DEFAULT_IP, DEFAULT_NETMASK); exit(0); } int main(int argc, char ** argv) { #define BUFFERSIZE 2000 /* must be larger than MTU - 1500 */ #define DEVNAMESIZE 25 int fd; /* file descriptor of the tap device; shorthand for primary_fd */ char devname[DEVNAMESIZE]={0}; /* initialize device name (where we'll pick up the generated dev name) to zeros so it doesn't look like we're sending a device name in*/ char buf[BUFFERSIZE]; /* buffer for receiving stuff */ in_addr_t ip = inet_addr(DEFAULT_IP); in_addr_t netmask = inet_addr(DEFAULT_NETMASK); char ip_s[INET_ADDRSTRLEN]; char netmask_s[INET_ADDRSTRLEN]; int argoff; /* argument offset; used for parsing CLI */ for(argoff = 1; argoff < argc; argoff++) { if(!strcmp(argv[argoff], "-h")) usage(); else if(!strcmp(argv[argoff], "--tuntap-headers")) enable_tuntap_headers = 1; else if(!strcmp(argv[argoff], "--tapper-headers")) enable_tapper_headers = 1; else if(!strcmp(argv[argoff], "-v")) enable_verbose++; else if(!strcmp(argv[argoff], "--ip-address")){ if(argoff == argc-1) usage(); ip = inet_addr(argv[++argoff]); if(ip == INADDR_NONE) errx(12, "%s: malformed ip address", argv[argoff]); DEBUG("ip address: %s", inet_ntoa(*(struct in_addr*)&ip)); }else if(!strcmp(argv[argoff], "--netmask")){ if(argoff == argc-1) usage(); netmask = inet_addr(argv[++argoff]); if(netmask == INADDR_NONE) errx(13, "%s: malformed netmask address", argv[argoff]); DEBUG("netmask: %s", inet_ntoa(*(struct in_addr*)&netmask)); }else if(!strcmp(argv[argoff], "--randomize-ip")){ srand(time(NULL)+devname[3]); /* we want our ip address to depend on time, and on last symbol in device name. dev name is always a three-letter 'tap' + number, and let's just presume it's a single digit num */ uint32_t *ip_int = (uint32_t*)&ip; uint32_t *netmask_int = (uint32_t*)&netmask; uint32_t local = (uint32_t)rand() & ~*netmask_int; if(local == 0) local = 1; *ip_int |= local; DEBUG("randomized ip address: %s", inet_ntoa(*(struct in_addr*)&ip)); } else break; } VERBOSE("verbosity: %d", enable_verbose); if(enable_tuntap_headers) VERBOSE("permitting tuntap headers"); if(enable_tapper_headers) VERBOSE("using tapper headers"); if(argc - argoff >= 2) { /* we can receive two arguments: - file we'll use for reading in place of stdin - file we'll use for writing in place of stdout */ close(0); close(1); VERBOSE("using %s for input and %s for output", argv[argoff], argv[argoff+1]); if(!fopen(argv[argoff], "r")) err(10, "fopen(%s, r)", argv[argoff]); if(!fopen(argv[argoff+1], "w")) err(11, "fopen(%s, w)", argv[argoff+1]); } /* get ip address and netmask as strings */ inet_ntop(AF_INET, &ip, ip_s, INET_ADDRSTRLEN); inet_ntop(AF_INET, &netmask, netmask_s, INET_ADDRSTRLEN); ip_s[INET_ADDRSTRLEN-1] = '\0'; netmask_s[INET_ADDRSTRLEN-1] = '\0'; /* let's create a tap device */ primary_fd=createTap(devname, DEVNAMESIZE); /* configure ip address and netmask */ snprintf(buf, sizeof(buf), "ifconfig %s inet %s netmask %s up", devname, ip_s, netmask_s); VERBOSE("configuring ip and netmask: %s", buf); system(buf); fd=primary_fd; /* store primary_fd into a shorthand */ if (fd<0) /* error with creating tap? tough luck, let's bail out */ err(ERR_OPEN_ERR, "open()"); atexit(atex); /* when the loop is aborted, cleanup */ while(1){ int readies, i; /* since we're trying to create a twoway tunnel between stdio and the tap device we need to do monitoring via select(). we simply don't know which one will send us data first. */ fd_set fds; FD_ZERO(&fds); /* init set of file descriptors */ FD_SET(fd,&fds); /* add tap device to set */ FD_SET(0,&fds); /* add stdin to set */ readies=select(fd+1, &fds, NULL, NULL, NULL); /* monitor the set. the first param is max fd we monitor +1 (as usual with select()). here that's fd. */ if(readies<=0) err(readies, "Not ready"); /* we passed a timeoutless select() with 0 active fds? ouch. */ for(i=0;i<2;i++){ /* some arcane magic to make the loop simple. i was lazy to cut paste code. basically first the fd_int is stdin (0) and fd_oth is our tap device (fd). then the fd_int is tap device (fd) and fd_oth is the stdout (1). */ int fd_int=i*fd; int fd_oth=abs(fd-i*fd); if(!fd_oth) fd_oth=1; /* is the currently monitored fd_int (first stdin, then tap) actually the one causing select() to unblock? */ if(FD_ISSET(fd_int, &fds)){ if(!enable_tapper_headers || fd_int != 0){ /* yay! that one has something to say. let's read as much as possible for our buffer. num of actually read bytes is stored in ret, unless it's -1 which is error */ ssize_t ret = read(fd_int, buf, BUFFERSIZE); if (!ret) { errx(100, "read(): nothing to read expecting data"); continue; } if (ret < 0) err(ERR_READ_ERR, "read(%d) for data", fd_int); /* using headers? then the fd_oth is the stdout. first, send the number of bytes we'll dispatch */ if(enable_tapper_headers){ uint16_t size = (uint16_t)htons(ret); /* copying because we want to do one write, not two */ char * with_headers = malloc(sizeof(size) + ret); memcpy(with_headers, &size, sizeof(size)); memcpy(with_headers + sizeof(size), buf, ret); if(write(fd_oth, with_headers, sizeof(size) + ret)<0) err(ERR_WRITE_ERR, "write(%d)", fd_oth); DEBUG("wrote %lu bytes", sizeof(size) + ret); free(with_headers); }else{ /* write ret bytes into fd_oth; that's all the bytes we read */ if(write(fd_oth, buf, ret)<0) err(ERR_WRITE_ERR, "write(%d)", fd_oth); } }else{ /* new codepath: buffer stdin until filled with enough data */ /* only executed for stdin, and if tapper headers are enabled */ static uint16_t expected_size = 0; static size_t current_buffer_content_size = 0; if(!expected_size){ ssize_t ret = read(fd_int, &expected_size, sizeof(uint16_t)); if(!ret) { errx(101, "read(): nothing to read expecting message size"); continue; } if (ret < 0) err(ERR_READ_ERR, "read(%d) for message size", fd_int); expected_size = ntohs(expected_size); DEBUG("now expecting %d bytes", expected_size); }else{ size_t bytes_left = expected_size - current_buffer_content_size; ssize_t ret = read(fd_int, buf + current_buffer_content_size, bytes_left); if(!ret){ errx(102, "read(): nothing to read expecting buffer content"); continue; } if (ret < 0) err(ERR_READ_ERR, "read(%d) for buffer content", fd_int); current_buffer_content_size += ret; DEBUG("received %lu bytes; buffer now %lu/%hu", ret, current_buffer_content_size, expected_size); if(current_buffer_content_size == expected_size){ DEBUG("got all content"); /* write ret bytes into fd_oth; that's all the bytes we read */ if(write(fd_oth, buf, ret)<0) err(ERR_WRITE_ERR, "write(%d)", fd_oth); current_buffer_content_size = 0; expected_size = 0; } } } } } } /* never happens */ return 0; }
发表评论
-
sdl笔记
2019-01-31 17:19 733sdl教程教程 https://github.com/Twin ... -
tinyemu
2019-01-24 17:59 1433参考https://bellard.org/jslinux/t ... -
jslinux总结帖
2019-01-04 21:33 1134注意个问题: chrome不要用两个tab页,否则ping不通 ... -
br0和tap0的互相影响
2019-01-02 19:17 814转载 http://www.cnblogs.com/wlei/ ... -
emscripten asm.js的helloworld
2018-03-01 20:15 1110mac下安装: brew install SDL2 SDL2_ ... -
nginx代理wss和https
2018-02-27 15:34 3929nginx启用ssl yum install openssl ... -
M版openstack(ovs,dvr,动态迁移)
2017-06-09 10:30 1788主要内容 1.先搭建三个节点的环境,dvr模式 2.建一个vm ... -
M版本的openstack的例子(linuxbridge)
2017-05-23 15:05 557做两个节点控制节点和计算节点 mcontroller521 ... -
jslinux-deobfuscated-network
2017-02-13 22:37 714基础知识 查看网络包 tcpdump -i eth0 -e ... -
用buildroot为jslinux建立最小rootfs
2016-11-18 17:59 1270############################### ... -
jslinux带网络功能的内核
2016-11-15 15:35 810想重新编译jslinux-network 的内核,其实就是比f ... -
Tunnels with iproute2
2016-11-14 15:22 585copy from http://members.ferrar ... -
nginx rewrite替代apache rewrite
2016-10-18 20:30 834清理chrome的缓存 chrome://appcache-i ... -
vxlan多台主机的vm之间不同网段互通
2016-09-19 21:06 4373组播: 试验: 在三台机器上 192.168.139.251 ... -
vxlan多台主机的vm之间相同网段互通
2016-09-19 16:30 2239三台机器 建立namespace ... -
qemu用tap方式启动vm的网络试验(ip route)
2016-09-14 11:29 2806ip route add 192.168.8.0/24 via ... -
openstack的M版本的neutron的实验
2016-09-01 20:00 3131试验步骤: 1.创建内部 ... -
socket的方式使用qemu建立虚拟机
2016-06-24 17:54 1910qemu的-net参数 -net nic 必须有,基本配置mo ... -
tap的方式使用qemu建立虚拟机NAT网络
2016-06-23 18:03 9849基本概念: vm:虚拟机 ... -
qemu用nat的方式使用tap建立虚拟机
2016-06-23 16:15 11普通桥接参考 http://haoningabc.iteye. ...
相关推荐
3. **持续集成(CI)**:在持续集成服务器如Jenkins、Travis CI或CircleCI中,TAP格式的测试报告可以被轻松地解析和展示,使得团队成员能够快速了解测试状态。 4. **第三方库**:如Jython(Python的Java实现)和...
FT2232C JTAG函数库是针对FT2232C芯片设计的一个用于进行JTAG(Joint Test Action Group)通信的C语言程序库。FT2232C是一款多协议USB到串行接口集成电路,它支持多种不同的通信协议,如UART、SPI、I²C、JTAG等。这...
在ELEC 4700这门课程中,学生可能被要求研究和应用TAPA技术,特别是在PA 6的设计上下文中。 标题中的“TAPA:ELEC 4700中用于PA 6的回购”可能指的是一个项目或课程作业,其中学生需要分析或重新设计PA 6,利用TAPA...
《iPhone开发基础教程》是一本面向初学者的iOS开发...总之,《iPhone开发基础教程》的源代码涵盖了iOS开发的多个重要方面,通过学习和实践这些代码,初学者能够逐步建立起扎实的iOS开发基础,从而迈向专业开发者之路。
嵌入式开发是现代电子设备设计的核心部分,尤其是在物联网和智能设备领域。由于大多数开发者习惯于Windows操作系统,并且Windows提供了丰富的开发工具,因此在Windows环境下建立Linux嵌入式开发平台具有显著的优势。...
C代码部分通常用于实现模糊控制器的实时运行,与电力系统硬件设备交互,调整变压器的分接开关,以达到期望的电压调节效果。而Matlab部分则用于设计和测试模糊控制算法,通过仿真验证控制策略的性能,便于快速迭代和...
错误的连接可能导致JTAG链路无法建立,从而无法识别到Cortex-M设备。 2. **BOOT引脚配置**:STM32的BOOT引脚用于设置启动模式,当BOOT1和BOOT0处于特定状态时,会进入不同的启动模式。在某些情况下,如果BOOT1被拉...
- **建立蓝牙连接**:接收端设备通过NFC与发送端建立蓝牙连接。 - **数据接收**:接收端设备通过蓝牙接收发送端设备传输过来的大数据。 #### 结论 本文总结了NFC的基本概念、硬件结构、Android系统中的总体框架...
接下来,通过以下C#代码片段创建一个进程来检查设备或模拟器是否已连接: ```csharp ProcessStartInfo startInfo = new ProcessStartInfo("adb", "devices"); startInfo.CreateNoWindow = true; startInfo....
用于MATLAB:registered:的Jenkins:trade_mark:插件使您能够运行MATLAB和Simulink:registered:测试并生成工件,例如PDF测试报告,JUnit和TAP测试结果以及Cobertura代码或模型覆盖率报告。 您也可以使用该插件导出...
我保持醒着状态-Erykah Badu建立包容性的工作环境对于健康,支持和富有生产力的文化以及每个人都感到受欢迎和包容的环境势在必行。 woke是一个文本文件分析工具,可以在源代码中查找包含非包容性语言的位置,并建议...
DE2-70是一款由台湾友晶公司生产的FPGA开发板,它采用了Altera公司的EP2C70F896C6 FPGA芯片作为核心处理器。这款开发板主要面向FPGA/SOPC(System-On-a-Programmable-Chip)领域的初学者,提供了丰富的实验指导和...
在本节的学习IOS实例(2)中,我们将深入...通过实际操作和代码分析,你可以逐步建立自己的iOS开发技能,为成为专业的iOS开发者打下坚实基础。在实践中不断探索,你会发现iOS开发不仅有趣,而且充满了创造的可能性。
JTAG最初是为了电路板级测试而设计的,它通过一个四线接口(TMS、TCK、TDI和TDO)连接到目标设备,形成一个TAP(Test Access Port)控制器。这些线分别代表测试模式选择(TMS)、时钟(TCK)、数据输入(TDI)和数据...
### 一、建立工作库文件夹和编辑设计文件 在开始任何设计之前,首先需要创建一个用于存放设计文件的工作库文件夹。这个文件夹将是项目的基础,其中将包含所有的设计文件、工程文件以及其他辅助文件等。接下来,使用...
()是实际的执行被测对象的程序代码,输入实现设计好的测试用例,检查程序代码运行得到的结果与测试用力中设计的预期结果之间是否有差异,判定实际结果与预测结果是否一致。** - **选项解析:** - **A. 集成测试...
根据光栅衍射理论,可以通过建立矩阵方程来解决该问题。这里我们定义了几个关键矩阵: - **A**: 零矩阵 - **B**: 单位矩阵 - **C**: 用于存储方程组中的系数 - **D**: 存储方程组中的另一组系数 接下来,通过循环...
客户端同样采用异步连接,这意味着在尝试建立与服务器的连接时,程序不会被阻塞,用户界面仍能保持交互性。此外,异步接收和发送数据让客户端能在等待数据传输的同时执行其他任务,提高了用户体验。 在VS2008中,C#...