Watchdog源码--neighboursPacketDetected

/**
* A packet from a neighbour has been detected.
*/
void
WATCHDOG::neighboursPacketDetected(int32_t source_ip, int32_t destination_ip, int source_mac, int destination_mac, int sourcePort, int destinationPort, char * tmp_data, packet_t packet_type, double pktime) {
if (debug > 2) printf("NeighbourPacket\n");
neighbour *neigh_src, *neigh_dst;
int data_size;

data_size = strlen(tmp_data);
protocol = packet_type;

neigh_src = neigs->ExistNeighbourMac(source_mac);
neigh_dst = neigs->ExistNeighbourMac(destination_mac);

if (isInterestingPacket(source_ip, source_mac, destination_ip, destination_mac)) {
/* If the destination IP is different of the destination neighbour, means that must be forwarded */
if (neigh_dst != NULL && (neigh_dst->ip != 666) && (destination_ip != neigh_dst->ip)) {
neigs->ShowAllNeighbours();
waitingForwardPacket(source_ip, destination_ip, sourcePort, destinationPort, tmp_data, data_size, neigh_dst, protocol, pktime);
}else{
if(destination_mac!=ownMAC){
neigs->ShowAllNeighbours();
}
}
/* If the IP source is different of the sender, means that is a forwarded packet */
if ((neigh_src != NULL) && (neigh_src->ip != 666)){
if (debug > 2) printf("Sender: %d Hop: %d Destination: %d\n", source_mac, neigh_src->mac, destination_ip);
if (source_ip != neigh_src->ip) {
packetForwarded(destination_ip, source_ip, tmp_data, data_size, neigh_src, protocol, pktime);
}}
}
}
/**
* A packet has been forwarded, delete it from the waiting forward list.
*/
void
WATCHDOG::packetForwarded(int32_t destination_ip, int32_t source_ip, char *body, int data_size, neighbour *neigh, int protocol, double pktime) {
if (debug > 2) printf("packetForwarded\n");
if (neigh != NULL) {
neigs->AddNeighbourPacketForwarded(neigh, body, destination_ip, source_ip, data_size, storing_packet_timeout, protocol, pktime);
}
}
 * Add a packet to a neighbour not forwarded yet.
*/
void
NEIGHBOURS::AddNeighbourPacketForwarded(neighbour *neig, char *body, int32_t ip_dst, int32_t ip_src, int data_size, int storing_time, int protocol, double pktime) {
neig->time = pktime;
neig->pckts->AddPacketForwarded(body, ip_dst, ip_src, data_size, storing_time, protocol, pktime);
}
/**
* Indicates that a new packet forwarded has been listened.
*/
void
PACKETS::AddPacketForwarded( char *body, int32_t ip_dst, int32_t ip_src, int data_size, int storing_time, int protocol, double pktime) {
packet * exists;
exists = ExistsPacket(body, ip_dst, ip_src, data_size, storing_time, protocol, pktime);
if (exists != NULL) {
pckts->forwarded_packets[protocol]++;
RemovePacket(exists, protocol);
}
}

 

/**
* Delete a stored packet.
*/
void
PACKETS::RemovePacket( packet *pk, int protocol) {
packet *next, *prev;
if (pk != NULL) {
next = pk->next;
prev = pk->previous;

/* is the first packet */
if (pk == pckts->packets[protocol]) {
pckts->packets[protocol] = pk->next;
}

/* is the last packet */
if (pk == pckts->last_packet[protocol]) {
pckts->last_packet[protocol] = pk->previous;
}

if (next != NULL) next->previous = prev;
if (prev != NULL) prev->next = next;

pckts->stored_packets--;
pckts->stored_packets_protocol[protocol] = pckts->stored_packets_protocol[protocol] - (1 / pk->devalue);
DeletePacket(pk);
pk = NULL;

} else {
printf("This packet does not exists!\n");
}
}





转载于:https://www.cnblogs.com/zhangrui/archive/2012/03/08/2385236.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值