当前位置: 首页>>代码示例>>C++>>正文


C++ TCPClient::sendSynAck方法代码示例

本文整理汇总了C++中TCPClient::sendSynAck方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPClient::sendSynAck方法的具体用法?C++ TCPClient::sendSynAck怎么用?C++ TCPClient::sendSynAck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCPClient的用法示例。


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

示例1: tick


//.........这里部分代码省略.........
								icmp = (struct icmp_packet *)ipdata;

								switch(icmp->type)
								{
									case ICMP_ECHO:
										icmp->type = ICMP_ECHOREPLY;
										memcpy(rx.header.ether_dhost,rx.header.ether_shost,6);
										memcpy(rx.header.ether_shost,iface->mac,6);
										memcpy(ip->daddr,ip->saddr,4);
										ip->saddr[3] = iface->ip & 0xFF;
										ip->saddr[2] = iface->ip>>8 & 0xFF;
										ip->saddr[1] = iface->ip>>16 & 0xFF;
										ip->saddr[0] = iface->ip>>24 & 0xFF;
										
										icmp->checksum = 0;
										icmp->checksum = htons(checksum16(ipdata,ipdlen,CS_IP));

										iface->queueTX((unsigned char *)&rx,len);
										break;
								}
								break;
							case IPPROTO_UDP:
								udp = (struct udp_packet *)ipdata;
								for(i=0; i<MAX_PORTS; i++)
								{
									if(this->udp_ports[i] != NULL)
									{
										if(this->udp_ports[i]->port == ntohs(udp->destPort))
										{
											this->udp_ports[i]->addPacket(len,&rx);
										}
									}
								}
								break;
							case IPPROTO_TCP:
								tcp = (struct tcp_packet *)ipdata;
								for(i=0; i<MAX_PORTS; i++)
								{
									if(this->tcp_clients[i]!=NULL)
									{
										if(this->tcp_clients[i]->socketMatch(ntohs(tcp->destPort), ntohs(tcp->sourcePort), 
											quad2ip(ip->saddr[0],ip->saddr[1],ip->saddr[2],ip->saddr[3]))==1)
										{
											cli = this->tcp_clients[i];
											cli->handleIncomingPacket(ip);
										}
									}
									if(this->tcp_servers[i]!=NULL)
									{
										// Packet coming in to a listening socket
										if((this->tcp_servers[i]->localPort == ntohs(tcp->destPort)) &&
											(this->tcp_servers[i]->state == TCP_LISTEN))
										{
											svr = this->tcp_servers[i];
											// Try and match it with an existing connection
											cli = NULL;
											for(i=0; i<MAX_TCP_CONNECTIONS; i++)
											{
												if(svr->connections[i].state!=TCP_CLOSED)
												{
													if(svr->connections[i].socketMatch(ntohs(tcp->destPort), ntohs(tcp->sourcePort), 
														quad2ip(ip->saddr[0],ip->saddr[1],ip->saddr[2],ip->saddr[3]))==1)
													{
														cli = &svr->connections[i];
														cli->handleIncomingPacket(ip);
													}
												}
											}
											// Not an existing connections.  If it's a SYN then start a connection up
											if(cli==NULL)
											{
												if(tcp->syn==1 && tcp->ack==0)
												{
													est = svr->getFreeConnection();
													if(est!=NULL)
													{
														est->localPort = svr->localPort;
														est->peerPort = ntohs(tcp->sourcePort);
														est->peerAddress = quad2ip(ip->saddr[0],ip->saddr[1],ip->saddr[2],ip->saddr[3]);
														est->tx_mss=1440;
														est->irs = ntohl(tcp->sequence);
														est->rx_nxt = est->irs+1;
														est->iss = rand();
														est->tx_nxt = est->iss;
														est->sendSynAck();
														est->state=TCP_ESTABLISHED;
													}
												}
											}
										}
									}
								}
								break;
							default:
								break;
						}
						break;
					default:
						break;
				}
开发者ID:AJoao,项目名称:embeddedlibs,代码行数:101,代码来源:Network.cpp


注:本文中的TCPClient::sendSynAck方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。