реклама на сайте
подробности

 
 
 
Reply to this topicStart new topic
> IP прототокол, контрольная сумма
zpv78
сообщение May 15 2007, 22:33
Сообщение #1





Группа: Новичок
Сообщений: 13
Регистрация: 8-02-07
Пользователь №: 25 181



Подскажите, пожалуйста, алгоритм подсчета контрольной суммы IP заголовка. Там есть поля по одному байту и по два байта, что-то я не пойму как она считается.
Заранее благодарен.
Go to the top of the page
 
+Quote Post
lebiga
сообщение May 16 2007, 01:13
Сообщение #2


Частый гость
**

Группа: Свой
Сообщений: 163
Регистрация: 22-06-06
Из: Киев
Пользователь №: 18 292



Цитата(zpv78 @ May 16 2007, 06:33) *
Подскажите, пожалуйста, алгоритм подсчета контрольной суммы IP заголовка. Там есть поля по одному байту и по два байта, что-то я не пойму как она считается.
Заранее благодарен.


Смотри пример из микрочиповского стека
Прикрепленные файлы
Прикрепленный файл  TCPIP_Stack_IP_Checksum.rar ( 7.28 килобайт ) Кол-во скачиваний: 57
 
Go to the top of the page
 
+Quote Post
zltigo
сообщение May 16 2007, 01:27
Сообщение #3


Гуру
******

Группа: Свой
Сообщений: 13 372
Регистрация: 27-11-04
Из: Riga, Latvia
Пользователь №: 1 244



Цитата(zpv78 @ May 16 2007, 05:33) *
алгоритм подсчета контрольной суммы IP заголовка.

RFC 791, как первооснова. Проще читать, чем чьи-то исходники smile.gif


--------------------
Feci, quod potui, faciant meliora potentes
Go to the top of the page
 
+Quote Post
ClockworkOrange
сообщение May 17 2007, 11:55
Сообщение #4


Местный
***

Группа: Свой
Сообщений: 337
Регистрация: 17-05-07
Пользователь №: 27 784



Цитата(zpv78 @ May 16 2007, 02:33) *
Подскажите, пожалуйста, алгоритм подсчета контрольной суммы IP заголовка.


this is beautiful guide:
Цитата
Checksum
As a precaution against corruption by routers, there is a checksum for the IP header. The steps for
transmission are as follows.
1. Prepare and byte swap the header.
2. If it is an odd length, pad with a zero byte.
3. Clear the checksum field.
4. Sum the 16-bit words in the header.
5. Put the one's complement of the result in the checksum field.
The addition is somewhat unusual, in that any carry bits are added back on.

Код
long sum;
WORD *data;
sum += *data++;
if (sum & 0x10000L)
  sum = (sum & 0xffffL) + 1;

This addition method is particularly suitable for implementation in assembly language because it is just a
repeated add-with-carry, irrespective of whether a big endian or little endian processor is being used. There
is a useful optimization to the C version, which involves saving up the carry bits then adding them on at the
end.
Код
/* Do checksum. Improved algorithm is from RFC 1071 */
WORD csum(void *dp, WORD count)
{
  register LWORD total=0L;
  register WORD n, *p, carries;
  n = count / 2;
  p = (WORD *)dp;
  while (n--)
    total += *p++;
  if (count & 1)
    total += *(BYTE *)p;
  while ((carries=(WORD)(total >>16))!=0)
    total = (total & 0xffffL) + carries;
  return((WORD)total);
}

This also caters to an odd length by doing an extra single-byte addition (little endian processors only). On
reception, the datagram header is verified by applying the checksum across it; the result should be FFFFh.


+ of cource, RFC 1071 - Computing the Internet checksum

Сообщение отредактировал ClockworkOrange - May 17 2007, 11:53


--------------------
Чтoбы yзнaть, кaкaя дopoгa впepeди, cпpocи тex, ктo пo нeй вoзвpaщaeтcя ©
Go to the top of the page
 
+Quote Post
zpv
сообщение May 21 2007, 07:16
Сообщение #5


Участник
*

Группа: Участник
Сообщений: 40
Регистрация: 4-11-05
Пользователь №: 10 471



Спасибо за помощь, разобрался.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 25th July 2025 - 19:30
Рейтинг@Mail.ru


Страница сгенерированна за 0.01404 секунд с 7
ELECTRONIX ©2004-2016