setsockopt

Duplicate packets in Multicast Receiver Socket [duplicate]

有些话、适合烂在心里 提交于 2019-12-04 10:23:08
This question already has an answer here: Receiving multiple multicast feeds on the same port - C, Linux 8 answers There seems to be a bug in the following MulticastReceiver implementation. On creating two instances for <224.0.25.46,13001> and <224.0.25.172,13001>, I get each packet twice in each stream. Any pointers ? My guess is REUSEADDR ? class MulticastReceiverSocket { protected: const std::string listen_ip_; const int listen_port_; int socket_file_descriptor_; public: MulticastReceiverSocket ( const std::string & listen_ip, const int listen_port ) : listen_ip_ ( listen_ip ), listen_port_

Socket buffer size not increasing

和自甴很熟 提交于 2019-12-03 17:45:41
int n = 0; if ( 0 != getsockopt(iSockFd,SOL_SOCKET,SO_RCVBUF, &n, sizeof(n))) { printf("Get socket option failed, errno: %d\n",errno); } else { printf("Current socket buff len = %d\n", n); } n = 225280; if(0 != setsockopt(iSockFd, SOL_SOCKET, SO_RCVBUF, (const void *)&n, sizeof(n))) { printf("setsock err errno %d\n", errno); } else { printf("setsock opt success\n"); } n = 0; if ( 0 != getsockopt(iSockFd,SOL_SOCKET,SO_RCVBUF, &n, sizeof(n))) { printf("Get socket option failed, errno: %d\n",errno); } else { printf("After setting socket buff len = %d\n", n); } Output is - Current socket buff len

What was the motivation for adding the IPV6_V6ONLY flag?

陌路散爱 提交于 2019-12-03 14:48:49
问题 In IPv6 networking, the IPV6_V6ONLY flag is used to ensure that a socket will only use IPv6, and in particular that IPv4-to-IPv6 mapping won't be used for that socket. On many OS's, the IPV6_V6ONLY is not set by default, but on some OS's (e.g. Windows 7), it is set by default. My question is: What was the motivation for introducing this flag? Is there something about IPv4-to-IPv6 mapping that was causing problems, and thus people needed a way to disable it? It would seem to me that if someone

套接字选项

▼魔方 西西 提交于 2019-12-03 11:46:47
之前读过unix网络编程,现在在看nginx源码,很多套接字选项不记得了,因此每遇到一个套接字选项就在此文章中进行补充。 1.获取和设置套接字选项的方法: getsockopt,setsockopt函数 fcntl函数 ioctl函数 2.4种函数简介: I.getsockopt,setsockopt函数 int getsockopt(int sockfd,int level,int optname,void *optval,socklen_t *optlen); int setsockopt(int sockfd,nt level,int optname,const void* optval,socklen_t optlen); sockfd必须是一个打开的套接字描述符,level指定系统中解释选项的代码或为通用套接字代码或为某个特定于协议的代码。optval 是一个指向某个变量的指针,setsockopt从*optval中取得选项待设置的新值,getsockopt则将获取的选项值放入*optval中。*optval的大小由最后一个参数指定,因此,获取或者设置的数据类型一定要一一对应。 3.套接字选项: 这里我将分不同的level来进行描述,但套接字选项可能和书上的顺序不同,标志字段为0表示禁用,否则启用。 I.SOL_SOCKET SO_KEEPALIVE,可获得,可设置

Is it possible to activate TCP keepalive on Apple iOS devices

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Apple device === Router === WiFi module Apple device(iPhone) is connecting to WiFi module port 2000 with TCP connection. I want to activate TCP keepalive packet sending on Apple device to find out when TCP connection to WiFi module is lost (module is switched off). My stream setup CFReadStreamRef readStream; CFWriteStreamRef writeStream; CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)CFBridgingRetain(moduleIPaddress), port2000, &readStream, &writeStream); outputStream = (NSOutputStream *)CFBridgingRelease(writeStream); inputStream =

setsockopt调用IP_ADD_MEMBERSHIP出错errno:19 no such device

匿名 (未验证) 提交于 2019-12-02 22:56:40
if (setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq)) < 0) { 提示: setsockopt fail, try again 这主要和当前的网络配置有关,因为多播IP地址没有加入到路由表中。 解决方法 :把需要用到的多播地址(如本例的224.0.0.88)加入到路由表中,命令如下: 224.0.0.88:为当前使用的多播IP地址 eth0:为当前使用的有效网卡 其它辅助命令: sudo route del -net 224.0.0.88 netmask 255.255.255.255 eth0 route -n 文章来源: setsockopt调用IP_ADD_MEMBERSHIP出错errno:19 no such device

How do I set `SO_RCVTIMEO` on a socket in Perl?

别等时光非礼了梦想. 提交于 2019-12-02 08:26:42
问题 If I try like this: my $sock = IO::Socket::INET->new( … ) or die "no socket for you"; defined $sock->setsockopt(SOL_SOCKET, SO_RCVTIMEO, 30) or die "setsockopt: $!"; then my script suffers death from "setsockopt: Invalid argument at [line 2]". The IO::Socket and perlfunc pods do not say, though perlfunc gives an example with TCP_NODELAY which makes it look like the above should work. ( quick note: I've answered my own question, as best I can, but certainly welcome a better answer. The most

How do I set `SO_RCVTIMEO` on a socket in Perl?

谁说我不能喝 提交于 2019-12-02 07:15:51
If I try like this: my $sock = IO::Socket::INET->new( … ) or die "no socket for you"; defined $sock->setsockopt(SOL_SOCKET, SO_RCVTIMEO, 30) or die "setsockopt: $!"; then my script suffers death from "setsockopt: Invalid argument at [line 2]". The IO::Socket and perlfunc pods do not say, though perlfunc gives an example with TCP_NODELAY which makes it look like the above should work. ( quick note: I've answered my own question, as best I can, but certainly welcome a better answer. The most obvious "better" would be for it to be portable, at least on POSIX machines) By using strace on the Perl

How to set TCP_NODELAY flag when loading URL with urllib2?

余生颓废 提交于 2019-12-01 15:12:12
I am using urllib2 for loading web-page, my code is: httpRequest = urllib2.Request("http:/www....com") pageContent = urllib2.urlopen(httpRequest) pageContent.readline() How can I get hold of the socket properties to set TCP_NODELAY ? In normal socket I would be using function: socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) If you need to access to such low level property on the socket used, you'll have to overload some objects. First, you'll need to create a subclass of HTTPHandler , that in the standard library do : class HTTPHandler(AbstractHTTPHandler): def http_open(self, req

Setting TCP receive window in C and working with tcpdump in Linux

蹲街弑〆低调 提交于 2019-11-30 02:39:42
问题 I am running a Linux box running 2.6.9-55.ELsmp, x86_64. I am trying to set the TCP receive window by using the setsockopt() function using C. I try the following: rwnd = 1024; setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&rwnd, sizeof(rwnd)); The code segment above is in a client program that receives data from a server. When I kick off the program to receive and observe tcpdump output, I observe window negotiation like so: 11:34:40.257755 IP clientReceiver.42464 > serverSender.8991: S