您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ sendto函数代码示例

51自学网 2021-06-03 07:35:57
  C++
这篇教程C++ sendto函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中sendto函数的典型用法代码示例。如果您正苦于以下问题:C++ sendto函数的具体用法?C++ sendto怎么用?C++ sendto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了sendto函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

//.........这里部分代码省略.........		perror("socket(DIVERT)");		exit(2);	}	sd = r;	sin.sin_port = htons(portnum);	sin.sin_family = AF_INET;	sin.sin_addr.s_addr = INADDR_ANY;	if (bind(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {		perror("bind(divert)");		exit(3);	}	p = pcap_open_dead(DLT_RAW, BUFMAX);	dp = pcap_dump_open(p, dumpf);	if (dp == NULL) {		pcap_perror(p, dumpf);		exit(4);	}	okay(portnum);	nfd = sd + 1;	for (;;) {		FD_ZERO(&rds);		FD_SET(sd, &rds);		r = select(nfd, &rds, NULL, NULL, NULL);		if (r == -1) {			if (errno == EINTR) continue;			perror("select");			quit(11);		}		if (!FD_ISSET(sd, &rds))			/* hmm. no work. */			continue;		/*		 * use recvfrom(3 and sendto(3) as in natd(8).		 * see /usr/src/sbin/natd/natd.c		 * see ipfw(8) about using 'divert' and 'tee'.		 */		/*		 * read packet.		 */		l = sizeof(sin);		nr = recvfrom(sd, buf, sizeof(buf), 0, (struct sockaddr *)&sin, &l);if (debug) fprintf(stderr, "recvfrom(%d) = %zd (%d)/n", sd, nr, l);		if (nr < 0 && errno != EINTR) {			perror("recvfrom(sd)");			quit(12);		}		if (nr <= 0) continue;		if (reflect) {			/*			 * write packet back so it can continue			 * being processed by any further IPFW rules.			 */			l = sizeof(sin);			r = sendto(sd, buf, nr, 0, (struct sockaddr *)&sin, l);if (debug) fprintf(stderr, "  sendto(%d) = %d/n", sd, r);			if (r < 0) { perror("sendto(sd)"); quit(13); }		}		/*		 * check maximums, if any.		 * but don't quit if must continue reflecting packets.		 */		if (maxpkts) {			totpkts++;			if (totpkts > maxpkts) {				if (reflect == 1) continue;				quit(0);			}		}		if (maxbytes) {			totbytes += nr;			if (totbytes > maxbytes) {				if (reflect == 1) continue;				quit(0);			}		}		/*		 * save packet in tcpdump(1) format. see pcap(3).		 * divert packets are fully assembled. see ipfw(8).		 */		(void) gettimeofday(&(phd.ts), NULL);		phd.caplen = phd.len = nr;		pcap_dump((u_char *)dp, &phd, buf);		if (ferror((FILE *)dp)) { perror(dumpf); quit(14); }		(void) fflush((FILE *)dp);	}	quit(0);}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:101,


示例2: main

int main(){  int s, len, nbytes, one = 1;  static struct sockaddr_in sin;  static struct ip_mreq imr;  char  buf[100];  if ((s = socket (AF_INET, SOCK_DGRAM, 0)) == -1)  {    perror("socket");    return 1;  }  if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (one)) == -1)  {    perror("setsockopt: SO_REUSEADDR");    exit(1);  }#ifdef SO_REUSEPORT  /*   * This must be added for OSF1 v2.x (and BSD 4.3)   */  if (setsockopt (s, SOL_SOCKET, SO_REUSEPORT, (char *) &one, sizeof (one)) == -1)   {    perror("setsockopt: SO_REUSEADDR");    exit(1);  }#endif  sin.sin_family = AF_INET;  sin.sin_port   = htons (PORT);  sin.sin_addr.s_addr = htonl (INADDR_ANY);  if (bind (s, (struct sockaddr *) & sin, sizeof (sin)) == -1)   {    perror ("bind");    return 1;  }  /*   * the original posting was = htonl(inet_addr (GROUP))    * which is wrong.   *   * Send greeting message to multicast group:    */  sin.sin_addr.s_addr = inet_addr (GROUP);  if (sendto (s, "Hi!", 4, 0, (struct sockaddr *) & sin, sizeof (sin)) == -1)   {    perror("socket");    return 1;  }  /*   * Join the group:    * IP multicast address of group:   * local IP address of interface:   */   imr.imr_multiaddr = sin.sin_addr;  imr.imr_interface.s_addr = htonl (INADDR_ANY);  if (setsockopt (s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &imr, sizeof (imr)) == -1)  {    /*     * The original posting did not include this:     * [email
C++ sendto_channel_local函数代码示例
C++ sendmessage函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。