Exemplo n.º 1
0
int main(int argc, char *argv[]) {
    struct sockaddr_storage their_addr;
    socklen_t addr_size;
    int socket_fd, time_stamp, num_bytes = 1;
    char output_buffer[100000];
    struct timespec initial_time, current_time;
    int new_fd;
    int recv_len = 1;
    double current_minus_initial = 0;
    pid_t my_pid;
    FILE *input_csv = NULL;
    int frame_size = 0;

    my_pid = syscall(__NR_gettid);
    if(register_pid(my_pid) != 1) {
        perror("register pid failed");
        exit(1);
    }
    socket_fd = initialize_connection();
    input_csv = fopen(MSG_SIZES_FILENAME, "r");

    if(input_csv == NULL) {
        perror("fopen error");
        exit(1);
    }
    addr_size = sizeof their_addr;

    new_fd = accept(socket_fd, (struct sockaddr *)&their_addr, &addr_size);
    yield_pid(my_pid);
    clock_gettime(CLOCK_REALTIME, &initial_time);

    while(fscanf(input_csv, "%d\n", &frame_size) != EOL) {
        recv_len = recv(new_fd, &output_buffer, frame_size, MSG_WAITALL);
        clock_gettime(CLOCK_REALTIME, &current_time);
        current_minus_initial = (current_time.tv_sec - initial_time.tv_sec) * 1000.0;
        current_minus_initial += (current_time.tv_nsec - initial_time.tv_nsec) / 1000000.0;
        printf("%d at %f\n", recv_len, current_minus_initial);
        yield_pid(my_pid);
    }

    unregister_pid(my_pid);
    fclose(proc_file);
    close(socket_fd);
    return 0;
}
Exemplo n.º 2
0
int initialize_remote_connection(struct sockaddr_in* address)
{
    return initialize_connection(AF_INET, (struct sockaddr *) address, sizeof(*address));
}
Exemplo n.º 3
0
int initialize_local_connection(struct sockaddr_un* address)
{
    return initialize_connection(AF_UNIX, (struct sockaddr *) address, sizeof(*address));
}
Exemplo n.º 4
0
struct connection *initialize_connection_from_string(const char *connection_string)
{
	int i;
	const char *ch;
	struct connection *new_connection = NULL;

	if(connection_string == NULL)
	{
		goto out_fail;
	}
	
	new_connection = initialize_connection();
	
	if(new_connection == NULL)
	{
		goto out_fail;
	}
	
	/*First field has to be a path*/
	
	i = 0;
	ch = connection_string;

	while(*ch != FIELD_SEPARATOR && *ch != '\0')
	{
		new_connection->executable[i] = *ch;
		ch++;
		i++;
	
		/*Too big path, fail to whitelist*/

		if(i >= MAX_ABSOLUTE_EXEC_PATH)
		{
			goto out_fail;
		}
	}
	
	new_connection->executable[i] = '\0';

	/*Skip the field separator, if any*/

	if(*ch == FIELD_SEPARATOR)
	{
		ch++;
	}
		
	/*Case of next field being an ip address*/
	
	if(*ch == 'i')
	{	
		/*If the ip is IPv6, we will add square brackets in the beginning and in
		 *the end. This is done in order to make right comparison between ipv6 
		 *addresses. The inet_utils functions return ipv6 addresses within square 
		 *brackets.
		 */
		
		int ipv6 = looks_like_ipv6(ch);
	
		ch++;
		
		/*Skip '<', if any*/
		
		if(*ch == '<')
		{
			ch++;
		}
	
		i = 0;
		
		if(ipv6)
		{
			/*Add opening square bracket*/

			new_connection->ip[0] = '[';
			i++;
		}

		while(*ch != '>' && *ch != '\0' && *ch != FIELD_SEPARATOR)
		{
			new_connection->ip[i] = *ch;
			ch++;
			i++;

			/*Too big ip, fail to whitelist*/

			if(i >= INET6_ADDRSTRLEN + 1)
			{
				goto out_fail;
			}
		}

		if(ipv6)
		{
			/*Add closing square bracket*/

			new_connection->ip[i] = ']';
			i++;
		}

		new_connection->ip[i] = '\0';
		ch++;

		if(!looks_like_valid_ip(new_connection->ip))
		{
			goto out_fail;
		}

	}

	/*Skip the field separator, if any*/

	if(*ch == FIELD_SEPARATOR)
	{
		ch++;
	}

	/*Case of next field being a port number*/

	if(*ch == 'p')
	{
		int base = 1;
		const char *number_start;

		ch++;
	
		/*Skip '<', if any*/
		
		if(*ch == '<')
		{
			ch++;
		}

		number_start = ch;

		/*Go to end of number*/
		
		while(*ch != '>' && *ch != '\0' && *ch != FIELD_SEPARATOR)
		{
			ch++;
		}
		ch--;
		
		new_connection->port = 0;
		
		while(ch >= number_start)
		{
			new_connection->port += (*ch - '0') * base;
			base *= 10;
			ch--;
		}
		
		if(!valid_port_number(new_connection->port))
		{
			goto out_fail;
		}
	}

	return new_connection;

out_fail:
	destroy_connection(new_connection);

	return NULL;
}