Ejemplo n.º 1
0
void print_internal_socket(socket_internal_t *current_socket_internal)
{
    socket_t *current_socket = &current_socket_internal->socket_values;
    printf("\n--------------------------\n");
    printf("ID: %i, RECV PID: %i SEND PID: %i\n",
           current_socket_internal->socket_id, current_socket_internal->recv_pid,
           current_socket_internal->send_pid);
    print_socket(current_socket);
    printf("\n--------------------------\n");
}
Ejemplo n.º 2
0
//TODO : receive window size should be 65535 not 0 when established
void print_sockets() {

	socket_t *sock, *temp;
	//printf("\nSOCKETS----------------------------------------------\n");
	printf("\nSockets:\n");

	if (HASH_CNT(hh1,fd_list) == 0) {
		printf("There are no socktes currently\n");
		return;
	}
	HASH_ITER(hh1, fd_list, sock, temp){
		print_socket(sock);
	}
Ejemplo n.º 3
0
static int print_socket(const char* desc, int fd) {
        int r;
        SocketAddress addr = {
                .size = sizeof(union sockaddr_union),
                .type = SOCK_STREAM,
        };
        int family;

        r = getsockname(fd, &addr.sockaddr.sa, &addr.size);
        if (r < 0) {
                log_warning("Failed to query socket on fd:%d: %m", fd);
                return 0;
        }

        family = socket_address_family(&addr);
        switch(family) {
        case AF_INET:
        case AF_INET6: {
                char* _cleanup_free_ a = NULL;
                r = socket_address_print(&addr, &a);
                if (r < 0)
                        log_warning("socket_address_print(): %s", strerror(-r));
                else
                        log_info("%s %s address %s",
                                 desc,
                                 family == AF_INET ? "IP" : "IPv6",
                                 a);
                break;
        }
        default:
                log_warning("Connection with unknown family %d", family);
        }

        return 0;
}

static int open_sockets(int *epoll_fd, bool accept) {
        int n, fd;
        int count = 0;
        char **address;

        n = sd_listen_fds(true);
        if (n < 0) {
                log_error("Failed to read listening file descriptors from environment: %s",
                          strerror(-n));
                return n;
        }
        log_info("Received %d descriptors", n);

        for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
                log_debug("Received descriptor fd:%d", fd);
                print_socket("Listening on", fd);

                if (!arg_accept) {
                        int r = set_nocloexec(fd);
                        if (r < 0)
                                return r;
                }

                count ++;
        }

        /** Note: we leak some fd's on error here. I doesn't matter
         *  much, since the program will exit immediately anyway, but
         *  would be a pain to fix.
         */

        STRV_FOREACH(address, arg_listen) {
                log_info("Opening address %s", *address);

                fd = make_socket_fd(*address, SOCK_STREAM | (arg_accept*SOCK_CLOEXEC));
                if (fd < 0) {
                        log_error("Failed to open '%s': %s", *address, strerror(-fd));
                        return fd;
                }

                count ++;
        }
Ejemplo n.º 4
0
/****************************************************************************
 * Public Functions
 ****************************************************************************/
int cmd_netmon(int argc, char **argv)
{
	sq_queue_t q_data;
	sq_init(&q_data);
	int ret;

	if (argc == 1 || argc > 2) {
		print_help();
	} else if (!(strncmp(argv[1], "sock", strlen("sock") + 1))) {
		/* Get socket information: SIOCGETSOCK */
		ret = netlib_netmon_sock(&q_data);
		if (!ret) {
			/* Free sq_queue entry of netmon_sock in print_socket() */
			print_socket(&q_data);
		} else {
			printf("Failed to fetch socket info.\n");
		}
	} else if (!(strncmp(argv[1], "wifi", strlen("wifi") + 1))) {
#ifdef CONFIG_WIFI_MANAGER
		wifi_manager_stats_s stats;
		wifi_manager_info_s info;

		wifi_manager_result_e res = wifi_manager_get_stats(&stats);
		if (res != WIFI_MANAGER_SUCCESS) {
			printf("Get Wi-Fi Manager stats failed\n");
			return ERROR;
		}
		printf("\n=======================================================================\n");
		printf("CONN    CONNFAIL    DISCONN    RECONN    SCAN    SOFTAP    JOIN    LEFT\n");
		printf("%-8d%-12d%-11d%-10d", stats.connect, stats.connectfail, stats.disconnect, stats.reconnect);
		printf("%-8d%-10d%-8d%-8d\n", stats.scan, stats.softap, stats.joined, stats.left);
		printf("=======================================================================\n");

		printf("Connection INFO.\n");
		res = wifi_manager_get_info(&info);
		if (res != WIFI_MANAGER_SUCCESS) {
			printf("Get Wi-Fi Manager Connection info failed\n");
			return ERROR;
		}
		if (info.mode == SOFTAP_MODE) {
			if (info.status == CLIENT_CONNECTED) {
				printf("MODE: softap (client connected)\n");
			} else if (info.status == CLIENT_DISCONNECTED) {
				printf("MODE: softap (no client)\n");
			}
			printf("IP: %s\n", info.ip4_address);
			printf("SSID: %s\n", info.ssid);
			printf("MAC %02X:%02X:%02X:%02X:%02X:%02X\n", info.mac_address[0], info.mac_address[1], info.mac_address[2], info.mac_address[3], info.mac_address[4], info.mac_address[5]);
		} else if (info.mode == STA_MODE) {
			if (info.status == AP_CONNECTED) {
				printf("MODE: station (connected)\n");
				printf("IP: %s\n", info.ip4_address);
				printf("SSID: %s\n", info.ssid);
				printf("rssi: %d\n", info.rssi);
			} else if (info.status == AP_DISCONNECTED) {
				printf("MODE: station (disconnected)\n");
			}
			printf("MAC %02X:%02X:%02X:%02X:%02X:%02X\n", info.mac_address[0], info.mac_address[1], info.mac_address[2], info.mac_address[3], info.mac_address[4], info.mac_address[5]);
		} else {
			printf("STATE: NONE\n");
		}
		printf("=======================================================================\n");
#else
		printf("Wi-Fi Manager is not enabled\n");
#endif
	} else {
#ifdef CONFIG_NET_STATS
		struct netmon_netdev_stats stats = {{0,}, 0, 0, 0, 0};
		char *intf = NULL;
		/* Get network interface stats if exists: SIOCGDEVSTATS */
		intf = argv[1];
		strncpy(stats.devname, intf, IFNAMSIZ);
		stats.devname[IFNAMSIZ] = '\0';
		ret = netlib_netmon_devstats(&stats);
		if (!ret) {
			print_devstats(&stats);
		} else {
			printf("No device interface %s\n", intf);
			return ERROR;
		}
#else
		printf("No such an option\n");
#endif
	}

	return OK;
}