Exemplo n.º 1
0
      /** @brief Trows exceptions that reflect OpenCL error codes */
      static void raise_exception(cl_int err)
      {
        switch (err)
        {
          case CL_DEVICE_NOT_FOUND:               throw device_not_found();
          case CL_DEVICE_NOT_AVAILABLE:           throw device_not_available();
          case CL_COMPILER_NOT_AVAILABLE:         throw compiler_not_available();
          case CL_MEM_OBJECT_ALLOCATION_FAILURE:  throw mem_object_allocation_failure();
          case CL_OUT_OF_RESOURCES:               throw out_of_resources();
          case CL_OUT_OF_HOST_MEMORY:             throw out_of_host_memory();
          case CL_PROFILING_INFO_NOT_AVAILABLE:   throw profiling_info_not_available();
          case CL_MEM_COPY_OVERLAP:               throw mem_copy_overlap();
          case CL_IMAGE_FORMAT_MISMATCH:          throw image_format_mismatch();
          case CL_IMAGE_FORMAT_NOT_SUPPORTED:     throw image_format_not_supported();
          case CL_BUILD_PROGRAM_FAILURE:          throw build_program_failure();
          case CL_MAP_FAILURE:                    throw map_failure();

          case CL_INVALID_VALUE:                  throw invalid_value();
          case CL_INVALID_DEVICE_TYPE:            throw invalid_device_type();
          case CL_INVALID_PLATFORM:               throw invalid_platform();
          case CL_INVALID_DEVICE:                 throw invalid_device();
          case CL_INVALID_CONTEXT:                throw invalid_context();
          case CL_INVALID_QUEUE_PROPERTIES:       throw invalid_queue_properties();
          case CL_INVALID_COMMAND_QUEUE:          throw invalid_command_queue();
          case CL_INVALID_HOST_PTR:               throw invalid_host_ptr();
          case CL_INVALID_MEM_OBJECT:             throw invalid_mem_object();
          case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: throw invalid_image_format_descriptor();
          case CL_INVALID_IMAGE_SIZE:             throw invalid_image_size();
          case CL_INVALID_SAMPLER:                throw invalid_sampler();
          case CL_INVALID_BINARY:                 throw invalid_binary();
          case CL_INVALID_BUILD_OPTIONS:          throw invalid_build_options();
          case CL_INVALID_PROGRAM:                throw invalid_program();
          case CL_INVALID_PROGRAM_EXECUTABLE:     throw invalid_program_executable();
          case CL_INVALID_KERNEL_NAME:            throw invalid_kernel_name();
          case CL_INVALID_KERNEL_DEFINITION:      throw invalid_kernel_definition();
          case CL_INVALID_KERNEL:                 throw invalid_kernel();
          case CL_INVALID_ARG_INDEX:              throw invalid_arg_index();
          case CL_INVALID_ARG_VALUE:              throw invalid_arg_value();
          case CL_INVALID_ARG_SIZE:               throw invalid_arg_size();
          case CL_INVALID_KERNEL_ARGS:            throw invalid_kernel_args();
          case CL_INVALID_WORK_DIMENSION:         throw invalid_work_dimension();
          case CL_INVALID_WORK_GROUP_SIZE:        throw invalid_work_group_size();
          case CL_INVALID_WORK_ITEM_SIZE:         throw invalid_work_item_size();
          case CL_INVALID_GLOBAL_OFFSET:          throw invalid_global_offset();
          case CL_INVALID_EVENT_WAIT_LIST:        throw invalid_event_wait_list();
          case CL_INVALID_EVENT:                  throw invalid_event();
          case CL_INVALID_OPERATION:              throw invalid_operation();
          case CL_INVALID_GL_OBJECT:              throw invalid_gl_object();
          case CL_INVALID_BUFFER_SIZE:            throw invalid_buffer_size();
          case CL_INVALID_MIP_LEVEL:              throw invalid_mip_level();
          case CL_INVALID_GLOBAL_WORK_SIZE:       throw invalid_global_work_size();
      #ifdef CL_INVALID_PROPERTY
    case CL_INVALID_PROPERTY:               throw invalid_property();
      #endif
          //  return "CL_INVALID_GLOBAL_WORK_SIZE";

          default: throw unknown_error();
        }

      } //getErrorString
Exemplo n.º 2
0
int setup_firewall(firewall_t* fwall, char* in, char* out, char* errbuf) {
	FILE *settings;
	settings = fopen("settings.config", "r");

	if (settings == NULL) {
		return 0;
	}
	
	int read = 0;
	char buff[1024];
	while (fgets(buff, 1024, settings) != NULL) {
		int str_tam = strlen(buff);
  	if (read == 0) {
  		str_to_mac(buff, fwall->virtual_mac); 	
  	} else if (read == 1) {
  		str_to_mac(buff, fwall->firewall_mac);
  	} else if (read == 2) {
  		str_to_mac(buff, fwall->switch_mac);
  	} else if (read == 3) {
  		str_to_mac(buff, fwall->router_mac);
  	} else if (read == 4) {
  		fwall->virtual_ip_str = (char*) malloc(str_tam+1);
  		memcpy(fwall->virtual_ip_str, buff, str_tam);
  		fwall->virtual_ip_str[str_tam] = 0;
  		str_to_ip(fwall->virtual_ip_str, fwall->virtual_ip_bin);		
  	} else if (read == 5) {
  		fwall->firewall_ip_str = (char*) malloc(str_tam+1);
  		memcpy(fwall->firewall_ip_str, buff, str_tam);
  		fwall->firewall_ip_str[str_tam] = 0;
  		str_to_ip(fwall->firewall_ip_str, fwall->firewall_ip_bin);
  	} else if (read == 6) {
  		fwall->switch_ip_str = (char*) malloc(str_tam+1);
  		memcpy(fwall->switch_ip_str, buff, str_tam);
  		fwall->switch_ip_str[str_tam] = 0;
  		str_to_ip(fwall->switch_ip_str, fwall->switch_ip_bin);
  	}
  	read++;
		if (read == MAX_INPUT_LINES)
			break;
	}
	
	if (read != MAX_INPUT_LINES) {
		fclose(settings);
		return 0;
	}
	
	int sz = strlen(in);
	fwall->dev_name_in = (char*) malloc(sz);
	memcpy(fwall->dev_name_in, in, sz);
	sz = strlen(out);
	fwall->dev_name_out = (char*) malloc(sz);
	memcpy(fwall->dev_name_out, out, sz);
	
	fwall->pcap_in_timeout = IN_TIMEOUT;
	fwall->pcap_out_timeout = OUT_TIMEOUT;
	
	NEXT_TCP_PORT = HIGH_PORT;
  NEXT_UDP_PORT = HIGH_PORT;
	
	ONLINE = 1;
	int i;
	for (i=0;i<strlen(fwall->dev_name_in);i++)
		if (fwall->dev_name_in[i] == '.') ONLINE = 0;
	
	if (ONLINE) {	
		if (device_not_found(in, errbuf)) {
			printf("Device %s not found!\n",in);
			return 0;
		}	
		if (device_not_found(out, errbuf)) {
			printf("Device %s not found!\n",out);
			return 0;
		}	
		
		fwall->pcap_in = pcap_open_live(fwall->dev_name_in, BUFSIZ, 0, fwall->pcap_in_timeout, errbuf);	
		if (fwall->pcap_in == NULL) {
			printf("Error pcap in: %s\n", errbuf);
			return 0;
		}
		if (pcap_datalink(fwall->pcap_in) != 1) {
			printf("Not ethernet data-link pcap in!\n");
			return 0;
		}
	
		fwall->pcap_out = pcap_open_live(fwall->dev_name_out, BUFSIZ, 0, fwall->pcap_out_timeout, errbuf);	
		if (fwall->pcap_out == NULL) {
			printf("Error pcap out: %s\n", errbuf);
			return 0;
		}
		if (pcap_datalink(fwall->pcap_out) != 1) {
			printf("Not ethernet data-link pcap out!\n");
			return 0;
		}
	} else {
		fwall->pcap_in = pcap_open_offline(fwall->dev_name_in, errbuf);	
		if (fwall->pcap_in == NULL) {
			printf("Error pcap in: %s\n", errbuf);
			return 0;
		}
		if (pcap_datalink(fwall->pcap_in) != 1) {
			printf("Not ethernet data-link pcap in!\n");
			return 0;
		}
	
		fwall->pcap_out = pcap_open_offline(fwall->dev_name_out, errbuf);	
		if (fwall->pcap_out == NULL) {
			printf("Error pcap out: %s\n", errbuf);
			return 0;
		}
		if (pcap_datalink(fwall->pcap_out) != 1) {
			printf("Not ethernet data-link pcap out!\n");
			return 0;
		}
	}
	
	fclose(settings);
	return 1;
}