Hot Search : Source embeded web remote control p2p game More...
Location : Home Search - sendto
Search - sendto - List
一个判断远程主机存活程序代码(ping) #include #include #include #include #include "winsock.h" #pragma comment(lib,"Ws2_32"); #define SEND_SIZE 32 #define PACKET_SIZE 4096 #define ICMP_ECHO 8 #define ICMP_ECHOREPLY 0 struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; unsigned short icmp_id; unsigned short icmp_seq; unsigned long icmp_data; }; struct ip { unsigned char ip_hl:4; unsigned char ip_v:4; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; unsigned long ip_src; unsigned long ip_dst; }; unsigned char sendpacket[PACKET_SIZE]; unsigned char recvpacket[PACKET_SIZE]; struct sockaddr_in dest_addr; struct sockaddr_in from_addr; int sockfd; int pid; unsigned short cal_chksum(unsigned short *addr,int len); int pack(int pack_no); int unpack(unsigned char *buf,int len); void send_packet(void); void recv_packet(void); void main(int argc,char *argv[]) { struct hostent *host; struct protoent *protocol; WSADATA wsaData; int timeout=1000; int SEND_COUNT=4; int i; char *par_host; par_host=argv[argc-1]; //IP赋值 switch(argc) { case 2: break; case 3: if(strcmp(argv[1],"-t")==0) { SEND_COUNT=10000; break; } //fall through default: printf("usage: %s [-t] Host name or IP address\n",argv[0]); exit(1); } if(WSAStartup(0x1010,&wsaData)!=0) { printf("wsastartup error\n"); exit(1); } if( (protocol=getprotobyname("icmp") )==NULL) { printf("getprotobyname error\n"); exit(1); } /* printf("%s\n",protocol->p_name); printf("%s\n",protocol->p_aliases); printf("%d\n",protocol->p_proto); system("pause"); */ if( (sockfd=socket(AF_INET,SOCK_RAW,protocol->p_proto) )<0) { printf("socket error\n"); exit(1); } if(setsockopt(sockfd,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,sizeof(timeout))h_length); //resolve address to hostname if(host=gethostbyaddr(host->h_addr,4,PF_INET)) par_host=host->h_name; // //printf("%s\n",par_host); // } else if( dest_addr.sin_addr.s_addr=inet_addr(par_host)==INADDR_NONE) { printf("Unkown host %s\n",par_host); exit(1); } pid=getpid(); /* printf("%d\n",pid); system("pause"); */ printf("Pinging %s [%s]: with %d bytes of data:\n\n",par_host,inet_ntoa(dest_addr.sin_addr),SEND_SIZE); for(i=0;i1) { sum+=*w++; nleft-=2; } if( nleft==1) { *(unsigned char *)(&answer)=*(unsigned char *)w; sum+=answer; } sum=(sum>>16)+(sum&0xffff); sum+=(sum>>16); answer=~sum; return answer; } //打包 int pack(int pack_no) { int packsize; struct icmp *icmp; packsize=8+SEND_SIZE; icmp=(struct icmp*)sendpacket; icmp->icmp_type=ICMP_ECHO; icmp->icmp_code=0; icmp->icmp_cksum=0; icmp->icmp_seq=pack_no; icmp->icmp_id=pid; icmp->icmp_data=GetTickCount(); icmp->icmp_cksum=cal_chksum( (unsigned short *)icmp,packsize); /*校验算法*/ return packsize; } //解包 int unpack(unsigned char *buf,int len) { struct ip *ip; struct icmp *icmp; double rtt; int iphdrlen; ip=(struct ip *)buf; iphdrlen=ip->ip_hl*4; icmp=(struct icmp *)(buf+iphdrlen); if( (icmp->icmp_type==ICMP_ECHOREPLY) && (icmp->icmp_id==pid) ) { len=len-iphdrlen-8; rtt=GetTickCount()-icmp->icmp_data; printf("Reply from %s: bytes=%d time=%.0fms TTL=%d icmp_seq=%u\n", inet_ntoa(from_addr.sin_addr), len, rtt, ip->ip_ttl, icmp->icmp_seq); return 1; } return 0; } //发送 void send_packet() { int packetsize; static int pack_no=0; packetsize=pack(pack_no++); if( sendto(sockfd,(char *)sendpacket,packetsize,0,(struct sockaddr *)&dest_addr,sizeof(dest_addr) )=0) success=unpack(recvpacket,n); else if (WSAGetLastError() == WSAETIMEDOUT) { printf("Request timed out.\n"); return; } }while(!success); } UID5380 帖子239 精华0 积分1289 阅读权限40 来自软件学院 在线时间81 小时 注册时间2006-5-22 最后登录2007-2-24 查看详细资料 TOP
Date : 2009-05-29 Size : 5.74kb User : shuiyuan313

创建原始套接字,构造ICMP协议ECHO数据头,发送数据sendto 接收数据recvfrom,分析返回IP数据头及ICMP数据头 程序代码极其简单,适合初学网络编程者参考- Founds the primitive sleeve joint character, structure ICMP the agreement ECHO data head, transmits data sendto receive data recvfrom, the analysis returns to the IP data and the ICMP data procedure code is extremely simple, suitablly begins studies the network programming reference
Date : 2025-12-19 Size : 4kb User : 唐富华

建立接收socket,将socket和指定的端口绑定 2、创建接收线程,在线程中调用ioctlsocket()判断是否接收到数据,接收到数据时调用OnReceive()(类似CSocket中的OnReceive()) 3、在OnReceive中申请空间调用recvfrom接收数据 4、建立发送socket,和INADDR_ANY绑定 5、调用sendto发送数据 -establishment receiving socket, the socket and designated ports bundled with two to create receive threads, Calling the threads ioctlsocket () to decide whether or not to receive data, to receive information call OnReceive () (similar to the OnReceive CSocket ()) 3, in which the application of space OnReceive call recvfrom four receive data, the establishment of this socket, and INADDR_ANY bundled 5, call sendto send data
Date : 2025-12-19 Size : 8kb User : 朱江涛

IPV6下的RAW_SOCK发送程序,以及基于组播和单播的UDP程序-IPV6 RAW_SOCK sent under the procedures, and based on the unicast and multicast UDP procedures
Date : 2025-12-19 Size : 3kb User :

用VC 写的一个钩子程序,有可视话界面.可以给windows任务管理器下的进程挂钩,比如QQ.对ws_2.dll的send sendto,recv,recvfrom进行了挂钩,可以截获这些内容-Using VC to write a hook procedure, if there are visual interface. Can give windows task manager process under the link, such as QQ. On ws_2.dll the send sendto, recv, recvfrom were linked, the content can be intercepted
Date : 2025-12-19 Size : 37kb User : linqj

网络syn Flood攻击的代码,需要的下载。本程序通过使用Winsock2原始套接字提供函数sendto(),手动构造TCP SYN帧,对目标主机进行SYN Flood攻击。-Network syn Flood attack code needed to download. This procedure by using raw socket to provide Winsock2 function sendto (), Manual TCP SYN frame structure on the target host for SYN Flood attacks.
Date : 2025-12-19 Size : 2kb User : 许凡

UDP网络传输动态连接库,一个项目中使用的网络接口,封装Windows Sockets API为UDP数据报传输类。而不是对整个Sockets API进行封装,只是对socket(), bind(), sendto(), recvfrom()等常用的方法对行了封装,方便UDP网络传输。-UDP network transport dynamic link library, a project to use the network interface, package, Windows Sockets API for UDP datagrams transmission class. Rather than the Sockets API for the entire package, just right socket (), bind (), sendto (), recvfrom () and other commonly used methods of packaging lines to facilitate the UDP network transmission.
Date : 2025-12-19 Size : 257kb User : yuwei

自己编写服务器端和客户端RTP收发包程序,VC工程,很实用-Write your own server and client send and receive RTP packets procedures, VC works, very practical
Date : 2025-12-19 Size : 3.48mb User : ruanliu

UDP客户端C程序,主要函数为sendto和recvfrom-UDP Client C program, the main function is sendto and recvfrom
Date : 2025-12-19 Size : 26kb User : gaojian

Linux网络编程用户数据报发送~sockfd,buf,len的意义和read,write一样,分别表示套接字描述符,发送或接收的缓冲区及大小. recvfrom负责从 sockfd接收数据,如果from不是NULL,那么在from里面存储了信息来源的情况,如果对信息的来源不感兴趣, 可以将from和fromlen 设置为NULL.sendto负责向to发送信息.此时在to里面存储了收信息方的详细资料. ~-Data transfering on web
Date : 2025-12-19 Size : 2kb User : lzy

Linux网络编程用户数据报发送,sockfd,buf,len的意义和read,write一样,分别表示套接字描述符,发送或接收的缓冲区及大小. recvfrom负责从 sockfd接收数据,如果from不是NULL,那么在from里面存储了信息来源的情况,如果对信息的来源不感兴趣, 可以将from和fromlen 设置为NULL.sendto负责向to发送信息.此时在to里面存储了收信息方的详细资料. -Linux network programming user datagram sockfd, buf, len sense and read, write, respectively, said socket descriptor, send or receive buffer size. Recvfrom responsible for from sockfd receive data, if from is not NULL, then stored in from inside sources of information, if the source of the information is not interested in, you can from and fromlen settings responsible for NULL.sendto to to send a message. storing the received information the details of the party to inside.
Date : 2025-12-19 Size : 2kb User : lwj

c.socket网络编程 Socket相关的操作由一系列API函数来完成,比如socket、bind、listen、connect、accept、send、sendto、recv、recvfrom等。调用这些API函数有一定的先后次序,有些函数的参数还比较复杂,对于开发者来说,不是很好用。于是,微软的MFC提供了两个类:CAsyncSocket和CSocket,极大地方便了Socket功能的使用。-failed to translate
Date : 2025-12-19 Size : 326kb User : david

windows网络编程sendto程序实例-windows network programming instance sendto
Date : 2025-12-19 Size : 7.26mb User : 左昱

a.确定本机的IP和端口,socket只有与某一IP和端口绑定,才能发挥其功能。 b.确定通讯协议:TCP 或 UDP。 编程步骤: a.建立一个套接字 b.绑定本机的IP和端口 c.如果是TCP,因为是面向连接的,要利用Listen()方法来监听网络上是否有人给自己发东西 如果是UDP,因为是无连接的,所以来者不拒。 d.TCP情况下,如果监听到一个连接,就可以使用accept来接收这个连接,然后就可以利用Send/Receive来执行操作了。而UDP,则不需要accept,直接使用SendTo/ReceiveFrom来执行操作。(注意,因为UDP不需要建立连接,所以在发送前并不知道对方的IP和端口,因此需要指定一个发送的节点才能进行正常的发送和接收) e.不继续发送和接收时使用close。-a. determine the machine s IP and port, socket only with an IP and port binding, in order to function. . b determine protocols: TCP or UDP. Programming steps: a. to establish a socket b. Bind the machine IP and port . c If TCP, because it is connection-oriented, and to take advantage of Listen () method to listen if anyone on the network to send their own thing if it is UDP, because it is not connected, so all comers. Under d.TCP case, if listening to a connection, you can use the accept to accept the connection, then you can use the Send/Receive to perform the operation. The UDP, you do not need accept, directly SendTo/ReceiveFrom to perform the operation. (Note that because UDP does not need to establish a connection, so before sending did not know each other s IP and port, so you need to specify a sending node can perform normal transmission and reception) e. not to continue sending and receiving using close.
Date : 2025-12-19 Size : 3kb User : 刘洋
CodeBus is one of the largest source code repositories on the Internet!
Contact us :
1999-2046 CodeBus All Rights Reserved.