Forum: FPGA, VHDL & Co. Berechnung der UDP, IP und Ethernet-Checksum


von Header (Gast)


Lesenswert?

Ich wollte nur fragen wie man die Checksummen von UDP, IP und Ethernet 
berechnet. Zu Ethernet hab ich gar nichts gefunden und zu UDP und IP hab 
ich folgendes gefunden, versteh es aber nicht.

IP
The checksum field is the 16 bit one's complement of the one's
complement sum of all 16 bit words in the header and text.  If a
segment contains an odd number of header and text octets to be
checksummed, the last octet is padded on the right with zeros to
form a 16 bit word for checksum purposes.  The pad is not
transmitted as part of the segment.  While computing the checksum, the 
checksum field itself is replaced with zeros.

UDP
Checksum is the 16-bit one's complement of the one's complement sum of a
pseudo header of information from the IP header, the UDP header, and the
data,  padded  with zero octets  at the end (if  necessary)  to  make  a
multiple of two octets.

von Jörn K. (joern)


Lesenswert?

Das Ethernetframe wird mit einer CRC32 Prüfsumme gesichert, IP und UDP 
mit einer einfachen Prüfsumme. Bei UDP/IP werden einfach immer 16Bit 
Werte aufaddiert und später der Überlauf wieder zu einer 16 Prüfsumme 
"zusammengefaltet".

In "C" sieht das so aus:
1
Unsigned short CalcChecksum(void *addr, unsigned int Count)
2
{
3
   /* Compute Internet Checksum for "count" bytes
4
    * beginning at location "addr". */
5
    register long sum = 0;
6
    while (count > 1) {
7
      /* This is the inner loop */
8
      sum += * (unsigned short) addr++;
9
      count -= 2;
10
    }
11
    /* Add left-over byte, if any */
12
    if( count > 0 )
13
    sum += * (unsigned char *) addr;
14
    /* Fold 32-bit sum to 16 bits */
15
    while (sum>>16)
16
    sum = (sum & 0xffff) + (sum >> 16);
17
    checksum = ~sum;
18
}

läßt sich aber auch recht einfach in Logik auslagern.

Viele Grüße
Jörn

von DC (Gast)


Lesenswert?

Wie würde das ganze in Logik aussehen?

von Christian P. (kron)


Lesenswert?

Guck dir mal diese Seite an,
damit kannst du dir fix und fertig Code generieren lassen:
http://www.easics.com/webtools/crctool

von Jörn K. (joern)


Angehängte Dateien:

Lesenswert?

Blockschaltbild im Anhang

von MAZINE (Gast)


Lesenswert?

Top...

thx

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.