수동으로 내 네트워크 패킷을 만들어야합니다. 모든 Protocol.i를 사용하여 클라이언트에 보내고 packet.Can any1을 사용하여 나를 분석하고 시작하고 어디에서 hpw를 도와야합니까 ??? 소켓 프로그래밍에 대한 아이디어가 있습니다.IP 네트워크 패킷 만들기
0
A
답변
10
<linux/ip.h>
에는 ip 패킷을 가리키는 구조가 있습니다. 또한 소켓을 사용할 수 있습니다.
예를 들면 다음과 같습니다. 이 예는 응답
/* send icmp packet example */
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <linux/ip.h>
#include <linux/icmp.h>
int main(int argc, char* argv[])
{
struct iphdr *ip, *ip_reply;
struct icmphdr* icmp;
struct sockaddr_in connection;
char *dst_addr="192.168.1.33";
char *src_addr="192.168.1.34";
char *packet, *buffer;
int sockfd, optval, addrlen;
packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr));
buffer = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr));
ip = (struct iphdr*) packet;
icmp = (struct icmphdr*) (packet + sizeof(struct iphdr));
ip->ihl = 5;
ip->version = 4;
ip->tot_len = sizeof(struct iphdr) + sizeof(struct icmphdr);
ip->protocol = IPPROTO_ICMP;
ip->saddr = inet_addr(src_addr);
ip->daddr = inet_addr(dst_addr);
ip->check = in_cksum((unsigned short *)ip, sizeof(struct iphdr));
icmp->type = ICMP_ECHO;
icmp->checksum = in_cksum((unsigned short *)icmp, sizeof(struct icmphdr));
/* open ICMP socket */
if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1) {
perror("socket");
exit(EXIT_FAILURE);
}
/* IP_HDRINCL must be set on the socket so that the kernel does not attempt
* to automatically add a default ip header to the packet*/
setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &optval, sizeof(int));
connection.sin_family = AF_INET;
connection.sin_addr.s_addr = ip->daddr;
sendto(sockfd, packet, ip->tot_len, 0, (struct sockaddr *)&connection, sizeof(struct sockaddr));
printf("Sent %d byte packet to %s\n", ip->tot_len, dst_addr);
addrlen = sizeof(connection);
if (recvfrom(sockfd, buffer, sizeof(struct iphdr) + sizeof(struct icmphdr), 0, (struct sockaddr *)&connection, &addrlen) == -1)
{
perror("recv");
}
else
{
char *cp;
ip_reply = (struct iphdr*) buffer;
cp = (char *)&ip_reply->saddr;
printf("Received %d byte reply from %u.%u.%u.%u:\n", ntohs(ip_reply->tot_len), cp[0]&0xff,cp[1]&0xff,cp[2]&0xff,cp[3]&0xff);
printf("ID: %d\n", ntohs(ip_reply->id));
printf("TTL: %d\n", ip_reply->ttl);
}
}
unsigned short in_cksum(unsigned short *addr, int len)
{
register int sum = 0;
u_short answer = 0;
register u_short *w = addr;
register int nleft = len;
/*
* Our algorithm is simple, using a 32 bit accumulator (sum), we add
* sequential 16 bit words to it, and at the end, fold back all the
* carry bits from the top 16 bits into the lower 16 bits.
*/
while (nleft > 1)
{
sum += *w++;
nleft -= 2;
}
/* mop up an odd byte, if necessary */
if (nleft == 1)
{
*(u_char *) (&answer) = *(u_char *) w;
sum += answer;
}
/* add back carry outs from top 16 bits to low 16 bits */
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
sum += (sum >> 16); /* add carry */
answer = ~sum; /* truncate to 16 bits */
return (answer);
}
+0
왜 당신은 패킷에 맥 헤더를 첨부하지 않았습니까? 커널에 의해 처리 되었습니까? –
0
사용 원시 소켓에 대한 ICMP ECHO 패킷을 전송하고 기다립니다.
도 원시 소켓을위한 & 소켓 프로그래밍을 위해 http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html을 참조 할 수 있습니다.
나는 생각한다. http://csis.bits-pilani.ac.in/faculty/dk_tyagi/Study_stuffs/raw.html
관련 문제
- 1. tcp/ip 패킷 수신기
- 2. 하나의 IP 주소에서 다른 IP 주소로 IP 패킷 라우팅하기
- 3. 네트워크 패킷 생성/파싱 라이브러리?
- 4. 병합 데이터/IP 패킷
- 5. IP 패킷 보내기
- 6. 일반 네트워크 패킷
- 7. iphone 네트워크 패킷 캡쳐
- 8. libpcap IP 패킷 리 어셈블리
- 9. 들어오는 tcp/ip 패킷 캡처
- 10. 매직 패킷 및 가상 네트워크
- 11. 네트워크 데이터 패킷 연결 의도
- 12. 은 네트워크 패킷 구조를 결정합니다.
- 13. WP7 용 네트워크 패킷 분석기
- 14. Perl 네트워크 프레임/패킷 파서
- 15. Mac OSX의 네트워크 패킷 검사기
- 16. UDP 패킷 스푸핑을위한 원시 패킷 만들기
- 17. 패킷 필터링, IP 테이블 및 라우팅
- 18. C에서 데이터 패킷 만들기
- 19. .NET에서 네트워크 패킷 스니핑 사용 권한 예외
- 20. Scapy : 전체 IP 패킷 헤더를 얻으려면 어떻게해야합니까?
- 21. C#을 IP 수신하고 여러 개의 패킷
- 22. C#의 패킷 마킹 (IP 트레이스 백)
- 23. 커널 모듈을 통해 ip 패킷 보내기
- 24. tcp/ip 패킷 변경 C++ 또는 java
- 25. 네트워크 패킷 도착 간 시간 측정
- 26. 네트워크 패킷 분석기로 연결 문자열 하이재킹
- 27. 네트워크 케이블을 통한 패킷 계산 시간
- 28. cisco 패킷 추적기와 같은 snmp 네트워크 시뮬레이터?
- 29. 구축 및 구문 분석 네트워크 패킷
- 30. 패킷 스니핑
정말 그렇게 나쁘지 않다. OSI 모델을 이해하고 있습니까? 그리고 IP 프로토콜이 어떻게 작동합니까? 당신을 위해 이것을 할 라이브러리가 있어야합니다 ... 그들에 대한 구글 –