16.04.2015 Views

Redes de computadores

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Re<strong>de</strong>s</strong> <strong>de</strong> <strong>computadores</strong><br />

ª FUOC • XP04/90786/00020<br />

Anexos<br />

Anexo 1<br />

El algoritmo checksum<br />

Los protocolos IP y TCP utilizan, entre otros, un sencillo checksum para<br />

la <strong>de</strong>tección <strong>de</strong> errores. Ésta es una versión <strong>de</strong>l algoritmo checksum:<br />

u_short checksum(u_short * addr,int len)<br />

{<br />

int aux_len = len;<br />

u_short *aux_addr = addr;<br />

u_short res;<br />

int sum = 0;<br />

while(aux_len > 1)<br />

{<br />

sum+ = *aux_addr++;<br />

aux_len- = 2;<br />

}<br />

if(aux_len == 1)<br />

sum+ = *(u_char) *aux_addr;<br />

}<br />

sum = (sum>>16) + (sum & 0xffff);<br />

sum+ = (sum>>16);<br />

res = ~sum;<br />

return res;<br />

ANOTACIONES<br />

331

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

Saved successfully!

Ooh no, something went wrong!