コード例 #1
0
ファイル: ethernet.c プロジェクト: vonfritz/owl
int parse_ethernet_config(case_t *eth_case, struct ethernet *eth)
{
	int argc, i;
	char argv[3][20];
	char *index = eth_case->nod_path;
	
	strncpy(eth->interface, eth_case->dev_name, 20);
	argc = parse_to_array(eth_case->nod_path, argv);
	if (argc < 0)
	{
		return -1;
	}
	for (i = 0; i < argc; i++)
	{
		char flag = argv[i][0];
		switch (flag)
		{
			case 'i':
				strncpy(eth->ip, &argv[i][1], 20);
				break;
			case 'm':
				strncpy(eth->netmask, &argv[i][1], 20);
				break;
			case 'p':
				strncpy(eth->ping, &argv[i][1], 20);
				break;
			default:
				break;
		}
	}
	if (strcmp(eth->ping, "") == 0)
	{
		strcpy(eth->ping, eth->ip);
	}
	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: shrenikjain38/ftutil
void server_query_handler (int sock, int connection, struct sockaddr_in server_addr, struct sockaddr_in client_addr) {
    char *argument_list[1000];
    parse_to_array(server_receive_buffer, argument_list);
    int len;

    for (len = 0; argument_list[len]; len++)
        ;

    if (strcmp(argument_list[0], "PING") == 0) {
        PING_handler(argument_list, len, sock, connection, client_addr);

        if (strcmp(connection_type, "tcp") == 0) {
            send(connection, server_send_buffer, 1024, 0);
        } else {
            if (strcmp(connection_type, "udp") == 0) {
                sendto(sock, server_send_buffer, 1024, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
            }
        }
        strcpy(server_send_buffer, "MAGIC-STRING-SPRINKLEBERRY-MUFFIN");
        if (strcmp(connection_type, "tcp") == 0) {
            send(connection, server_send_buffer, 1024, 0);
        } else {
            if (strcmp(connection_type, "udp") == 0) {
                sendto(sock, server_send_buffer, 1024, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
            }
        }

        return;
    }

    if (strcmp(argument_list[0], "IndexGet") == 0) {
        if (len < 2) {
            logger_error_server("TOO FEW ARGUMENTS TO INDEXGET");
            strcpy(server_send_buffer, "TOO FEW ARGUMENTS TO INDEXGET.\nUSAGE: IndexGet <flag> [<arg1> <arg2>]");
        }
        else if ( (strcmp(argument_list[1], "--shortlist") == 0 && len != 4) || (strcmp(argument_list[1], "--regex") == 0 && len != 3) || (strcmp(argument_list[1], "--longlist") == 0 && len != 2) ) {
            logger_error_server("INVALID FORMAT. PLEASE CHECK SYNTAX OF INDEXGET");
            strcpy(server_send_buffer, "INVALID FORMAT. PLEASE CHECK SYNTAX OF INDEXGET\nUSAGE: IndexGet <flag> [<arg1> <arg2>]");
        }
        else
            IndexGet_handler(argument_list, len, sock, connection, client_addr);

        strcat(server_send_buffer, "MAGIC-STRING-SPRINKLEBERRY-MUFFIN");

        if (strcmp(connection_type, "tcp") == 0) {
            send(connection, server_send_buffer, 1024, 0);
        } else {
            if (strcmp(connection_type, "udp") == 0) {
                sendto(sock, server_send_buffer, 1024, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
            }
        }

        return;
    }

    if (strcmp(argument_list[0], "FileHash") == 0) {
        FileHash_handler(argument_list, len, sock, connection, client_addr);

        strcat(server_send_buffer, "MAGIC-STRING-SPRINKLEBERRY-MUFFIN");

        if (strcmp(connection_type, "tcp") == 0) {
            send(connection, server_send_buffer, 1024, 0);
        } else {
            if (strcmp(connection_type, "udp") == 0) {
                sendto(sock, server_send_buffer, 1024, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
            }
        }

        return;
    }

    if (strcmp(argument_list[0], "FileUpload") == 0) {
        FileUpload_handler(argument_list, len, sock, connection, client_addr);

        strcat(server_send_buffer, "MAGIC-STRING-SPRINKLEBERRY-MUFFIN");

        if (strcmp(connection_type, "tcp") == 0) {
            send(connection, server_send_buffer, 1024, 0);
        } else {
            if (strcmp(connection_type, "udp") == 0) {
                sendto(sock, server_send_buffer, 1024, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
            }
        }

        return;
    }

    if (strcmp(argument_list[0], "FileDownload") == 0) {
        FileDownload_handler(argument_list, len, sock, connection, client_addr);

        strcat(server_send_buffer, "MAGIC-STRING-SPRINKLEBERRY-MUFFIN");

        if (strcmp(connection_type, "tcp") == 0) {
            send(connection, server_send_buffer, 1024, 0);
        } else {
            if (strcmp(connection_type, "udp") == 0) {
                sendto(sock, server_send_buffer, 1024, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
            }
        }

        return;
    }

    else
        strcpy(server_send_buffer, "INVALID COMMAND.\nList of Allowed Commands is:\n1) IndexGet\n2) FileHash\n3) FileDownload\n4) FileUpload\n5) exit");

    strcat(server_send_buffer, "MAGIC-STRING-SPRINKLEBERRY-MUFFIN");

    if (strcmp(connection_type, "tcp") == 0) {
        send(connection, server_send_buffer, 1024, 0);
    } else {
        if (strcmp(connection_type, "udp") == 0) {
            sendto(sock, server_send_buffer, 1024, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
        }
    }

    logger_error_server("UNKNOWN COMMAND");
    logger_warn_server("IGNORING UNKNOWN COMMAND");
}