[PATCH] iphlpapi: Implement find_owning_pid() on FreeBSD.

Charles Davis cdavis5x at gmail.com
Mon Aug 19 13:07:26 CDT 2013


---
 configure.ac              |   21 ++++++++++++++++
 dlls/iphlpapi/Makefile.in |    2 +-
 dlls/iphlpapi/ipstats.c   |   59 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 958fa5f..0458206 100644
--- a/configure.ac
+++ b/configure.ac
@@ -491,6 +491,7 @@ AC_CHECK_HEADERS(\
 	sys/prctl.h \
 	sys/protosw.h \
 	sys/ptrace.h \
+	sys/queue.h \
 	sys/resource.h \
 	sys/scsiio.h \
 	sys/shm.h \
@@ -506,6 +507,7 @@ AC_CHECK_HEADERS(\
 	sys/timeout.h \
 	sys/times.h \
 	sys/uio.h \
+	sys/user.h \
 	sys/utsname.h \
 	sys/vm86.h \
 	sys/wait.h \
@@ -660,6 +662,17 @@ AC_CHECK_HEADERS([linux/videodev.h linux/videodev2.h libv4l1.h],,,
 #include <asm/types.h>
 #endif])
 
+AC_CHECK_HEADERS([libprocstat.h],,,
+[#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_QUEUE_H
+#include <sys/queue.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif])
+
 dnl **** Check for working dll ****
 
 AC_SUBST(DLLEXT,"")
@@ -1723,6 +1736,14 @@ then
                   AC_SUBST(LIBKSTAT,"-lkstat")])
 fi
 
+dnl **** Check for libprocstat ****
+if test "$ac_cv_header_libprocstat_h" = "yes"
+then
+    AC_CHECK_LIB(procstat,procstat_open_sysctl,
+                 [AC_DEFINE(HAVE_LIBPROCSTAT, 1, [Define to 1 if you have the `procstat' library (-lprocstat).])
+                  AC_SUBST(LIBPROCSTAT,"-lprocstat")])
+fi
+
 dnl **** Check for libodbc ****
 WINE_CHECK_SONAME(odbc,SQLConnect,,[AC_DEFINE_UNQUOTED(SONAME_LIBODBC,["libodbc.$LIBEXT"])])
 
diff --git a/dlls/iphlpapi/Makefile.in b/dlls/iphlpapi/Makefile.in
index 892a3cb..9cfc955 100644
--- a/dlls/iphlpapi/Makefile.in
+++ b/dlls/iphlpapi/Makefile.in
@@ -1,7 +1,7 @@
 MODULE    = iphlpapi.dll
 IMPORTLIB = iphlpapi
 IMPORTS   = advapi32
-EXTRALIBS = @RESOLVLIBS@ @LIBKSTAT@
+EXTRALIBS = @RESOLVLIBS@ @LIBKSTAT@ @LIBPROCSTAT@
 
 C_SRCS = \
 	icmp.c \
diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index cbeea61..dce5f74 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -123,6 +123,19 @@
 #ifdef HAVE_SYS_TIHDR_H
 #include <sys/tihdr.h>
 #endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_QUEUE_H
+#include <sys/queue.h>
+#endif
+#ifdef HAVE_SYS_USER_H
+/* Make sure the definitions of struct kinfo_proc are the same. */
+#include <sys/user.h>
+#endif
+#ifdef HAVE_LIBPROCSTAT_H
+#include <libprocstat.h>
+#endif
 #ifdef HAVE_LIBPROC_H
 #include <libproc.h>
 #endif
@@ -1987,6 +2000,52 @@ static unsigned int find_owning_pid( struct pid_map *map, unsigned int num_entri
         }
     }
     return 0;
+#elif defined(HAVE_LIBPROCSTAT)
+    struct procstat *pstat;
+    struct kinfo_proc *proc;
+    struct filestat_list *fds;
+    struct filestat *fd;
+    struct sockstat sock;
+    unsigned int i, proc_count;
+
+    pstat = procstat_open_sysctl();
+    if (!pstat) return 0;
+
+    for (i = 0; i < num_entries; i++)
+    {
+        proc = procstat_getprocs( pstat, KERN_PROC_PID, map[i].unix_pid, &proc_count );
+        if (!proc || proc_count < 1) continue;
+
+        fds = procstat_getfiles( pstat, proc, 0 );
+        if (!fds)
+        {
+            procstat_freeprocs( pstat, proc );
+            continue;
+        }
+
+        STAILQ_FOREACH( fd, fds, next )
+        {
+            char errbuf[_POSIX2_LINE_MAX];
+
+            if (fd->fs_type != PS_FST_TYPE_SOCKET) continue;
+
+            procstat_get_socket_info( pstat, fd, &sock, errbuf );
+
+            if (sock.so_pcb == inode)
+            {
+                procstat_freefiles( pstat, fds );
+                procstat_freeprocs( pstat, proc );
+                procstat_close( pstat );
+                return map[i].pid;
+            }
+        }
+
+        procstat_freefiles( pstat, fds );
+        procstat_freeprocs( pstat, proc );
+    }
+
+    procstat_close( pstat );
+    return 0;
 #elif defined(HAVE_LIBPROC_H)
     struct proc_fdinfo *fds;
     struct socket_fdinfo sock;
-- 
1.7.5.4




More information about the wine-patches mailing list