/[pengfork]/pengfork/src/p3/check.c
ViewVC logotype

Diff of /pengfork/src/p3/check.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by chupa, Wed Sep 11 15:39:32 2002 UTC revision 1.9 by chupa, Thu Sep 12 15:00:12 2002 UTC
# Line 34  int Line 34  int
34  p3_check_header (header)  p3_check_header (header)
35       struct p3hdr *header;       struct p3hdr *header;
36  {  {
   /* Check size */  
   if (ntohs (header->size) > P3_MAX_SIZE - P3_SIZE_OFFSET ||  
       ntohs (header->size) < P3_SIZE_OFFSET)  
     return 0;  
37    
38    /* Check sequence number */    /* Check sequence number */
39    if (header->seq < PACKET_MIN_SEQ || header->seq > PACKET_MAX_SEQ)    if (header->seq < PACKET_MIN_SEQ || header->seq > PACKET_MAX_SEQ)
40      return 0;      {
41          debug (2, "P3 - Bad header received\n");
42          debug (3,"\tbad sequence: %02x\n", header->seq);
43          return 0;
44        }
45    
46    /* Check ack number */    /* Check ack number */
47    if (header->ack < PACKET_MIN_SEQ || header->ack > PACKET_MAX_SEQ)    if (header->ack < PACKET_MIN_SEQ || header->ack > PACKET_MAX_SEQ)
48      return 0;      {
49          debug (2, "P3 - Bad header received\n");
50          debug (3,"\tbad ack: %02x\n", header->ack);
51          return 0;
52        }
53    
54      /* Check size */
55      if (ntohs (header->size) > P3_MAX_SIZE - P3_SIZE_OFFSET ||
56          ntohs (header->size) < P3_SIZE_OFFSET)
57        {
58          debug (2, "P3 - Bad header received\n");
59          debug (3,"\tbad size: %d\n", ntohs (header->size));
60          return 0;
61        }
62    
63    /* Check type */    /* Check type */
64    if (header->type < TYPE_DATA || header->type > TYPE_PING)    if (header->type < TYPE_DATA || header->type > TYPE_PING)
65      return 0;      {
66          debug (2, "P3 - Bad header received\n");
67          debug (3,"\tbad type: %02x\n", header->type);
68          return 0;
69        }
70    
71    return 1;    return 1;
72  }  }
# Line 68  p3_check_packet (header, data, data_size Line 85  p3_check_packet (header, data, data_size
85    /* Check packet is 0x0d terminated */    /* Check packet is 0x0d terminated */
86    if (p[data_size] != P3_STOP)    if (p[data_size] != P3_STOP)
87      {      {
88        debug(1,"P3 - Bad packet received:\n");        debug (1,"P3 - Bad packet received:\n");
89        debug(1,"\tnot 0x0d terminated\n");        debug (1,"\tnot 0x0d terminated\n");
90        p3_send_nack (header);        p3_send_nack (header);
91        return 0;        return 0;
92      }      }
# Line 77  p3_check_packet (header, data, data_size Line 94  p3_check_packet (header, data, data_size
94    /* Check client bit */    /* Check client bit */
95    if(header->client)    if(header->client)
96      {      {
97        debug(1,"P3 - Bad packet received:\n");        debug (1,"P3 - Bad packet received:\n");
98        debug(1,"\tthis is a client packet!\n");        debug (1,"\tthis is a client packet!\n");
99        p3_send_nack (header);        p3_send_nack (header);
100        return 0;        return 0;
101      }      }
# Line 87  p3_check_packet (header, data, data_size Line 104  p3_check_packet (header, data, data_size
104    crc = htons (p3_crc16 ((char *) &header->size, data_size + 5));    crc = htons (p3_crc16 ((char *) &header->size, data_size + 5));
105    if (crc != header->checksum)    if (crc != header->checksum)
106      {      {
107        debug(1,"P3 - Bad packet received:\n");        debug (1,"P3 - Bad packet received:\n");
108        debug(1,"\tbad CRC checksum\n");        debug (1,"\tbad CRC checksum\n");
109        p3_send_nack (header);        p3_send_nack (header);
110        return 0;        return 0;
111      }      }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26