diff --git a/bin/system_info/print_system_info.c b/bin/system_info/print_system_info.c index c29877086..3ceec31cd 100644 --- a/bin/system_info/print_system_info.c +++ b/bin/system_info/print_system_info.c @@ -33,10 +33,27 @@ int main(void) { size_t numa_nodes = aws_system_environment_get_cpu_group_count(env); if (numa_nodes > 1) { - fprintf(stdout, " 'numa architecture': 'true',\n"); + fprintf(stdout, " 'numa architecture': true,\n"); fprintf(stdout, " 'number of numa nodes': '%lu'\n", (unsigned long)numa_nodes); } else { - fprintf(stdout, " 'numa architecture': 'false'\n"); + fprintf(stdout, " 'numa architecture': false\n"); + } + size_t nic_count = aws_system_environment_get_network_card_count(env); + fprintf(stdout, " 'network_card_count': %lu\n", (unsigned long)nic_count); + + if (nic_count > 0) { + fprintf(stdout, " 'network_cards: [\n"); + + const struct aws_string **nic_array = aws_system_environment_get_network_cards(env); + for (size_t i = 0; i < nic_count; ++i) { + fprintf(stdout, " '%s'", aws_string_c_str(nic_array[i])); + + if (i != nic_count - 1) { + fprintf(stdout, ","); + } + fprintf(stdout, "\n"); + } + fprintf(stdout, " ]\n"); } fprintf(stdout, "}\n"); diff --git a/include/aws/common/private/system_info_priv.h b/include/aws/common/private/system_info_priv.h index 27b1d4ad1..b1cc2e7f9 100644 --- a/include/aws/common/private/system_info_priv.h +++ b/include/aws/common/private/system_info_priv.h @@ -14,6 +14,7 @@ struct aws_system_environment { struct aws_ref_count ref_count; struct aws_byte_buf virtualization_vendor; struct aws_byte_buf product_name; + struct aws_array_list str_list_network_cards; enum aws_platform_os os; size_t cpu_count; size_t cpu_group_count; diff --git a/include/aws/common/system_info.h b/include/aws/common/system_info.h index 91da41f9d..7203a4fd2 100644 --- a/include/aws/common/system_info.h +++ b/include/aws/common/system_info.h @@ -58,6 +58,12 @@ struct aws_byte_cursor aws_system_environment_get_virtualization_vendor(const st AWS_COMMON_API struct aws_byte_cursor aws_system_environment_get_virtualization_product_name(const struct aws_system_environment *env); +AWS_COMMON_API +size_t aws_system_environment_get_network_card_count(const struct aws_system_environment *env); + +AWS_COMMON_API +const struct aws_string **aws_system_environment_get_network_cards(const struct aws_system_environment *env); + /** * Returns the number of processors for the specified compute environment. */ diff --git a/source/linux/system_info.c b/source/linux/system_info.c index 2d9c5a120..65b241af6 100644 --- a/source/linux/system_info.c +++ b/source/linux/system_info.c @@ -5,6 +5,12 @@ #include #include +#include +#include +#include +#include +#include + int aws_system_environment_load_platform_impl(struct aws_system_environment *env) { /* provide size_hint when reading "special files", since some platforms mis-report these files' size as 4KB */ aws_byte_buf_init_from_file_with_size_hint( @@ -15,10 +21,35 @@ int aws_system_environment_load_platform_impl(struct aws_system_environment *env aws_byte_buf_init_from_file_with_size_hint( &env->product_name, env->allocator, "/sys/devices/virtual/dmi/id/product_name", 32 /*size_hint*/); + struct ifaddrs *addrs; + struct ifaddrs *iterator; + iterator = addrs; + + getifaddrs(&addrs); + + while(iterator) { + if (iterator->ifa_addr && iterator->ifa_addr->sa_family == AF_PACKET) { + struct aws_string *device_name = aws_string_new_from_c_str(env->allocator, iterator->ifa_name); + aws_array_list_push_back(&env->str_list_network_cards, &device_name); + } + } + + if (addrs) { + freeifaddrs(addrs); + } + return AWS_OP_SUCCESS; } void aws_system_environment_destroy_platform_impl(struct aws_system_environment *env) { + size_t length = aws_array_list_length(&env->str_list_network_cards); + + for (size_t i = 0; i < length; ++i) { + struct aws_string *device_name = NULL; + aws_array_list_get_at(&env->str_list_network_cards, &device_name, i); + aws_string_destroy(device_name); + } + aws_byte_buf_clean_up(&env->virtualization_vendor); aws_byte_buf_clean_up(&env->product_name); } diff --git a/source/system_info.c b/source/system_info.c index 4b721f63a..3f33acd5b 100644 --- a/source/system_info.c +++ b/source/system_info.c @@ -11,6 +11,7 @@ void s_destroy_env(void *arg) { if (env) { aws_system_environment_destroy_platform_impl(env); + aws_array_list_clean_up(&env->str_list_network_cards); aws_mem_release(env->allocator, env); } } @@ -20,6 +21,8 @@ struct aws_system_environment *aws_system_environment_load(struct aws_allocator env->allocator = allocator; aws_ref_count_init(&env->ref_count, env, s_destroy_env); + aws_array_list_init_dynamic(&env->str_list_network_cards, env->allocator, 2, sizeof(struct aws_string *)); + if (aws_system_environment_load_platform_impl(env)) { AWS_LOGF_ERROR( AWS_LS_COMMON_GENERAL, @@ -74,7 +77,15 @@ size_t aws_system_environment_get_processor_count(struct aws_system_environment return env->cpu_count; } -AWS_COMMON_API size_t aws_system_environment_get_cpu_group_count(const struct aws_system_environment *env) { return env->cpu_group_count; } + +size_t aws_system_environment_get_network_card_count(const struct aws_system_environment *env) { + return aws_array_list_length(&env->str_list_network_cards); +} + + +const struct aws_string **aws_system_environment_get_network_cards(const struct aws_system_environment *env) { + return env->str_list_network_cards.data; +}