当前位置: 技术问答>linux和unix
分数已经不多了,这次花血本了,大家帮帮忙吧(在线等啊)~~~~
来源: 互联网 发布时间:2015-09-29
本文导语: 我想用raw socket发送一个字符串,这个字符串填在哪里? 是填在tcp头的“选项”里吗? | if((sockfd = socket(AF_INET,SOCK_RAW,IPPROTO_UDP))id = htons(getpid()); ip_header->ttl = ttl; /* #define IPTTL...
我想用raw socket发送一个字符串,这个字符串填在哪里?
是填在tcp头的“选项”里吗?
是填在tcp头的“选项”里吗?
|
if((sockfd = socket(AF_INET,SOCK_RAW,IPPROTO_UDP))id = htons(getpid());
ip_header->ttl = ttl; /* #define IPTTL 60;*/
ip_header->protocol = protocol;
ip_header->saddr = saddr.s_addr;
ip_header->daddr = daddr.s_addr;
ip_header->check = 0;
ip_header->check = ((unsigned short)ip_cksum1((unsigned short *)ip_header,sizeof(struct iphdr)));
return;
}
void build_udphdr(char *packet,unsigned short sport,unsigned short dport,unsigned short length)
{
struct udphdr *udp;
char *packetck = NULL;
udp = (struct udphdr *)packet;
udp->source = htons(sport);
udp->dest = htons(dport);
udp->len = htons(length);
udp->check = 0;
packetck = (char*)malloc(8 + sizeof(struct pseudoudp) + length - sizeof(struct udphdr));
memset(packetck, 0, 8 + length - sizeof(struct udphdr) + sizeof(struct pseudoudp));
psudp = (struct pseudoudp *) (packetck);
psudp->ipdest = 0xffffffff;
psudp->ipsource = 0;
psudp->zero = 0;
psudp->proto = 17;
psudp->length = htons(8+length-sizeof(struct udphdr));
memcpy(packetck+sizeof(struct pseudoudp), &udp, 8);
printf("%d %drn", length, sizeof(struct udphdr));
//memcpy(packetck+sizeof(struct pseudoudp)+8, (char*)(packet+sizeof(struct udphdr)), length-sizeof(struct udphdr));
udp->check = 0;
//udp->check = udp_cksum((u_short *)packetck, 8 + length - sizeof(struct udphdr) + sizeof(struct pseudoudp));
//udp->check = (tcp_check1(packet, length, htonl(inet_addr("61.235.102.98")), htonl(inet_addr ("202.100.4.15"))));
}
这也是当时一个人的问题 帮他调了调 能用
你参考吧
ip_header->ttl = ttl; /* #define IPTTL 60;*/
ip_header->protocol = protocol;
ip_header->saddr = saddr.s_addr;
ip_header->daddr = daddr.s_addr;
ip_header->check = 0;
ip_header->check = ((unsigned short)ip_cksum1((unsigned short *)ip_header,sizeof(struct iphdr)));
return;
}
void build_udphdr(char *packet,unsigned short sport,unsigned short dport,unsigned short length)
{
struct udphdr *udp;
char *packetck = NULL;
udp = (struct udphdr *)packet;
udp->source = htons(sport);
udp->dest = htons(dport);
udp->len = htons(length);
udp->check = 0;
packetck = (char*)malloc(8 + sizeof(struct pseudoudp) + length - sizeof(struct udphdr));
memset(packetck, 0, 8 + length - sizeof(struct udphdr) + sizeof(struct pseudoudp));
psudp = (struct pseudoudp *) (packetck);
psudp->ipdest = 0xffffffff;
psudp->ipsource = 0;
psudp->zero = 0;
psudp->proto = 17;
psudp->length = htons(8+length-sizeof(struct udphdr));
memcpy(packetck+sizeof(struct pseudoudp), &udp, 8);
printf("%d %drn", length, sizeof(struct udphdr));
//memcpy(packetck+sizeof(struct pseudoudp)+8, (char*)(packet+sizeof(struct udphdr)), length-sizeof(struct udphdr));
udp->check = 0;
//udp->check = udp_cksum((u_short *)packetck, 8 + length - sizeof(struct udphdr) + sizeof(struct pseudoudp));
//udp->check = (tcp_check1(packet, length, htonl(inet_addr("61.235.102.98")), htonl(inet_addr ("202.100.4.15"))));
}
这也是当时一个人的问题 帮他调了调 能用
你参考吧
|
http://bricks.diy.myrice.com/linux/program/raw-socket.txt
|
楼上的废话!