- snprint_ip_port(rem_addr, sizeof(rem_addr),
- (struct sockaddr *) &remaddr, rem_port,
- "tcp", flags&NETSTAT_NUMERIC);
+static int FAST_FUNC dir_act(const char *fileName,
+ struct stat *statbuf UNUSED_PARAM,
+ void *userData UNUSED_PARAM,
+ int depth)
+{
+ const char *pid;
+ char *pid_slash_progname;
+ char proc_pid_fname[sizeof("/proc/%u/cmdline") + sizeof(long)*3];
+ char cmdline_buf[512];
+ int n, len;
+
+ if (depth == 0) /* "/proc" itself */
+ return TRUE; /* continue looking one level below /proc */
+
+ pid = fileName + sizeof("/proc/")-1; /* point after "/proc/" */
+ if (!isdigit(pid[0])) /* skip /proc entries which aren't processes */
+ return SKIP;
+
+ len = snprintf(proc_pid_fname, sizeof(proc_pid_fname), "%s/cmdline", fileName);
+ n = open_read_close(proc_pid_fname, cmdline_buf, sizeof(cmdline_buf) - 1);
+ if (n < 0)
+ return FALSE;
+ cmdline_buf[n] = '\0';
+
+ /* go through all files in /proc/PID/fd and check whether they are sockets */
+ strcpy(proc_pid_fname + len - (sizeof("cmdline")-1), "fd");
+ pid_slash_progname = concat_path_file(pid, bb_basename(cmdline_buf)); /* "PID/argv0" */
+ n = recursive_action(proc_pid_fname,
+ ACTION_RECURSE | ACTION_QUIET,
+ add_to_prg_cache_if_socket,
+ NULL,
+ (void *)pid_slash_progname,
+ 0);
+ free(pid_slash_progname);
+
+ if (!n)
+ return FALSE; /* signal permissions error to caller */
+
+ return SKIP; /* caller should not recurse further into this dir */
+}