/*--------------------------------------------------------------------- * Method: process_ip(struct sr_instance* sr, * uint8_t * packet, * unsigned int len, * char* interface) * Scope: Internal * * Processes a received IP packet. Takes in a raw ethernet packet. * *---------------------------------------------------------------------*/ void process_ip(struct sr_instance* sr, uint8_t * packet, unsigned int len, char* interface) { struct sr_ip_hdr *ip_hdr; /* Return if it is not a valid ip packet */ if (!valid_ip(packet, len)) return; /* Is it destined for me?! */ ip_hdr = ip_header(packet); if (sr_interface_ip_match(sr, ip_hdr->ip_dst)) { /* Process ICMP. */ if (ip_hdr->ip_p == ip_protocol_icmp) { process_icmp(sr, ip_hdr); /* If it's TCP/UDP, send ICMP port unreachable. */ } else { sr_send_icmp(sr, (uint8_t *)ip_hdr, ip_len(ip_hdr), ICMP_UNREACHABLE_TYPE, ICMP_PORT_CODE); } /* Forward it. */ } else { forward_ip_pkt(sr, ip_hdr); } }
void logic_pinger_exec(void) { int i; struct logic_pinger_setup_s *setup = logic_pinger_setup; struct logic_pinger_state_s *state = logic_pinger_state; struct ping_state_s *ping = &ping_state[LOGIC_PING_CH]; systime_t time = sys_clock(); for(i=0; i<LOGIC_MAX_PINGER; ++i, ++setup, ++state, ++ping) { if(ping->state == PING_RESET && time >= state->next_time) { state->next_time = time + setup->period * 1000; if(valid_ip(setup->ip) == 0) { if(setup->hostname[0] == 0) { // no ip or hostname, skip state->result = 0xfe; continue; } else { // dns unresolved, treat as ping fail state->result = 0; continue; } } util_cpy(setup->ip, ping->ip, 4); ping->timeout = setup->timeout; ping->max_retry = 4; // 26.09.2013 fixed value state->attempt_counter = 0; ping->state = PING_START; } else if(ping->state == PING_COMPLETED) { state->result = ping->result; ping->state = PING_RESET; } } // for channels }
int main() { char c []="236.0.0.225"; valid_ip(c); }