int get_network_connections()

in source/linux/network.c [270:327]


int get_network_connections(
    struct aws_array_list *net_conns,
    struct aws_iotdevice_network_ifconfig *ifconfig,
    struct aws_allocator *allocator) {
    struct aws_byte_buf net_tcp;
    AWS_ZERO_STRUCT(net_tcp);
    struct aws_byte_buf net_udp;
    AWS_ZERO_STRUCT(net_udp);
    int return_code = AWS_OP_ERR;

    if (read_proc_net_from_file(&net_tcp, allocator, s_proc_net_tcp_size_hint, "/proc/net/tcp")) {
        AWS_LOGF_ERROR(
            AWS_LS_IOTDEVICE_NETWORK_CONFIG,
            "id=%p: Failed to retrieve network configuration: %s",
            (void *)ifconfig,
            aws_error_name(aws_last_error()));
        goto cleanup;
    }
    s_proc_net_tcp_size_hint = net_tcp.len * PROC_NET_HINT_FACTOR;

    if (read_proc_net_from_file(&net_udp, allocator, s_proc_net_udp_size_hint, "/proc/net/udp")) {
        AWS_LOGF_ERROR(
            AWS_LS_IOTDEVICE_NETWORK_CONFIG,
            "id=%p: Failed to retrieve network configuration: %s",
            (void *)ifconfig,
            aws_error_name(aws_last_error()));
        goto cleanup;
    }
    s_proc_net_udp_size_hint = net_udp.len * PROC_NET_HINT_FACTOR;

    struct aws_byte_cursor net_tcp_cursor = aws_byte_cursor_from_buf(&net_tcp);
    if (get_net_connections_from_proc_buf(net_conns, allocator, &net_tcp_cursor, ifconfig, AWS_IDNP_TCP)) {
        AWS_LOGF_ERROR(
            AWS_LS_IOTDEVICE_NETWORK_CONFIG,
            "id=%p: Failed to parse network connections from /proc/net/tcp",
            (void *)ifconfig);
    }

    struct aws_byte_cursor net_udp_cursor = aws_byte_cursor_from_buf(&net_udp);
    if (get_net_connections_from_proc_buf(net_conns, allocator, &net_udp_cursor, ifconfig, AWS_IDNP_UDP)) {
        AWS_LOGF_ERROR(
            AWS_LS_IOTDEVICE_NETWORK_CONFIG,
            "id=%p: Failed to parse network connections from /proc/net/udp",
            (void *)ifconfig);
    }

    return_code = AWS_OP_SUCCESS;

cleanup:
    if (net_tcp.allocator) {
        aws_byte_buf_clean_up(&net_tcp);
    }
    if (net_udp.allocator) {
        aws_byte_buf_clean_up(&net_udp);
    }

    return return_code;
}