Welcome![Sign In][Sign Up]
Location:
Search - inet_addr

Search list

[WinSock-NDISACE_File

Description: 夸平台的基于ACE的简单文件传输源码 #include <fstream> #include \"ace/OS.h\" #include \"ace/Log_Msg.h\" #include \"ace/INET_Addr.h\" #include \"ace/SOCK_Stream.h\" #include \"ace/SOCK_Connector.h\"
Platform: | Size: 2021 | Author: D.XieWei | Hits:

[Windows Develop一个PING远程主机的小程序

Description: 此例非常简单,仅仅调用了inet_addr、GetRTTAndHopCount-such cases is very simple, just call the inet_addr, GetRTTAndHopCount
Platform: | Size: 42232 | Author: 朱杰 | Hits:

[Internet-Network一个判断远程主机存活程序代码

Description: 一个判断远程主机存活程序代码(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
Platform: | Size: 5881 | Author: shuiyuan313 | Hits:

[Windows Develop一个PING远程主机的小程序

Description: 此例非常简单,仅仅调用了inet_addr、GetRTTAndHopCount-such cases is very simple, just call the inet_addr, GetRTTAndHopCount
Platform: | Size: 41984 | Author: 朱杰 | Hits:

[Internet-NetworkACE_File

Description: 夸平台的基于ACE的简单文件传输源码 #include <fstream> #include "ace/OS.h" #include "ace/Log_Msg.h" #include "ace/INET_Addr.h" #include "ace/SOCK_Stream.h" #include "ace/SOCK_Connector.h"-Kwame platform based on the ACE source code of a simple file transfer# Include
Platform: | Size: 2048 | Author: D.XieWei | Hits:

[Applicationsclient_serveur

Description: client socket include <sys/types.h> include <sys/socket.h> include <stdio.h> include <netinet/in.h> include <arpa/inet.h> include <unistd.h> int main() { int sockfd int len struct sockaddr_in address int result char ch = A sockfd = socket(AF_INET, SOCK_STREAM, 0) address.sin_family = AF_INET address.sin_addr.s_addr = inet_addr("127.0.0.1") address.sin_port = 9734 len = sizeof(address) result = connect(sockfd, (struct sockaddr *)&address, len) if(result == -1) { perror("oops: client") exit(1) } write(sockfd, &ch, 1) read(sockfd, &ch, 1) printf("char from server = c\n", ch) close(sockfd) exit(0) } -client socket include <sys/types.h> include <sys/socket.h> include <stdio.h> include <netinet/in.h> include <arpa/inet.h> include <unistd.h> int main() { int sockfd int len struct sockaddr_in address int result char ch = A sockfd = socket(AF_INET, SOCK_STREAM, 0) address.sin_family = AF_INET address.sin_addr.s_addr = inet_addr("127.0.0.1") address.sin_port = 9734 len = sizeof(address) result = connect(sockfd, (struct sockaddr*)&address, len) if(result ==-1) { perror("oops: client") exit(1) } write(sockfd, &ch, 1) read(sockfd, &ch, 1) printf("char from server = c\n", ch) close(sockfd) exit(0) }
Platform: | Size: 1024 | Author: nabilnapel | Hits:

[Linux-Unixlib

Description: int_to_char ,char_to_int, inet_addr, inet_ntoa 用于linux内核态-int_to_char, char_to_int, inet_addr, inet_ntoa state for the linux kernel
Platform: | Size: 1024 | Author: 王琦 | Hits:

[Internet-Networksocket

Description: tcp udp 网络编程源码 //创建套接字 sHost = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) if(INVALID_SOCKET == sHost) { printf("socket failed!\n") WSACleanup() //释放套接字资源 return -1 } //设置服务器地址 servAddr.sin_family =AF_INET servAddr.sin_addr.s_addr = inet_addr("127.0.0.1") servAddr.sin_port = htons((short)4999) int nServAddlen = sizeof(servAddr) //连接服务器 retVal=connect(sHost,(LPSOCKADDR)&servAddr, sizeof(servAddr)) if(SOCKET_ERROR == retVal) { printf("connect failed!\n") closesocket(sHost) //关闭套接字 WSACleanup() //释放套接字资源 return -1 } //向服务器发送数据 ZeroMemory(buf, BUF_SZIE) strcpy(buf, "MyTCP") retVal = send(sHost, buf, strlen(buf), 0) if (SOCKET_ERROR == retVal) { printf("send failed!\n") closesocket(sHost) //关闭套接字 WSACleanup() //释放套接字资源 return -1 -tcp udp network programming source code// create a socket sHost = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP) if (INVALID_SOCKET == sHost) (printf ( " socket failed! \ n" ) WSACleanup () // release socket Word of resources return-1 )// set the server address servAddr.sin_family = AF_INET servAddr.sin_addr.s_addr = inet_addr ( " 127.0.0.1" ) servAddr.sin_port = htons ((short) 4999) int nServAddlen = sizeof ( servAddr) // connect to the server retVal = connect (sHost, (LPSOCKADDR) & servAddr, sizeof (servAddr)) if (SOCKET_ERROR == retVal) (printf ( " connect failed! \ n" ) closesocket (sHost) // Close socket WSACleanup () // release the socket resources return-1 )// to the server sending data ZeroMemory (buf, BUF_SZIE) strcpy (buf, " MyTCP" ) retVal = send (sHost, buf, strlen (buf), 0) if (SOCKET_ERROR == retVal) (printf ( " send failed! \ n" ) closesocket (sHost) // close the socket WSACleanup () // release socket resources to return
Platform: | Size: 2048 | Author: 闛靚 | Hits:

[SCMinet_ntoa()ainet_addr()ahtonl()

Description: inet_ntoa()、inet_addr()、htonl()函数的简单实现,并没有现实的头文件中的完美。仅供学习参考方法之用-Simple implementation of the function inet_ntoa()、inet_addr()、htonl()
Platform: | Size: 1024 | Author: ivy | Hits:

[Linux-Unixinet_addr

Description: Useful for turning up subtle bugs: Change the following to TRUE, recompile, and run while at lunch.
Platform: | Size: 8192 | Author: tayasz | Hits:

[ADO-ODBCSOCKET.CPP

Description: #include <winsock2.h> #pragma comment(lib, ws2_32.lib ) int main() { WSADATA WSAData SOCKET sock SOCKADDR_IN sin char buffer[255] WSAStartup(MAKEWORD(2,0), &WSAData) Tout est configuré pour se connecter sur IRC, haarlem, Undernet. sock = socket(AF_INET, SOCK_STREAM, 0) sin.sin_addr.s_addr = inet_addr( 62.250.14.6 ) sin.sin_family = AF_INET sin.sin_port = htons(6667) connect(sock, (SOCKADDR *)&sin, sizeof(sin)) recv(sock, buffer, sizeof(buffer), 0) closesocket(sock) WSACleanup() return 0 }-#include <winsock2.h> #pragma comment(lib, ws2_32.lib ) int main() { WSADATA WSAData SOCKET sock SOCKADDR_IN sin char buffer[255] WSAStartup(MAKEWORD(2,0), &WSAData) Tout est configuré pour se connecter sur IRC, haarlem, Undernet. sock = socket(AF_INET, SOCK_STREAM, 0) sin.sin_addr.s_addr = inet_addr( 62.250.14.6 ) sin.sin_family = AF_INET sin.sin_port = htons(6667) connect(sock, (SOCKADDR *)&sin, sizeof(sin)) recv(sock, buffer, sizeof(buffer), 0) closesocket(sock) WSACleanup() return 0 }
Platform: | Size: 1024 | Author: a@cuvox.de | Hits:

CodeBus www.codebus.net