Location:
Search - sockaddr_in
Search list
Description: 一个IP地址字符串到标准SOCKADDR_IN IP地址的过程-a string of IP addresses standards SOCKADDR_IN the process of IP addresses
Platform: |
Size: 3350 |
Author: 沈建中 |
Hits:
Description: /*** *** *** *** **/
/* 灌水机 源代码 */
/* PostForum.cpp */
/********************************************/
#include
#include
#include <winsock.h>
main(int argc,char *argv[]){
char buff[4096]
SOCKET sock
SOCKADDR_IN addr
Platform: |
Size: 1166 |
Author: liuchao |
Hits:
Description: 本程序只对一个IP地址进行,如果要对一段IP进行测试,简单修改程序即可。可将发送放在单独的进程 里(使用fork()),send_icmp里做成循环,每次重新初始化struct sockaddr_in。那么对接收到的数据 进行分析的proc_icmp()将多一道对IP报头ip->src字段的判断。-this procedure only a pair of IP addresses, IP to a test, a simple change procedures. This can be placed on a separate process (the use of fork ()), causing Lane send_icmp cycle, each re-initialization struct sockaddr_in. Then Butt received the data analysis proc_icmp () will more than one pair of IP header ip-gt; Src field judgment.
Platform: |
Size: 2109 |
Author: 吕杰 |
Hits:
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:
Description: 本程序只对一个IP地址进行,如果要对一段IP进行测试,简单修改程序即可。可将发送放在单独的进程 里(使用fork()),send_icmp里做成循环,每次重新初始化struct sockaddr_in。那么对接收到的数据 进行分析的proc_icmp()将多一道对IP报头ip->src字段的判断。-this procedure only a pair of IP addresses, IP to a test, a simple change procedures. This can be placed on a separate process (the use of fork ()), causing Lane send_icmp cycle, each re-initialization struct sockaddr_in. Then Butt received the data analysis proc_icmp () will more than one pair of IP header ip-gt; Src field judgment.
Platform: |
Size: 2048 |
Author: 吕杰 |
Hits:
Description: 一个IP地址字符串到标准SOCKADDR_IN IP地址的过程-a string of IP addresses standards SOCKADDR_IN the process of IP addresses
Platform: |
Size: 3072 |
Author: 沈建中 |
Hits:
Description: VB的函数大全,从网上下载的,VB调用API的函数,希望各位能有用-VB function Daquan, downloaded from the Internet, called VB API function, hope can be useful
Platform: |
Size: 12318720 |
Author: 高力 |
Hits:
Description: /*** *** *** *** **/
/* 灌水机 源代码 */
/* PostForum.cpp */
/********************************************/
#include
#include
#include <winsock.h>
main(int argc,char *argv[]){
char buff[4096]
SOCKET sock
SOCKADDR_IN addr
-/***********************//* Irrigation machine source code*//* PostForum.cpp*//********************************************/# include# include# include
Platform: |
Size: 1024 |
Author: liuchao |
Hits:
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:
Description: 通用因特网IPV4网络编程接口
//TCP
int uin_open_tcp(unsigned short port)
int uin_accept(int fd, struct sockaddr_in *addr)
int uin_connect(const char *cp, unsigned short port)
int r_recv(int fd, void* buf, int size)
int r_send(int fd, const void* msg, int count)
int n_send(int fd, const void* msg, int count)
//UDP
int uin_open_udp(unsigned short port)
int uin_sendtohost(int fd, void *buf, int count, char *cp, unsigned short port)
int uin_sendto(int fd, void *buf, int count, struct sockaddr_in *addr)
int uin_recvfrom(int fd, void *buf, int size, struct sockaddr_in *addr) -UICI
Platform: |
Size: 3072 |
Author: jannzeng |
Hits:
Description: #define DESTPORT 80 /* 要攻击的端口(WEB) */
#define LOCALPORT 8888
void send_tcp(int sockfd,struct sockaddr_in *addr)
unsigned short check_sum(unsigned short *addr,int len)
-#define DESTPORT 80 /* 要攻击的端口(WEB)*/
#define LOCALPORT 8888
void send_tcp(int sockfd,struct sockaddr_in*addr)
unsigned short check_sum(unsigned short*addr,int len)
Platform: |
Size: 5120 |
Author: 周嘻嘻 |
Hits:
Description:
void send_tcp(int sockfd,struct unsigned short check_sum(unsigned short *addr,int len)
-sockaddr_in*addr)
unsigned short check_sum(unsigned short*addr,int len)
Platform: |
Size: 9216 |
Author: 周嘻嘻 |
Hits:
Description: 服务器端程序,winsock
socket sockaddr_in-Server-side programs, winsock socket sockaddr_in
Platform: |
Size: 4663296 |
Author: 金力 |
Hits:
Description: sinp = (struct sockaddr_in *)aip->ai_addr 会将struct sockaddr 变量强制转化为struct sockaddr_in 类型
inet_ntop函数用于在二进制格式与点分十进制格式表示(a.b.c.d)之间进行转换
-sinp = (struct sockaddr_in*) aip-> ai_addr the struct sockaddr variables forced into the struct sockaddr_in the type inet_ntop function. used in binary format and dotted decimal format (abcd) to convert between
Platform: |
Size: 1024 |
Author: lihongbo |
Hits:
Description:
1、首先需要定义的对象:
SOCKET ReceivingSocket //接收端的Socket
SOCKADDR_IN ReceiverAddr //接收端的地址信息
char ReceiveBuf[1024] //接收数据缓冲区大小
int BufLength //缓冲区长度
SOCKADDR_IN SenderAddr //发送数据端地址信息
int SenderAddrSize = sizeof(SenderAddr) //发送端地址信息的长度
2、启动WSA动态库:
WSAStartup(MAKEWORD(2,2),&wsd)
3、创建socket:
ReceivingSocket=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)
4、初始化服务器地址及监听端口
ReceiverAddr.sin_family=AF_INET //家族
ReceiverAddr.sin_port=htons(9000) //设置端口号
ReceiverAddr.sin_addr.s_addr=htonl(INADDR_ANY) //地址
5、绑定端口
6、接收数据:
ReceivingSocket,//接收端Socket
ReceiveBuf,//接收端用来存储数据的缓冲区
BufLength,//缓冲区的大小
0,//接收的附加选项,设置为0即可
(SOCKADDR*)&SenderAddr,//发送端的Socket地址
&SenderAddrSize//发送端Socket地址的大小 )
7、关闭socket,关闭WSA,1, you first need to define the object: the SOCKET ReceivingSocket // the the receiving end Socket SOCKADDR_IN distant ReceiverAddr // the receiving end the address information char ReceiveBuf of [1024] / / receive data buffer size int BufLength // buffer length SOCKADDR_IN distant SenderAddr // send data end address information int SenderAddrSize = sizeof (SenderAddr) // length of the address information of the sender, start WSA dynamic library: the WSAStartup (MAKEWORD (2,2), & wsd) 3, create socket: ReceivingSocket = socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP) initialize server address and listen port ReceiverAddr.sin_family = AF_INET //family ReceiverAddr.sin_port = htons (9000) //set port number ReceiverAddr.sin_addr.s_addr = htonl (INADDR_ANY) //address 5, binding port 6 the the receiver Data: ReceivingSocket,// receiving end the the Socket ReceiveBuf,// receiving end is used to store data buffer BufLength// buffer size 0,//
Platform: |
Size: 5223424 |
Author: xiaoxiao |
Hits:
Description: init_clnt() - gets the hostname and sockaddr_in for the target host, and initializes the RPC client handle.
Platform: |
Size: 3072 |
Author: xxtpdd |
Hits:
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:
Description: Tcp_client 源代码
SOCKET sclient socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
if(sclient INVALID_SOCKET)
{
printf( invalid socket ! )
return
}
CEdit* pEdit (CEdit*)GetDlgItem(IDC_EDIT_PORT)
CString sPort
pEdit->GetWindowTextW(sPort) //获取端口字符串
int dPort _ttoi(sPort) //获取端口整形
DWORD dwIP
m_IP.GetAddress(dwIP) //获取ip
sockaddr_in serAddr
serAddr.sin_family AF_INET
serAddr.sin_port htons(dPort)
serAddr.sin_addr.S_un.S_addr htonl(dwIP)
//创建连接
if (connect(sclient, (sockaddr *)&serAddr, sizeof(serAddr)) SOCKET_ERROR)
{
closesocket(sclient)
AfxMessageBox(_T( connect error ! ))
printf( connect error ! )
return
}-Tcp_client
SOCKET sclient socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
if(sclient INVALID_SOCKET)
{
printf( invalid socket ! )
return
}
CEdit* pEdit (CEdit*)GetDlgItem(IDC_EDIT_PORT)
CString sPort
pEdit->GetWindowTextW(sPort) //获取端口字符串
int dPort _ttoi(sPort) //获取端口整形
DWORD dwIP
m_IP.GetAddress(dwIP) //获取ip
sockaddr_in serAddr
serAddr.sin_family AF_INET
serAddr.sin_port htons(dPort)
serAddr.sin_addr.S_un.S_addr htonl(dwIP)
//创建连接
if (connect(sclient, (sockaddr*)&serAddr, sizeof(serAddr)) SOCKET_ERROR)
{
closesocket(sclient)
AfxMessageBox(_T( connect error ! ))
printf( connect error ! )
return
}
Platform: |
Size: 30090240 |
Author: 陈 |
Hits: