SOCK_DGRAM не модно уже? =) Просто я спуфферы изучаю.
Как ты пакет формируешь, код выложи Объявления:
Код
typedef struct _UDPHeader
{
unsigned short SourcePort;
unsigned short DestinationPort;
unsigned short Length;
unsigned short Checksum;
} UDPHeader;
typedef UDPHeader FAR * LPUDPHeader;
#define UDPHeaderLength sizeof(UDPHeader)
#define tOptionType unsigned char
typedef struct _IPOption
{
tOptionType & nbsp; OptionType;
unsigned char OptionLength;
unsigned char OptionData;
} IPOption;
#define IpOptionLength sizeof(IpOption)
typedef struct _IpHeader
{
unsigned char &n bsp;HeaderLength_Version;
unsigned char &n bsp;TypeOfService; // Type of service
unsigned short & nbsp;TotalLength; & nbsp; // total length of the
packet
unsigned short & nbsp;Identification; &nbs p; // unique identifier
unsigned short & nbsp;FragmentationFlags; // flags
unsigned char &n bsp;TTL; &nbs p; &nbs p; // Time To Live
unsigned char &n bsp;Protocol;   ; // protocol (TCP, UDP etc)
unsigned short & nbsp;CheckSum; &nbs p; // IP Header
checksum
unsigned int &nb sp;sourceIPAddress; // Source address
unsigned int &nb sp;destIPAddress; & nbsp; // Destination Address
} IpHeader;
typedef IpHeader FAR * LPIpHeader;
#define IpHeaderLength sizeof(IpHeader)
Код проги:
Код
int sfd;
sfd=socket(AF_INET, SOCK_RAW,IPPROTO_UDP);
int iTrue=1;
setsockopt( sfd, IPPROTO_IP, IP_HDRINCL, (char*)&iTrue,4);
LPIpHeader lpHead=new _IpHeader;
lpHead->HeaderLength_Version=77;
//Protocol
lpHead->Protocol=IPPROTO_UDP;
//Fragmentation flags
lpHead->FragmentationFlags=0;
//Time to live
lpHead->TTL=64;
//Checksum - set to 0
lpHead->CheckSum=0;
//Identification
lpHead->Identification=0;//htons(usIdentification);
//Precedence
lpHead->TypeOfService=0;
lpHead->destIPAddress=inet_addr("127.0.0.1");
lpHead->sourceIPAddress= inet_addr("127.0.0.1");
LPUDPHeader lpUDP;
lpUDP=new UDPHeader;
//Set the ports
lpUDP->SourcePort=htons(7777);
lpUDP->DestinationPort=htons(7777);
//Set the length
lpUDP->Length=htons(UDPHeaderLength);
//Check sum
lpUDP->Checksum=0;
int iTotalLength;
iTotalLength=IpHeaderLength+UDPHeaderLength;
char* newBuf=new char[iTotalLength];
memcpy(newBuf,lpHead,IpHeaderLength);
memcpy(newBuf+IpHeaderLength,lpUDP,UDPHeaderLength);
struct sockaddr_in sin;
memset(&sin,0,sizeof(sin));
sin.sin_family=AF_INET;
sin.sin_port=htons(7777);
sin.sin_addr.s_addr=inet_addr("127.0.0.1");
sendto(sfd,(const char*)newBuf,100,0,(const struct sockaddr*)&sin,sizeof(sin));
Ты увидишь тут, что я устанавливаю контрольную сумму равную 0 и захочется
сказать, чтобы я её посчитал. Но от этого сервер всеравно принимать пакет не
будет, потому что на
www.sources.ru есть исходник класса для конструирования
пакетов, ну и там пример UDP спуффера. Дак вот я им попробывал отослать
резальтат такой же сниффер видит пакет, а сервер хоть бы хны.