?
So hier mal der ganze code. Es sollen nur daten gesendet werden und nicht empfangen.
#include <stdio.h>
#include "main.h"
#define szSTRING "TesTesTesTesTesTesT\0"
struct ip_header_s
{
unsigned char ip_hl:4, ip_v:4;
unsigned char ip_tos;
unsigned short int ip_len;
unsigned short int ip_id;
unsigned short int ip_off;
unsigned char ip_ttl;
unsigned char ip_p;
unsigned short int ip_sum;
unsigned int ip_src;
unsigned int ip_dst;
};
struct udp_header_s
{
unsigned short int uh_sport;
unsigned short int uh_dport;
unsigned short int uh_len;
unsigned short int uh_check;
};
int main()
{
char Packet[1024];
SOCKET s;
ip_header_s *iphdr = (struct ip_header_s *)Packet;
udp_header_s *udphdr = (struct udp_header_s *)Packet + sizeof(struct ip_header_s);
strcat(Packet, szSTRING );
sockaddr_in sockaddr;
WinsockStartup();
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons(7777);
sockaddr.sin_addr.s_addr = inet_addr("80.128.134.124");
s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if(s == INVALID_SOCKET)
{
printf("Invalid Socket\n");
return 0;
}
memset(Packet, 0, sizeof(Packet));
iphdr->ip_hl = 5;
iphdr->ip_v = 4;
iphdr->ip_tos = 0x8;
iphdr->ip_len = sizeof(struct ip_header_s) + sizeof(struct udp_header_s) + sizeof(szSTRING);
iphdr->ip_id = 156;
iphdr->ip_off = 0;
iphdr->ip_ttl = 128;
iphdr->ip_p = IPPROTO_RAW;
iphdr->ip_sum = 0;
iphdr->ip_src = inet_addr("80.128.134.124");
iphdr->ip_dst = inet_addr("80.128.134.124");
udphdr->uh_check = 0;
udphdr->uh_len = htons(sizeof(struct udp_header_s) + sizeof(szSTRING));
udphdr->uh_sport = htons(7777);
udphdr->uh_dport = htons(7777);
udphdr->uh_check = Checksum((unsigned short *)Packet, iphdr->ip_len );
iphdr->ip_sum = Checksum((unsigned short *)Packet, iphdr->ip_len );
memcpy(Packet, &iphdr, sizeof(ip_header_s));
memcpy(Packet + sizeof(udp_header_s), &udphdr, sizeof(udp_header_s));
memcpy(Packet + sizeof(ip_header_s)+ sizeof(udp_header_s), szSTRING, sizeof(ip_header_s) + sizeof(udp_header_s) + sizeof(szSTRING));
sendto(s, Packet, sizeof(Packet), 0 , (struct sockaddr *) &sockaddr, sizeof (sockaddr));
return 0;
}