저는 수동으로 OSPF 패킷을 생성해야하는 프로젝트에서 작업하고 있습니다. 현재 OSPF 체크섬을 올바르게 가져 오는 데 문제가 있습니다. 나는 Auth 데이터를 계산에서 제외시켜야한다는 것을 알았고, 비록 내가 그것을하고있다하더라도 나는 그것을 작동시키지 못한다. IP 헤더의 체크섬을 생성하기 위해 동일한 것을 사용하기 때문에 체크섬을 생성하는 데 사용되는 함수가 정확하다는 것을 알고 있습니다.OSPF - 체크섬이 작동하지 않습니다.
* 나쁜 C 프로그래밍은 유감스럽게 생각하며, 제 주요 언어가 아닙니다.
void generateHello(unsigned char* packet_return,unsigned char* buff,unsigned short *ospf_packet){
ospf_packet = (unsigned short*) malloc(14*sizeof(unsigned short));
//OSPF Version
packet_return[34] = 0x02;
//Message Type - Hello
packet_return[35] = 0x01;
//Packet Length
packet_return[36] = 0x00;
packet_return[37] = 0x2c;
//Source OSPF Router (IP)
packet_return[38]=local_ip[0];
packet_return[39]=local_ip[1];
packet_return[40]=local_ip[2];
packet_return[41]=local_ip[3];
//Area
packet_return[42]=0x00;
packet_return[43]=0x00;
packet_return[44]=0x00;
packet_return[45]=0x01;
//ADD CHECKSUM
packet_return[46]=0x00;
packet_return[47]=0x00;
//Auth Type
packet_return[48]=0x00;
packet_return[49]=0x00;
//Auth Data
packet_return[50]=0x00;
packet_return[51]=0x00;
packet_return[52]=0x00;
packet_return[53]=0x00;
packet_return[54]=0x00;
packet_return[55]=0x00;
packet_return[56]=0x00;
packet_return[57]=0x00;
//Network Mask
packet_return[58]=0xff;
packet_return[59]=0xff;
packet_return[60]=0xff;
packet_return[61]=0x00;
//Hello Interval
packet_return[62]=0x00;
packet_return[63]=0x0a;
//Multi-Topology Routing
packet_return[64]=0x12;
//Router Priority
packet_return[65]=0x01;
//Router Dead Interval
packet_return[66]=0x00;
packet_return[67]=0x00;
packet_return[68]=0x00;
packet_return[69]=0x28;
//Designated Router
packet_return[70]=0x00;
packet_return[71]=0x00;
packet_return[72]=0x00;
packet_return[73]=0x00;
//Backup designated router
packet_return[74]=0x00;
packet_return[75]=0x00;
packet_return[76]=0x00;
packet_return[77]=0x00;
//Checksum
packet_return[78]=0x00;
packet_return[79]=0x00;
//LLS Data Length
packet_return[80]=0x00;
packet_return[81]=0x03;
//Type
packet_return[82]=0x00;
packet_return[83]=0x01;
//Length
packet_return[84]=0x00;
packet_return[85]=0x04;
//Options - LSDB Resynchronization
packet_return[86]=0x00;
packet_return[87]=0x00;
packet_return[88]=0x00;
packet_return[89]=0x01;
int i;
int j;
for(i=0,j=34;i<48;i++,j+=2)
{
ospf_packet[i]= htons(((packet_return[j] << 8) | packet_return[j+1]));
}
unsigned short ck_sum = in_cksum(ospf_packet,sizeof(unsigned short)*14);
printf("CHECKSUM OSPF - %.4x \n", ck_sum);
packet_return[46]=ck_sum & 0xff;
packet_return[47]=(ck_sum >> 8) & 0xff;
}