Пример #1
0
Файл: arp.c Проект: pizhi/ok6410
void arp_progress()
{
	FLAG_ARPPR0CESS = 1;
	arp_request();
	while(FLAG_ARPPR0CESS);
	
}
Пример #2
0
void arp_timer(int delta)
{
	struct arpentry *ae;

	arp_cache_lock();
	for (ae = arp_cache_head; ae < arp_cache_end; ae++) {
		if (ae->ae_state == ARP_FREE)
			continue;
		ae->ae_ttl -= delta;
		if (ae->ae_ttl <= 0) {
			if ((ae->ae_state == ARP_WAITING && --ae->ae_retry < 0)
				|| ae->ae_state == ARP_RESOLVED) {
				if (ae->ae_state == ARP_WAITING)
					arp_queue_drop(ae);
				ae->ae_state = ARP_FREE;
			} else {
				/* retry arp request */
				ae->ae_ttl = ARP_WAITTIME;
				arp_cache_unlock();
				arp_request(ae);
				arp_cache_lock();
			}
		}
	}
	arp_cache_unlock();
}
Пример #3
0
static void timer(ENTRY *entry)
{
    switch (entry->state) {
	case as_resolv:
	    arp_request(entry->itf,entry->ip);
	    break;
	case as_invalid:
	    if (entry->vccs) inarp_request(entry);
	    else if (!(entry->flags & ATF_ARPSRV))
		    diag(COMPONENT,DIAG_INFO,"as_invalid, no VCCs, but not "
		      "ARP server entry");
			/* this is a valid condition if we're the ATMARP server
			   and the remote disconnected */
		    else if (!want_arp_srv(entry->itf)) STOP_TIMER(entry);
	    break;
	case as_valid:
	    if (entry->flags & ATF_ARPSRV) {
		if (!want_arp_srv(entry->itf)) STOP_TIMER(entry);
		break;
	    }
	    /* fall through */
	default:
	    diag(COMPONENT,DIAG_FATAL,"timer in state %d",entry->state);
    }
}
Пример #4
0
int main(int argc, const char *argv[])
{
	const char* ethdevide = NULL, * arpsrcip = NULL, * arpdstip = NULL, * arpsrcmac = NULL;

	if (argc >= 5)
	{
		ethdevide = argv[2];
		if (!strcmp(argv[1], "spoofMAC"))
			arpsrcmac = argv[3];
		else if (!strcmp(argv[1], "spoofIP"))
			arpsrcip = argv[3];
		else
			goto error_format;
		arpdstip = argv[4];
	}
	else
	{
error_format:
		printf("Useage: arp.exe EthDevice srcIP srcMAC, dstIP\n");
		printf("Useage:\nfor spoofing ARPMAC: ./arp.exe spoofMAC Ethdevice arpMAC dstIP\n");
		printf("for spoofing ARPIP: ./arp.exe spoofIP Ethdevice arpIP dstIP\n");
		printf("the default is: h1 ping h2\n");
		ethdevide = "h1-eth0";
		/*
		arpsrcip = "10.0.0.1";
		arpsrcmac = "00:00:00:00:01";*/
		arpdstip = "10.0.0.2";
	}
	arp_request(ethdevide, arpsrcip, arpsrcmac, arpdstip);
	return 0;
}
Пример #5
0
MINI2440_STATUS arp_test(int argc, char(*argv)[MAX_COMMAND_LENGTH])
{
	MINI2440_STATUS status = MINI2440_SUCCESS;
	
	u32 isr_status = 0;
	char recv_char[200] = {'\0'};
	int test_times = 10;
	
	dm9000_init();
	
	print_string("arp_test\n");
	
	delay(1000000);
	
	while(test_times--)
	{
		arp_request();
		
		delay(200000);
	}

	dm9000_int_clear();
	
	return status;
}
Пример #6
0
static void revalidate(ENTRY *entry)
{
    entry->state = as_resolv;
    if (want_arp_srv(entry->itf) <= 0) return;
    arp_request(entry->itf,entry->ip);
    START_TIMER(entry,REPLY);
}
Пример #7
0
static int ping_send(void)
{
	uchar *pkt;
	int eth_hdr_size;

	/* XXX always send arp request */

	debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &net_ping_ip);

	net_arp_wait_packet_ip = net_ping_ip;

	eth_hdr_size = net_set_ether(net_tx_packet, net_null_ethaddr, PROT_IP);
	pkt = (uchar *)net_tx_packet + eth_hdr_size;

	set_icmp_header(pkt, net_ping_ip);

	/* size of the waiting packet */
	arp_wait_tx_packet_size = eth_hdr_size + IP_ICMP_HDR_SIZE;

	/* and do the ARP request */
	arp_wait_try = 1;
	arp_wait_timer_start = get_timer(0);
	arp_request();
	return 1;	/* waiting */
}
Пример #8
0
void arp_handle() {

    //cprintf("receive arp .............................\n");
    int * data = ethernet_rx_data + ETHERNET_HDR_LEN;
    if(data[ARP_TYPE] == ARP_TYPE_REPLY) {
        if(eth_memcmp(data + ARP_TARGET_IP, IP_ADDR, 4) != 0);
            return;

        int i=0;
        for (i=0; i<4; i++)
            cprintf("%d\n", *(data+ARP_SENDER_IP+i));
        //tcp_request();
		
		for (i = 0; i < 6; i++)
			remote_mac[i] = *(data+ARP_SENDER_MAC+i);
		
 
    }
	else if (data[ARP_TYPE] == ARP_TYPE_REQUEST && 
		     data[ARP_TARGET_IP] == IP_ADDR[0] &&
			 data[ARP_TARGET_IP + 1] == IP_ADDR[1] &&
			 data[ARP_TARGET_IP + 2] == IP_ADDR[2] &&
			 data[ARP_TARGET_IP + 3] == IP_ADDR[3]) 
	{
		ethernet_tx_len = ETHERNET_HDR_LEN + ARP_BODY_LEN;
        ethernet_set_tx(ethernet_rx_src, ETHERNET_TYPE_ARP);
		
        int * buf = ethernet_tx_data + ETHERNET_HDR_LEN;
		eth_memcpy(buf, ARP_FIX_HDR, 6 + 1);
		buf[ARP_TYPE] = ARP_TYPE_REPLY;
        eth_memcpy(buf + ARP_SENDER_MAC, MAC_ADDR, 6);
        eth_memcpy(buf + ARP_SENDER_IP, IP_ADDR, 4);
        eth_memcpy(buf + ARP_TARGET_MAC,
               data + ARP_SENDER_MAC, 6);
        eth_memcpy(buf + ARP_TARGET_IP,
               data + ARP_SENDER_IP, 4);
		
		cprintf("send arp response...\n");
		
        ethernet_send();
	}
	else if (data[ARP_TYPE] == ARP_TYPE_REQUEST && 
		     data[ARP_TARGET_IP] == data[ARP_SENDER_IP] &&
			 data[ARP_TARGET_IP + 1] == data[ARP_SENDER_IP + 1] &&
			 data[ARP_TARGET_IP + 2] == data[ARP_SENDER_IP + 2] &&
			 data[ARP_TARGET_IP + 3] == data[ARP_SENDER_IP + 3]) //Is gratuitous = true
	{
		if (data[ARP_TARGET_IP] ==  tcp_dst_addr[0] &&
			 data[ARP_TARGET_IP + 1] == tcp_dst_addr[1] &&
			 data[ARP_TARGET_IP + 2] == tcp_dst_addr[2] &&
			 data[ARP_TARGET_IP + 3] == tcp_dst_addr[3])
		{
			int i;
			for (i = 0; i < 6; i++)
				remote_mac[i] = *(data+ARP_SENDER_MAC+i);
			arp_request();
			tcp_request();
		}
	}
}
Пример #9
0
void cache_add_packet(struct sr_instance * sr, uint8_t * packet, unsigned int length, char * interface, struct in_addr ip) {
	struct in_addr dest_ip = next_hop_ip(sr, ip);
	struct sr_arp_record *record = cache_lookup(sr, dest_ip);
	
	if(record == NULL) {
		// Check to see if there is an outstanding ARP request
		struct sr_arp_request *request = cache_lookup_outstanding(sr, dest_ip);
		if(request == NULL) {
			// Create a new ARP request
			if(arp_request(sr, dest_ip, interface) == 0) {
				request = cache_add_request(sr, dest_ip);
				// Add the recieved message to the outstanding arp request
				cache_add_message(request, packet, length, interface, ip);
			} /* endif: arp request sent succesfully */
			
			else {
				printf("ARP request failed for address %s - dropping packet.\n", inet_ntoa(ip));
			} /* endelse: arp request not sent succesfully */
			
		} /* endif: no outstanding ARP request */
		
		else {
			cache_add_message(request, packet, length, interface, ip);
		} /* endelse: ARP request already outstanding for this ip */
		
	} /* endif: No record */
	
	else {
		// Send packet
		struct sr_ethernet_hdr *eth_hdr = (struct sr_ethernet_hdr *)packet;
		memcpy(eth_hdr->ether_dhost, record->address, ETHER_ADDR_LEN);
		sr_send_packet(sr, packet, length, interface);
	} /* endelse: ARP record already exists */
}
Пример #10
0
int arp_resolve(char * ipdest, char * hwaddr) {
  int i;
  char proaddr[4];
  struct arp_entry * entry;

  if (differ_subnet(ipdest)) {
#if debug_arp
    printf("Different SubNet: using Gateway IP address\r\n");
#endif
    memcpy(proaddr, Gateway, 4);
  }else {
    memcpy(proaddr, ipdest, 4);
  }
  for(i=0;i<ARP_CACHE_SIZE;i++) {
    entry = &arp_cache[i];
    if (entry->state == ARP_ENTRY_FREE)
      continue;
    if ( memcmp(entry->proaddr, proaddr, 4)==0) {
      memcpy(hwaddr, entry->hwaddr,6);
      entry->queries++;	
      return ARP_ENTRY_FOUND;
    }
  }
  arp_request(proaddr);
#if debug_arp
  printf("ARP: Entry not found! Sending an ARP Request (Broadcast)\r\n");
#endif
  return ARP_ENTRY_NOT_FOUND;
}
Пример #11
0
//-----------------------------------------------------------------------------------
// sending msg to syslog server defined in EEPROM
void syslog_send ( char *msg )
{
	char *packet = (char *)(eth_buffer+UDP_DATA_START);
	char *pp = packet;
	int i = 0;

	SYSLOG_DEBUG("SYSLOG send %s\r\n", msg);

	(*((unsigned long*)&syslog_server_ip[0])) = para_getip(SYSLOG_IP_EEPROM_STORE,SYSLOG_IP);
	SYSLOG_DEBUG("Server: %1i.%1i.%1i.%1i\r\n",syslog_server_ip[0],syslog_server_ip[1],syslog_server_ip[2],syslog_server_ip[3]);

	//Arp-Request senden
	unsigned long tmp_ip = (*(unsigned long*)&syslog_server_ip[0]);
	if ( syslog_server_ip[3] != 0xFF )	// quickhack for broadcast address
		if ( arp_entry_search(tmp_ip) >= MAX_ARP_ENTRY ) //Arp-Request senden?
			for ( i=0; i<SYSLOG_ARPRETRIES && (arp_request(tmp_ip) != 1); i++ );

	if (i>=SYSLOG_ARPRETRIES) {
	  SYSLOG_ERROR("No SYSLOG server!\r\n");
	}

	// building the packet structure
	*pp++ = '<';
	*pp++ = '0';
	*pp++ = '>';
	strcpy ( pp, msg );
	create_new_udp_packet(strlen(packet),SYSLOG_CLIENT_PORT,SYSLOG_SERVER_PORT,tmp_ip);
}
Пример #12
0
static void arp_pack_func(void** state) {
	// Nic initialization
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	__nics[0] = malloc(sizeof(NIC));
	__nic_count++;

	__nics[0]->mac = 0x10c37b9309d1;
	__nics[0]->pool_size = POOL_SIZE;
	__nics[0]->pool = malloc_pool;
	__nics[0]->output_buffer = fifo_create(8, malloc_pool);
	__nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool);

	uint32_t spa = 0xc0a80a6f;
	uint32_t dpa = 0xc0a80a90;
	arp_request(__nics[0], dpa, spa);

	Packet* packet = fifo_pop(__nics[0]->output_buffer); 
	uint32_t comp_size = packet->end;
	packet->end = 0;

	arp_pack(packet);

	// Checking packet->end
	assert_int_equal(comp_size, packet->end);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
Пример #13
0
bool_t
arp_resolve (T_IF_ADDR *ifaddr, T_NET_BUF *output, T_IN4_ADDR gw)
{
	T_ARP_ENTRY	*ent;
	T_ETHER_HDR	*eth;
	T_IFNET		*ifp = IF_GET_IFNET();

	eth = GET_ETHER_HDR(output);

	/*
	 *  次の場合は、イーサネットのブロードキャストアドレスを返す。
	 *
	 *    ・全ビットが 1
	 *    ・ホスト部の全ビットが 1 で、ネットワーク部がローカルアドレス
	 */
	if (gw == IPV4_ADDR_BROADCAST ||
	    gw == ((ifp->in_ifaddr.addr & ifp->in_ifaddr.mask) | ~ifp->in_ifaddr.mask)) {
		memcpy(eth->dhost, ether_broad_cast_addr, ETHER_ADDR_LEN);
		return true;
		}

	/* 送信先 GW の IP アドレスが ARP キャッシュにあるか調べる。*/
	syscall(wai_sem(SEM_ARP_CACHE_LOCK));
	ent = arp_lookup(gw, true);
	if (ent->expire) {
		memcpy(eth->dhost, ent->mac_addr, ETHER_ADDR_LEN);
		syscall(sig_sem(SEM_ARP_CACHE_LOCK));
		return true;
		}
	else {
	 	/* 送信がペンデングされているフレームがあれば捨てる。*/
		if (ent->hold) {
			NET_COUNT_IP4(net_count_ip4[NC_IP4_OUT_ERR_PACKETS], 1);
			syscall(rel_net_buf(ent->hold));
			}

		/*
		 *  送信をペンディングする。
		 *  IF でネットワークバッファを開放しないフラグが設定されているときは、
		 *  送信をペンディングしない。
		 */
		if ((output->flags & NB_FLG_NOREL_IFOUT) == 0)
			ent->hold = output;
		else {
			output->flags &= (uint8_t)~NB_FLG_NOREL_IFOUT;
			ent->hold = NULL;
			}
		syscall(sig_sem(SEM_ARP_CACHE_LOCK));

		/* アドレス解決要求を送信する。*/
		arp_request(ifaddr, gw);
		return false;
		}
	}
Пример #14
0
void Node::verify_arp_cache(string address)
{
	time_t timestamp = time(0);
	//Endereco nao esta na ARP Cache. Comecando o processo do ARP
	if(arp_cache.size() < 1 || arp_cache.find(address) == arp_cache.end()) arp_request(this->arp_packet,address);
	//Aguardando 15 segundos para o retorno de resposta, caso contrario, Timeout
	while(arp_cache.find(address) == arp_cache.end()){ 
		try { if(time(0)-timestamp > 15) throw TimeoutException(); }
		catch(exception& e){ cout << e.what() << endl; break; }
	}
}
Пример #15
0
int arp_lookup(struct netdevice* dev, uint32_t ip, mac dest) {
    for (int e = 0; e < table.count; e++) {
        if (table.ips[e] == ip) {
            memcpy(dest, table.macs[e], 6);
            return 1;
        }
    }

    arp_request(dev, ip);
    return 0;
}
Пример #16
0
struct arptab *arp_lookup(struct sk_buff *skb, __be32 daddr, unsigned char *mac)
{
	struct arptab *entry;

	pthread_spin_lock(&arp_lock);
	entry = &arp_table[arp_hash(daddr)];
	if (entry->status == ARP_STATUS_EMPTY)
	{
		arp_queue_try_insert(skb);
		entry->status = ARP_STATUS_REQUEST;
		pthread_spin_unlock(&arp_lock);
		arp_request(daddr);
		goto wait;
	}
	else if (entry->status == ARP_STATUS_REQUEST)
	{
		arp_queue_try_insert(skb);
		pthread_spin_unlock(&arp_lock);
		arp_request(daddr);
		goto wait;
	}
	else
	{
		if (get_second() > entry->time + ARP_MAX_LIFE)
		{
			arp_queue_try_insert(skb);
			entry->status = ARP_STATUS_REQUEST;
			pthread_spin_unlock(&arp_lock);
			arp_request(daddr);
			goto wait;
		}
		else
		{
			memcpy(mac, entry->mac, ETH_ALEN);
			pthread_spin_unlock(&arp_lock);
			return entry;
		}
	}
wait:
	return NULL;
}
Пример #17
0
void arp_poll(void) {
  int i;

  if (timer_expired(&arptimer)) {		// 100 msec has elapsed
    for(i=0; i<ARP_CACHE_SIZE; i++) {
      if (arp_cache[i].state != ARP_ENTRY_FREE)
        arp_cache[i].tout--;
    }
    timer_start(&arptimer, CLOCK_SECOND/10);// 100ms
  }else
    return;

  for(i=0; i<ARP_CACHE_SIZE; i++) {
    if (arp_cache[i].state == ARP_ENTRY_FREE)
      continue;
    if (arp_cache[i].tout == ARP_ENTRY_TIMED_OUT) {
      switch(arp_cache[i].state) {
        case ARP_ENTRY_OK:
	  arp_request(arp_cache[i].proaddr);
	  arp_cache[i].tout = ARP_REQUEST_TOUT;
	  arp_cache[i].state = ARP_ENTRY_RESOLVING;
	  break;
        case ARP_ENTRY_RESOLVING:
	  if (arp_cache[i].retries > 0) {
	    arp_cache[i].retries--;
	    arp_request(arp_cache[i].proaddr);
	    arp_cache[i].tout = ARP_REQUEST_TOUT;
          }else
            arp_cache[i].state = ARP_ENTRY_FREE;
	    break;
        default:
		#if debug_arp
	       printf("ARP: Invalid State!\r\n");
		#endif
		;
      }
    }
  }
}
Пример #18
0
//----------------------------------------------------------------------------
//HTTP Request an einen Webserver stelle
void http_request (void)
{
    unsigned long index = MAX_TCP_ENTRY;
    
    if (http_get_state > 1 && http_get_state < 20) http_get_state++;

    if (http_get_state == 0)
    {
        //offnet eine Verbindung zu meinem Webserver
        HTTPC_DEBUG("ARP Request\n\r");
        unsigned int my_http_cp = 2354;
        add_tcp_app (my_http_cp, (void(*)(unsigned char))test);
        
        //ARP Request senden
        if(arp_request (WEATHER_SERVER_IP))
        {
            for(unsigned long a=0;a<2000000;a++){asm("nop");};
            
            tcp_port_open (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80),LBBL_ENDIAN_INT(my_http_cp));
               
            unsigned char tmp_counter = 0;
            while((index >= MAX_ARP_ENTRY) && (tcp_entry[index].app_status != 1))
            {
                index = tcp_entry_search (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80));
                if (tmp_counter++ > 30)
                {
                    HTTPC_DEBUG("TCP Eintrag nicht gefunden (HTTP_CLIENT)!\r\n");
                    return;
                }
            }
             
            HTTPC_DEBUG("TCP Eintrag gefunden (HTTP_CLIENT)!\r\n");
            tcp_entry[index].first_ack = 1;
            http_get_state = 2;
        }
        else
        {
            http_get_state = 1;
        }
    }
    
    //if (http_get_state == 10)  
    if (http_get_state > 10 && http_get_state < 20)
    {
        HTTPC_DEBUG("\r\n\r\n\r\nDaten Anfordern\r\n");
        index = tcp_entry_search (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80));
        memcpy_P(&eth_buffer[TCP_DATA_START],WEATHER_GET_STRING,(sizeof(WEATHER_GET_STRING)-1));
        tcp_entry[index].status =  ACK_FLAG | PSH_FLAG;
        create_new_tcp_packet((sizeof(WEATHER_GET_STRING)-1),index);
    }
}
Пример #19
0
int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, int sport,
		int payload_len)
{
	uchar *pkt;
	int eth_hdr_size;
	int pkt_hdr_size;

	/* make sure the net_tx_packet is initialized (net_init() was called) */
	assert(net_tx_packet != NULL);
	if (net_tx_packet == NULL)
		return -1;

	/* convert to new style broadcast */
	if (dest.s_addr == 0)
		dest.s_addr = 0xFFFFFFFF;

	/* if broadcast, make the ether address a broadcast and don't do ARP */
	if (dest.s_addr == 0xFFFFFFFF)
		ether = (uchar *)net_bcast_ethaddr;

	pkt = (uchar *)net_tx_packet;

	eth_hdr_size = net_set_ether(pkt, ether, PROT_IP);
	pkt += eth_hdr_size;
	net_set_udp_header(pkt, dest, dport, sport, payload_len);
	pkt_hdr_size = eth_hdr_size + IP_UDP_HDR_SIZE;

	/* if MAC address was not discovered yet, do an ARP request */
	if (memcmp(ether, net_null_ethaddr, 6) == 0) {
		debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &dest);

		/* save the ip and eth addr for the packet to send after arp */
		net_arp_wait_packet_ip = dest;
		arp_wait_packet_ethaddr = ether;

		/* size of the waiting packet */
		arp_wait_tx_packet_size = pkt_hdr_size + payload_len;

		/* and do the ARP request */
		arp_wait_try = 1;
		arp_wait_timer_start = get_timer(0);
		arp_request();
		return 1;	/* waiting */
	} else {
		debug_cond(DEBUG_DEV_PKT, "sending UDP to %pI4/%pM\n",
			   &dest, ether);
		net_send_packet(net_tx_packet, pkt_hdr_size + payload_len);
		return 0;	/* transmitted */
	}
}
Пример #20
0
Файл: arp.c Проект: bkbme/avr
void arp_send_request(ip_addr* ip)
{
	eth_addr brdcast;
	brdcast.words[0] = HTONS(0xffff);
	brdcast.words[1] = HTONS(0xffff);
	brdcast.words[2] = HTONS(0xffff);

	buffer_t* buf = NULL;
	buffer_create(buf, ARP_PLEN);
	ethernet_gen_header(&brdcast, ETHERTYPE_ARP, buf->data);
	ethernet_header* eh = (ethernet_header*)buf->data;
	arp_request(ip, buf->data+sizeof(ethernet_header));
	enc_prepare_ethernet_packet(eh);
	enc_add_packet_data(buf->data+sizeof(ethernet_header), sizeof(arp_header));
	enc_send_packet();
}
Пример #21
0
int arp_cache_get_haddr(in_addr_t iface, in_addr_t ip_addr, mac_addr_t haddr)
{
    struct arp_cache_entry * entry = arp_cache_get_entry(ip_addr);
    struct ip_route route;

    if (entry && entry->age >= 0) {
        memcpy(haddr, entry->haddr, sizeof(mac_addr_t));
        return 0;
    }

    if (!ip_route_find_by_iface(iface, &route) &&
        !arp_request(route.r_iface_handle, route.r_iface, ip_addr)) {
        errno = EHOSTUNREACH;
    }

    return -1;
}
Пример #22
0
void shell_arp(void)
{
	uint8_t tarip[] = {192,168,1,100};
	uint8_t mode = atoi(cmd_pointer[1]);
	
	if(ARP_TABLE == mode)
	{
		arp_show_table();
	}
	else if(ARP_REQ == mode)
	{
		arp_request(tarip);
		printf("a arp packet to 192.168.1.100 send\n");
	}
	else 
	{
		tcp_sockets_show();
	}
}
Пример #23
0
void notifications__run(void) {
    unsigned long index = MAX_TCP_ENTRY;
    
    if (http_get_state < 1) {
        HTTPC_DEBUG("httpc: ARP lookup for notification server\n\r");
        unsigned int httpc__source_port = 2354;
        add_tcp_app(httpc__source_port, (void(*)(unsigned char))httpc_acknowledge);
        
        // Send ARP request
        if (arp_request(NOTIFICATIONS__SERVER_HOST)) {
            for(unsigned long a = 0;a < 2000000; a++) { asm("nop"); };
            
            tcp_port_open(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT), htons(httpc__source_port));
               
            unsigned char tmp_counter = 0;
            while ((index >= MAX_ARP_ENTRY) && (tcp_entry[index].app_status != 1)) {
                index = tcp_entry_search(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT));
                if (tmp_counter++ > 30) {
                    HTTPC_DEBUG("httpc: tcp entry not found!\r\n");
                    return;
                }
            }
             
            HTTPC_DEBUG("httpc: tcp entry found!\r\n");
            tcp_entry[index].first_ack = 1;
            ++http_get_state;
        }
        else {
            ++http_get_state;
        }
    }
    else if (http_get_state == 20000)  
    {
        HTTPC_DEBUG("httpc: sending HTTP request\r\n");
        index = tcp_entry_search(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT));
        memcpy_P(&eth_buffer[TCP_DATA_START], PUT_REQUEST, (sizeof(PUT_REQUEST)-1));
        tcp_entry[index].status =  ACK_FLAG | PSH_FLAG;
        create_new_tcp_packet((sizeof(PUT_REQUEST)-1), index);
        http_get_state = 20001;
    }
    else if (http_get_state < 20000) http_get_state++; // wait.. ugly
}
Пример #24
0
void vcc_connected(VCC *vcc)
{
    ENTRY *entry;

    diag(COMPONENT,DIAG_DEBUG,"connected VCC 0x%p",vcc);
    if (!vcc->connecting)
	diag(COMPONENT,DIAG_FATAL,"non-connecting VCC connected");
    vcc->connecting = 0;
    if (vcc->entry->flags & ATF_ARPSRV)
	for (entry = vcc->entry->itf->table; entry; entry = entry->next)
	    if (entry->state == as_resolv) {
		START_TIMER(entry,REPLY);
		arp_request(entry->itf,entry->ip);
	    }
    inarp_request(vcc->entry);
    if (vcc->entry->state == as_valid)
	if (set_ip(vcc->fd,vcc->entry->ip) < 0) {
	    diag(COMPONENT,DIAG_ERROR,"can't set IP (%s)",strerror(errno));
	    disconnect_vcc(vcc);
	}
}
Пример #25
0
/**
 * \ingroup tcpcmd
 * \b PING-Befehl Sende "Ping" an angegebene Adresse
 */
int16_t command_ping (char *outbuffer)
{
	uint32_t var = 0;

	if (getLong(&var))
	{
		unsigned long dest_ip=0;

		for (uint8_t i=0; i<4; ++i) {
			dest_ip += (var<<(8*i));
			if (!getLong(&var))
				break;
		}

		//ARP Request senden
		arp_request (dest_ip);
		
		//ICMP-Nachricht Type=8 Code=0: Echo-Anfrage
		//TODO: Sequenznummer, Identifier 
		icmp_send(dest_ip,0x08,0x00,1,1);
	}
	return 0;
}
Пример #26
0
void handle_timer() {
    time_t crnt = time(NULL);
    struct sr_arp_request *reqs = sr_handle->cache->requests;
    struct sr_arp_request *prev = NULL;

    while (reqs) {
        if (difftime(crnt, reqs->time) > 1) {
        	if(reqs->repeated > MAX_REPEAT) {
        		printf("IP Unreachable\n");
            	ip_unreachable(sr_handle, reqs->messages->packet, reqs->messages->length, reqs->messages->interface);
            	
	            if (!prev) {
	                sr_handle->cache->requests = reqs->next;
	                free(reqs);
	                reqs = reqs->next;
	            } else {
	                prev->next = reqs->next;
	                free(reqs);
	                reqs = prev->next;
	            }
	        }
	        
	        else { // resend message
	        	printf("Resending ARP\n");
		        arp_request(sr_handle, reqs->ip, next_hop(sr_handle, reqs->ip));
		        reqs->repeated++;
		        reqs->time = time(NULL);
	        }
        } 
        
        else {
            prev = reqs;
            reqs = reqs->next;
        }
    }
}
Пример #27
0
int arp_timeout_check(void)
{
	ulong t;

	if (!net_arp_wait_packet_ip.s_addr)
		return 0;

	t = get_timer(0);

	/* check for arp timeout */
	if ((t - arp_wait_timer_start) > ARP_TIMEOUT) {
		arp_wait_try++;

		if (arp_wait_try >= ARP_TIMEOUT_COUNT) {
			puts("\nARP Retry count exceeded; starting again\n");
			arp_wait_try = 0;
			net_set_state(NETLOOP_FAIL);
		} else {
			arp_wait_timer_start = t;
			arp_request();
		}
	}
	return 1;
}
Пример #28
0
//=====================================================================================
//
//	* Function : request
//	* Description 
//		target_ip로 ARP request packet을 보내는 스레드의 콜백함수 
//
//=====================================================================================
DWORD WINAPI request(LPVOID arg)
{
	arp_request(target_ip);

	return 0;
}
Пример #29
0
int main(int argc, char *argv[]) {

	char pcap_buff[PCAP_ERRBUF_SIZE];	// Error buffer used by pcap
	size_t userin_len = 0;
	ssize_t n;
	int ret;
	struct pcap_pkthdr *packet_hdr = NULL;
	const u_char *packet_data = NULL;
	char *userin = NULL;
	char got_response;

	init(argc, argv, pcap_buff);

	while (!quit) {

		// read user input
		printf("Enter next IP address: ");
		// getline malloc's userin, so free it each time
		if (userin)
			free(userin);
		userin_len = 0;
		n = getline(&userin, &userin_len, stdin);
		if (n < 0) {
			if (errno == EINTR)
				break;
			perror("getline failed");
			exit(EXIT_FAILURE);
		}
		// remove new line
		userin[n-1] = '\0';

		if (0 == strcmp("", userin))
			continue;

		// send an ARP request
		n = arp_request(pcap_handle, userin);
		if (n < 0) {
			printf("ARP request failed\n");
			continue;
		}

		// wait for a response
		got_response = 0;

		// look for a response
		while (!quit) {
			// receive some data
			alarm(RESP_TIMEOUT);
			ret = pcap_next_ex(pcap_handle, &packet_hdr,
					&packet_data);
			if (ret < 0)
				break;  // timeout or error

			// if the response is ours,
			// display the result and break.
			if (check_response(packet_hdr, packet_data)) {
				got_response = 1;
				break;
			}
		}
		alarm(0);  // disable timeout
		if (!got_response) {
			printf("MAC: Lookup failed\n");		
		}
	}

	if (userin)
		free(userin);

	if (pcap_handle)
		pcap_close(pcap_handle);

	return 0;
}
Пример #30
0
//----------------------------------------------------------------------------
//send query to DNS server
void dns_query(char *name)
{
    unsigned char   *nptr;
    unsigned char   n;
    unsigned int    byte_count;
    unsigned long   tmp_ip;

    tmp_ip = (*(unsigned long*)&dns_server_ip[0]);

    if (arp_request(tmp_ip) == 1) // if DNS server is answering to ARP
    {  
        nptr = &eth_buffer[UDP_DATA_START];
        *nptr++ = 0x12; //ID h
        *nptr++ = 0x34; //ID l
        *nptr++ = 0x01; //Flags h  FLAG_RD ->Standard query
        *nptr++ = 0x00; //Flags l
        *nptr++ = 0x00; //QDCOUNT h
        *nptr++ = 0x01; //QDCOUNT l
        *nptr++ = 0x00; //ANCOUNT h
        *nptr++ = 0x00; //ANCOUNT l
        *nptr++ = 0x00; //NSCOUNT h
        *nptr++ = 0x00; //NSCOUNT l
        *nptr++ = 0x00; //ARCOUNT h
        *nptr++ = 0x00; //ARCOUNT l
   
        byte_count = 12;
        --name;
        /* Convert hostname to query format. */
        do 
        {
            ++name;
            nptr = &eth_buffer[UDP_DATA_START+byte_count];   //remember the first byte
            byte_count++;
            for(n = 0; *name != '.' && *name != 0; ++name)  //copy the name
            {
                eth_buffer[UDP_DATA_START+byte_count] = *name;
                byte_count++;
                n++;
            }
            *nptr = n;       //store the length in the first byte
        }
        while(*name != 0); //until name string is finished 
   
        //end of query:
        eth_buffer[UDP_DATA_START+byte_count] = 0; //zero string
        byte_count++;
    
        eth_buffer[UDP_DATA_START+byte_count] = 0; //2 bytes QTYPE 1=a host address
        byte_count++;
        eth_buffer[UDP_DATA_START+byte_count] = 1; //
        byte_count++;
    
        eth_buffer[UDP_DATA_START+byte_count] = 0; //2 bytes QCLASS 1=Internet
        byte_count++;
        eth_buffer[UDP_DATA_START+byte_count] = 1; //
        byte_count++;
   
        create_new_udp_packet(byte_count,DNS_CLIENT_PORT,DNS_SERVER_PORT,tmp_ip);
        dns_state = DNS_STATE_REQ_SENT;
        return;
    }
    dns_state = DNS_STATE_REQ_ERR;
    DNS_DEBUG("No DNS server!!\r\n");
}