ipv4

How to know the IP address for interfaces in C using IPv6

删除回忆录丶 提交于 2019-12-02 07:31:12
问题 Suppose I'd like a list of all IP addresses on my Linux machine by their interface names, using both IPv6 and IPv4. The best advice I could find is to use getifaddrs() that should support IPv6, similarly to a post from here. However, the getifaddrs() uses struct ifaddrs which uses struct sockaddr which is incompatible with IPv6. Instead, it should be a pointer to a union with struct in6_addr as well. How is this handled? How does getifaddrs() support IPv6? Is the documentation obsolete? 回答1:

Netty检查连接断开的几种方法

↘锁芯ラ 提交于 2019-12-02 07:00:56
最近项目中需要判定客户端是否还在线,需要用到心跳检测机制。这里做个笔记总结一下。 心跳检测机制: 网络中接收和发送数据都是通过操作系统的socket实现的。但是如果套接字已经断开,那发送和接收数据就会出问题。 但如何判断套接字是否断开了呢?这就需要建立一种机制,能够检测通信对方是否还存活。如果已经断开,就要释放资源。这种机制通常采用心跳检测实现。 所谓的“心跳”就是定时发送一个自定义的结构体(心跳包或心跳帧),让对方知道自己“在线”,以确保链接的有效性。心跳检测规定定时发送心跳检测数据包,接收方接心跳包后回复,否则认为连接断开。 一、Netty心跳检测方式 1、pipeline加入IdleStateHandler Netty提供了心跳检测类IdleStateHandler,它有三个参数,分别是读超时时间、写超时时间、读写超时时间。 1)readerIdleTime:读超时时间; 2)writerIdleTime:写超时时间; 3)allIdleTime:所有类型超时时间; 这里最重要是的readerIdleTime,当设置了readerIdleTime以后,服务端server会每隔readerIdleTime时间去检查一次channelRead方法被调用的情况,如果在readerIdleTime时间内该channel上的channelRead()方法没有被触发

Convert IPv4 to IPv6 manually

霸气de小男生 提交于 2019-12-02 03:54:40
After read this article i have a question: In the exapmle in this link there is explanation hot to convert 192.168.25.234 into equivalent IPv6 address so in the example this address become C0A8:19EA and it says that this can be written into the following 128-Bit IPv6 link-local address: FE80:0000:0000:0000:0000:0000:C0A8:19EA or FE80::C0A8:19EA So my question is how C0A8:19EA become FE80:0000:0000:0000:0000:0000:C0A8:19EA ? The C0, A8, 19 and EA are just 192, 168, 25 and 234 displayed in hex. The FE80 is a well-known prefix for link local. The rest is always all zero in this case (or for the

nginx+php7.0.x+redis+memcached环境搭建编译命令

♀尐吖头ヾ 提交于 2019-12-02 02:37:12
yum install gcc.x86_64 gcc-c++.x86_64 pcre-devel.x86_64 nginx+php+mysql 服务架设 wget http://www.openssl.org/source/openssl-1.0.2e.tar.gz ./config make wget http://zlib.net/zlib-1.2.8.tar.gz ./configure make wget http://nginx.org/download/nginx-1.9.9.tar.gz ./configure --prefix=/usr/local/nginx --without-select_module --without-poll_module --with-threads --with-http_ssl_module --with-http_v2_module --with-stream --with-pcre --with-openssl=/opt/software/openssl-1.0.2e/ --with-zlib=/opt/software/zlib-1.2.8 *unix 系统内核参数的配置 vi /etc/sysctl.conf net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter =

NGINX学习(八)--nginx优化配置

99封情书 提交于 2019-12-02 02:32:05
nginx指令中的优化(配置文件) worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数。 worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; 为每个进程分配cpu,上例中将8个进程分配到8个cpu,当然可以写多个,或者将一个进程分配到多个cpu。 worker_rlimit_nofile 102400; 这个指令是指当一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(ulimit -n)与nginx进程数相除,但是nginx分配请求并不是那么均匀,所以最好与ulimit -n的值保持一致。 use epoll; 使用epoll的I/O模型,这个不用说了吧。 worker_connections 102400; 每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为worker_processes*worker_connections。 keepalive_timeout 60; keepalive超时时间。 client_header_buffer_size 4k; 客户端请求头部的缓冲区大小,这个可以根据你的系统分页大小来设置,一般一个请求的头部大小不会超过1k

超级马里奥这个系统开发流程

两盒软妹~` 提交于 2019-12-02 02:10:02
关于超级马里奥这个APP开发的要求,可以问阮生(181微4289电8881)可以开发源码,毕竟是我。现成当然可以快速上线,流程我们以后再详谈。 端口号 在同一台主机或设备上,可能有多个进程同时在使用TCP或UDP协议,端口号的作用就是区分这些不同的进程,即每个进程使用各自不同的端口号。 对于TCP协议和UDP协议,端口号都是用unsigned short类型表示,即端口号的范围为0-65535,这65536个端口号被分为3段: 众所周知端口(well-known port):范围为0-1023,这些端口被赋予了专用功能,如FTP的21端口、Web的80端口等,应用程序不能将它们用作其他功能 已登记端口(registered port):范围为1024-49151 临时端口:范围为49152-65535 well-known端口在Unix系统中称为保留端口,使用保留端口的服务器程序,必须以root用户启动运行。 套接字对 TCP套接字对是定义TCP连接两个端点的四元组,包括:本地IP地址、本地端口号、对端IP地址、对端端口号,每个端点的IP地址和端口号通常称为一个套接字。 TCP套接字对可用于唯一标识一个网络中的TCP连接。 套接字地址结构 大多数套接字API都需要一个指向套接字地址结构的指针作为函数参数,每个协议族都定义它自己的套接字地址结构,这些结构的名字均以sockaddr

How show IPv4 only with REMOTE_ADDR in PHP?

放肆的年华 提交于 2019-12-01 22:19:02
I have a question with variable : $_SERVER['REMOTE_ADDR'] . I wish he recovers ONLY IP addresses in IPv4 format . It extracted me a few times in IPv6 format . How to do? $_SERVER['REMOTE_ADDR'] always contains the address of the visitor. If it contains an IPv6 address then the visitor used IPv6 and there is no IPv4 address. And vice versa of course. These days you have to be able to deal with both. Some visitors will have only IPv4, some will have only IPv6 and some will have both. The browser decides what is available and what it will use, and that's all you'll see. Note that a browser that

国内镜像

元气小坏坏 提交于 2019-12-01 22:02:39
1.企业贡献: 搜狐开源镜像站:http://mirrors.sohu.com/ 网易开源镜像站:http://mirrors.163.com/ 首都在线科技股份有限公司:http://mirrors.yun-idc.com/ 2.大学教学: <1>镜像较多内容: 西安电子科技大学: ftp://linux.xidian.edu.cn 哈尔滨工业大学: http://run.hit.edu.cn/ 大连理工大学: http://mirror.dlut.edu.cn/ 北京理工大学: http://mirror.bit.edu.cn (IPv4 only) http://mirror.bit6.edu.cn (IPv6only) 北京交通大学: http://mirror.bjtu.edu.cn (IPv4 only) http://mirror6.bjtu.edu.cn (IPv6 only) http://debian.bjtu.edu.cn(IPv4+IPv6) 兰州大学:http://mirror.lzu.edu.cn/ 厦门大学:http://mirrors.xmu.edu.cn/ 上海交通大学: http://ftp.sjtu.edu.cn/ (IPv4 only) http://ftp6.sjtu.edu.cn (IPv6 only) 清华大学: http:/

Python urllib2 force IPv4

不打扰是莪最后的温柔 提交于 2019-12-01 17:44:07
I am running a script using python that uses urllib2 to grab data from a weather api and display it on screen. I have had the problem that when I query the server, I get a "no address associated with hostname" error. I can view the output of the api with a web browser, and I can download the file with wget, but I have to force IPv4 to get it to work. Is it possible to force IPv4 in urllib2 when using urllib2.urlopen? Not directly, no. So, what can you do? One possibility is to explicitly resolve the hostname to IPv4 yourself, and then use the IPv4 address instead of the name as the host. For

Efficient way to store IPv4/IPv6 addresses

↘锁芯ラ 提交于 2019-12-01 17:00:06
问题 I am working on a C/C++ networking project that it should be able to both use the IPv4 and IPv6 networking stacks. The project works only on Linux. So, I tried to find an efficient way to store the IP addresses and differentiate between the protocol families. The first approach was to have a union: struct ip_addr { uint8_t fam; // socket family type union { struct in_addr ipv4_sin_addr; struct in6_addr ipv6_sin_addr; }addr; }; The second approach was to define a typedef std::vector<unsigned