示例#1
0
int
iso_csum_verify (u_char * buffer, int len, uint16_t * csum)
{
  u_int16_t checksum;
  u_int32_t c0;
  u_int32_t c1;

  c0 = *csum & 0xff00;
  c1 = *csum & 0x00ff;

  /*
   * If both are zero return correct
   */
  if (c0 == 0 && c1 == 0)
    return 0;

  /*
   * If either, but not both are zero return incorrect
   */
  if (c0 == 0 || c1 == 0)
    return 1;

  /* Offset of checksum from the start of the buffer */
  int offset = (u_char *) csum - buffer;

  checksum = fletcher_checksum(buffer, len, offset);
  if (checksum == *csum)
    return 0;
  return 1;
}
示例#2
0
int
ospf_lsa_checksum_valid (struct lsa_header *lsa)
{
  u_char *buffer = (u_char *) &lsa->options;
  int options_offset = buffer - (u_char *) &lsa->ls_age; /* should be 2 */

  /* Skip the AGE field */
  u_int16_t len = ntohs(lsa->length) - options_offset;

  return(fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0);
}
示例#3
0
u_int16_t
ospf_lsa_checksum (struct lsa_header *lsa)
{
  u_char *buffer = (u_char *) &lsa->options;
  int options_offset = buffer - (u_char *) &lsa->ls_age; /* should be 2 */

  /* Skip the AGE field */
  u_int16_t len = ntohs(lsa->length) - options_offset;

  /* Checksum offset starts from "options" field, not the beginning of the
     lsa_header struct. The offset is 14, rather than 16. */
  int checksum_offset = (u_char *) &lsa->checksum - buffer;

  return fletcher_checksum(buffer, len, checksum_offset);
}