02.12.2014 Views

Redes de Computadoras

Redes de Computadoras

Redes de Computadoras

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

24.3. Checksum<br />

<strong>Re<strong>de</strong>s</strong> <strong>de</strong> <strong>Computadoras</strong>, 2007/08<br />

Consiste en sumar (usando una <strong>de</strong>terminada precisión aritmética) todas<br />

las palabras <strong>de</strong>l mensaje y transmitir como EDC dicha suma [22].<br />

El receptor realiza la misma suma y si no concuerda con el EDC se<br />

sabe que se ha producido un error <strong>de</strong> transmisión.<br />

Como ejemplo se muestra (en C) el algoritmo <strong>de</strong> la suma <strong>de</strong> comprobación<br />

usado por el TCP/IP:<br />

unsigned short cksum (unsigned short *buf, int count) { /* 1 */<br />

register unsigned long sum=0; /* 2 */<br />

while (count--) { /* 3 */<br />

sum += *buff++; /* 4 */<br />

if (sum & 0xFFFF0000) { /* 5 */<br />

sum &= 0xFFFF; /* 6 */<br />

sum++; /* 7 */<br />

} /* 8 */<br />

} /* 9 */<br />

return ~(sum & 0xFFFF); /* 10 */<br />

} /* 11 */<br />

24.3 Checksum 456

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!