Exemple #1
0
void icmp( unsigned int packet_lenght, unsigned char *buffer)
	{
		unsigned char i;
		unsigned int checksum;
		
		struct ETH_header *ETH_packet; 		// ETH_struct anlegen
		ETH_packet = (struct ETH_header *)&buffer[0];
		struct IP_header *IP_packet;		// IP_struct anlegen
		IP_packet = ( struct IP_header *)&buffer[ETHERNET_HEADER_LENGTH];
		struct ICMP_header *ICMP_packet;	// ICMP_struct anlegen
		ICMP_packet = ( struct ICMP_header *)&buffer[ETHERNET_HEADER_LENGTH + ((IP_packet->IP_Version_Headerlen & 0x0f) * 4 )];

		switch ( ICMP_packet->ICMP_type )
			{
				case ICMP_EchoRequest:			//IP_header unbauen zum versenden 
												IP_packet->IP_DestinationIP = IP_packet->IP_SourceIP;
												IP_packet->IP_SourceIP = myIP;
												//IP_header checksummer ausrechnen
												IP_packet->IP_Headerchecksum = 0x0;
												checksum = Checksum_16( &buffer[14], ((IP_packet->IP_Version_Headerlen & 0x0f) * 4 ) );
												IP_packet->IP_Headerchecksum = ChangeEndian16bit( checksum );
												ICMP_packet->ICMP_type = ICMP_EchoReplay; // auf reply einstellen
												ICMP_packet->ICMP_code = 0x00; 
												//Simple ICMP Checksummenbildung, die Idee stammt von
												//Simon, siehe http://avr.auctionant.de/
												if(ICMP_packet->ICMP_checksumByteOne >  0xFF-0x08)ICMP_packet->ICMP_checksumByteTwo++;
												ICMP_packet->ICMP_checksumByteOne+=0x08;
												// Ethernetframe bauen
												for(i = 0; i < 6 ; i++ ){	
													ETH_packet->ETH_destMac[i] = ETH_packet->ETH_sourceMac[i];	
													ETH_packet->ETH_sourceMac[i] = mymac[i]; }
												// und ab die post
												sendEthernetframe( packet_lenght, buffer); // packet_lenght - 4 weil der Controller die checksumme selber berechnet
												break;

				case ICMP_EchoReplay:			if ( ICMP_packet->ICMP_Identifierer == 0xac1d && ICMP_Replaystate == ICMP_WaitForReplay )
													ICMP_Replaystate = ICMP_ReplayOkay;
												break;
			}
	}
Exemple #2
0
/* -----------------------------------------------------------------------------------------------------------*/
void MakeIPheader( long SourceIP, char Protocoll, int Datalenght , char *ethernetbuffer )
	{
		struct ETH_header *ETH_packet; 		// ETH_struct anlegen
		ETH_packet = (struct ETH_header *) ethernetbuffer;
		struct IP_header *IP_packet;		// IP_struct anlegen
		IP_packet = ( struct IP_header *) &ethernetbuffer[ETHERNET_HEADER_LENGTH];
		struct TCP_header *TCP_packet;		// TCP_struct anlegen
		TCP_packet = ( struct TCP_header *) &ethernetbuffer[ETHERNET_HEADER_LENGTH + ((IP_packet->IP_Version_Headerlen & 0x0f) * 4 )];

		IP_packet->IP_Version_Headerlen = 0x45;
		IP_packet->IP_TOS = 0x0;
		IP_packet->IP_Totallenght = htons ( IP_HEADER_LENGHT + Datalenght );
		IP_packet->IP_Identification = 0x1DAC;
//		IP_packet->IP_Flags = 0x40;
		IP_packet->IP_Flags_Fragmentoffset = 0x0040;
		IP_packet->IP_TTL = 64 ;		
		IP_packet->IP_Protocol = Protocoll;
		IP_packet->IP_Headerchecksum = 0x0;
		IP_packet->IP_SourceIP = myIP;
		IP_packet->IP_DestinationIP = SourceIP;
		IP_packet->IP_Headerchecksum = htons ( Checksum_16( &ethernetbuffer[ETHERNET_HEADER_LENGTH] ,(IP_packet->IP_Version_Headerlen & 0x0f) * 4 ) );

		return;
	}