Пример #1
0
int
find_if_client_local(struct sockaddr_in servaddr, struct sockaddr_in clientaddr, interface_info_t *ii, size_t interface_info_len, struct sockaddr_in recv_netmask)
{
  // return 1 -> loopback;
  // return 2 -> local;
  // else return 3.

  int i;
  struct in_addr client_ip;
  //struct sockaddr_in netmask;
  struct in_addr temp, netmask, longest_prefix;
  char str[INET_ADDRSTRLEN];

  inet_pton(AF_INET, "127.0.0.1", &temp);

  if (compare_ips(servaddr.sin_addr, temp) == 1) {
    return 1;
  }

  // Not on same host, check if they are on same subnet now.

  netmask = recv_netmask.sin_addr;
  if ((servaddr.sin_addr.s_addr & netmask.s_addr) == (clientaddr.sin_addr.s_addr & netmask.s_addr))
    return 2;

  return 3;
}
Пример #2
0
void
filter_nodes(ContainerRoot* model, int children_count, char* childrenIP[], const char* deployUnitType, list_t* r)
{
	struct SuperData superData = { .l = r, .requiredDU=deployUnitType };
	// print address of each node
	hashmap_iterate(model->nodes, printNodes , &superData);

	// filter out elements if they are not in the list of children results
	list_t nodes = *r;
	LIST(tmp);
	list_init(tmp);
	for (int i = 0 ; i < children_count ; i++) {
		struct NodeItem * found = NULL;
		for (struct NodeItem* p =list_head(nodes); p != NULL ; p = list_item_next(p)) {
			if (compare_ips(childrenIP[i], p->nodeIp)) {
				found = p;
			}
		}
		if (found) { 
			list_remove(nodes, found);
			list_push(tmp, found);
		}
	}
	// now just empty the previous list
	while (list_length(nodes) > 0) {
		void* item = list_pop(nodes);
		free(item);
	}

	// now add elements to the empty list
	while (list_length(tmp) > 0) {
		void* item = list_pop(tmp);
		list_push(nodes, item);
	}
}
Пример #3
0
int main(void){
	init_uart();
	
	uint16_t packet_length, rxstat;
	
	uart_puts("beginning startup procedure\r\n");    
	/*ENC Initialisieren*/
	enc28j60Init();
	uart_puts("initialization finished\r\n");
	//Mac Adresse setzen(stack.h, dort wird auch die Ip festgelegt)
	nicSetMacAddress(mymac);
	uart_puts("mac address set\r\n");
	/*	Leds konfigurieren
		LEDA : Link status
		LEDB : Receive activity
		Led Settings : enc28j60 datasheet, page 11*/
	
	enc28j60PhyWrite(0x14,0b0000010000100000);
	
	/*	Leds konfigurieren
		LEDA : Link status
		LEDB : Blink Fast
		Led Settings : enc28j60 datasheet, page 11
		Auskommentieren, wenn mans lieber blinken sieht ;-)		*/
	
	//enc28j60PhyWrite(0x14,0b0000010000100000);

	
	while(1) {
		// Buffer des Enc's abhohlen :-)
		packet_length = enc28j60PacketReceive(BUFFER_SIZE, buffer, &rxstat);

		// Wenn ein Packet angekommen ist, ist packet_length =! 0
		if(packet_length) {
			packet_length -= 4;
			struct ETH_frame *frame = (struct ETH_frame *) buffer;
			frame->type_length = ntohs(frame->type_length);
			// arping uses unicast after the first by default, but we don't care because performance
			if(/*(*/rxstat&BROADCAST_BIT /*|| compare_macs(frame->destMac, (uint8_t *) mymac))*/ && frame->type_length == TYPE_ARP) {
				struct ARP_packet *arp_pkt = (struct ARP_packet *) frame->payload;
				if(compare_ips(arp_pkt->destIp, (uint8_t *) myip)) {
					arp(packet_length, buffer);
				}
				continue;
			}

			if(compare_macs(frame->destMac, (uint8_t *) mymac)) {
				if(frame->type_length == TYPE_IP4) {
					struct IP_segment *ip = (struct IP_segment *) frame->payload;
					if(ip->protocol == TYPE_ICMP) {
						icmp(packet_length, buffer);
						continue;
					} else if(ip->protocol == TYPE_UDP) {
						struct UDP_packet *pkt = (struct UDP_packet *) ip->payload;
						pkt->destPort = pkt->destPort;
						pkt->sourcePort = pkt->sourcePort;

						if(pkt->destPort == ntohs(7)) {
							udp(htons(pkt->length), buffer);
							continue;
						}

						if(pkt->destPort == ntohs(85) && compare(pkt->data, "test")) {
							printinbuffer(pkt->data, "Test erfolgreich!", TERMINATE);
							udp(18, buffer);
							continue;
						}

						if(pkt->destPort == ntohs(86)) {
							uart_puts((char*) pkt->data);
							uart_puts("\r\n");
							continue;
						}
					} else if(ip->protocol == TYPE_TCP) {
						uart_puts("received tcp package!\r\n");
						#if DEBUG
						hexdump(ip, 256);
						#endif
						struct TCP_segment *tcp = (struct TCP_segment *) ip->payload;
						if(tcp->sourcePort == ntohs(7)) {

						}
					}
				}
			}
		}
	}
	
	return 1;
}