File: [cvs.NetBSD.org] / pkgsrc / sysutils / py-psutil / patches / Attic / patch-psutil_arch_bsd_netbsd__socks.c (download)
Revision 1.1, Tue Dec 1 14:07:36 2015 UTC (7 years, 5 months ago) by ryoon
Branch: MAIN
CVS Tags: pkgsrc-2015Q4-base, pkgsrc-2015Q4
Update to 3.3.0
* Add preliminary NetBSD support code.
It is sufficient to run letsencrypt python client on NetBSD.
Changelog:
3.3.0 - 2015-11-25
==================
**Enhancements**
- #558: [Linux] exposed psutil.PROCFS_PATH constant to change the default
location of /proc filesystem.
- #615: [OpenBSD] added OpenBSD support. (contributed by Landry Breuil)
**Bug fixes**
- #692: [UNIX] Process.name() is no longer cached as it may change.
3.2.2 - 2015-10-04
==================
**Bug fixes**
- #517: [SunOS] net_io_counters failed to detect network interfaces
correctly on Solaris 10
- #541: [FreeBSD] disk_io_counters r/w times were expressed in seconds instead
of milliseconds. (patch by dasumin)
- #610: [SunOS] fix build and tests on Solaris 10
- #623: [Linux] process or system connections raises ValueError if IPv6 is not
supported by the system.
- #678: [Linux] can't install psutil due to bug in setup.py.
- #688: [Windows] compilation fails with MSVC 2015, Python 3.5. (patch by
Mike Sarahan)
3.2.1 - 2015-09-03
==================
**Bug fixes**
- #677: [Linux] can't install psutil due to bug in setup.py.
3.2.0 - 2015-09-02
==================
**Enhancements**
- #644: [Windows] added support for CTRL_C_EVENT and CTRL_BREAK_EVENT signals
to use with Process.send_signal().
- #648: CI test integration for OSX. (patch by Jeff Tang)
- #663: [UNIX] net_if_addrs() now returns point-to-point (VPNs) addresses.
- #655: [Windows] different issues regarding unicode handling were fixed. On
Python 2 all APIs returning a string will now return an encoded version of it
by using sys.getfilesystemencoding() codec. The APIs involved are:
- psutil.net_if_addrs()
- psutil.net_if_stats()
- psutil.net_io_counters()
- psutil.Process.cmdline()
- psutil.Process.name()
- psutil.Process.username()
- psutil.users()
**Bug fixes**
- #513: [Linux] fixed integer overflow for RLIM_INFINITY.
- #641: [Windows] fixed many compilation warnings. (patch by Jeff Tang)
- #652: [Windows] net_if_addrs() UnicodeDecodeError in case of non-ASCII NIC
names.
- #655: [Windows] net_if_stats() UnicodeDecodeError in case of non-ASCII NIC
names.
- #659: [Linux] compilation error on Suse 10. (patch by maozguttman)
- #664: [Linux] compilation error on Alpine Linux. (patch by Bart van Kleef)
- #670: [Windows] segfgault of net_if_addrs() in case of non-ASCII NIC names.
(patch by sk6249)
- #672: [Windows] compilation fails if using Windows SDK v8.0. (patch by
Steven Winfield)
- #675: [Linux] net_connections(); UnicodeDecodeError may occur when listing
UNIX sockets.
3.1.1 - 2015-07-15
==================
**Bug fixes**
- #603: [Linux] ionice_set value range is incorrect. (patch by spacewander)
- #645: [Linux] psutil.cpu_times_percent() may produce negative results.
- #656: 'from psutil import *' does not work.
3.1.0 - 2015-07-15
==================
**Enhancements**
- #534: [Linux] disk_partitions() added support for ZFS filesystems.
- #646: continuous tests integration for Windows with
https://ci.appveyor.com/project/giampaolo/psutil.
- #647: new dev guide:
https://github.com/giampaolo/psutil/blob/master/DEVGUIDE.rst
- #651: continuous code quality test integration with
https://scrutinizer-ci.com/g/giampaolo/psutil/
**Bug fixes**
- #340: [Windows] Process.open_files() no longer hangs. Instead it uses a
thred which times out and skips the file handle in case it's taking too long
to be retrieved. (patch by Jeff Tang, PR #597)
- #627: [Windows] Process.name() no longer raises AccessDenied for pids owned
by another user.
- #636: [Windows] Process.memory_info() raise AccessDenied.
- #637: [UNIX] raise exception if trying to send signal to Process PID 0 as it
will affect os.getpid()'s process group instead of PID 0.
- #639: [Linux] Process.cmdline() can be truncated.
- #640: [Linux] *connections functions may swallow errors and return an
incomplete list of connnections.
- #642: repr() of exceptions is incorrect.
- #653: [Windows] Add inet_ntop function for Windows XP to support IPv6.
- #641: [Windows] Replace deprecated string functions with safe equivalents.
3.0.1 - 2015-06-18
==================
**Bug fixes**
- #632: [Linux] better error message if cannot parse process UNIX connections.
- #634: [Linux] Proces.cmdline() does not include empty string arguments.
- #635: [UNIX] crash on module import if 'enum' package is installed on python
< 3.4.
3.0.0 - 2015-06-13
==================
**Enhancements**
- #250: new psutil.net_if_stats() returning NIC statistics (isup, duplex,
speed, MTU).
- #376: new psutil.net_if_addrs() returning all NIC addresses a-la ifconfig.
- #469: on Python >= 3.4 ``IOPRIO_CLASS_*`` and ``*_PRIORITY_CLASS`` constants
returned by psutil.Process' ionice() and nice() methods are enums instead of
plain integers.
- #581: add .gitignore. (patch by Gabi Davar)
- #582: connection constants returned by psutil.net_connections() and
psutil.Process.connections() were turned from int to enums on Python > 3.4.
- #587: Move native extension into the package.
- #589: Process.cpu_affinity() accepts any kind of iterable (set, tuple, ...),
not only lists.
- #594: all deprecated APIs were removed.
- #599: [Windows] process name() can now be determined for all processes even
when running as a limited user.
- #602: pre-commit GIT hook.
- #629: enhanced support for py.test and nose test discovery and tests run.
- #616: [Windows] Add inet_ntop function for Windows XP.
**Bug fixes**
- #428: [all UNIXes except Linux] correct handling of zombie processes;
introduced new ZombieProcess exception class.
- #512: [BSD] fix segfault in net_connections().
- #555: [Linux] psutil.users() correctly handles ":0" as an alias for
"localhost"
- #579: [Windows] Fixed open_files() for PID>64K.
- #579: [Windows] fixed many compiler warnings.
- #585: [FreeBSD] net_connections() may raise KeyError.
- #586: [FreeBSD] cpu_affinity() segfaults on set in case an invalid CPU
number is provided.
- #593: [FreeBSD] Process().memory_maps() segfaults.
- #606: Process.parent() may swallow NoSuchProcess exceptions.
- #611: [SunOS] net_io_counters has send and received swapped
- #614: [Linux]: cpu_count(logical=False) return the number of physical CPUs
instead of physical cores.
- #618: [SunOS] swap tests fail on Solaris when run as normal user
- #628: [Linux] Process.name() truncates process name in case it contains
spaces or parentheses.
2.2.1 - 2015-02-02
==================
**Bug fixes**
- #496: [Linux] fix "ValueError: ambiguos inode with multiple PIDs references"
(patch by Bruno Binet)
2.2.0 - 2015-01-06
==================
**Enhancements**
- #521: drop support for Python 2.4 and 2.5.
- #553: new examples/pstree.py script.
- #564: C extension version mismatch in case the user messed up with psutil
installation or with sys.path is now detected at import time.
- #568: New examples/pidof.py script.
- #569: [FreeBSD] add support for process CPU affinity.
**Bug fixes**
- #496: [Solaris] can't import psutil.
- #547: [UNIX] Process.username() may raise KeyError if UID can't be resolved.
- #551: [Windows] get rid of the unicode hack for net_io_counters() NIC names.
- #556: [Linux] lots of file handles were left open.
- #561: [Linux] net_connections() might skip some legitimate UNIX sockets.
(patch by spacewander)
- #565: [Windows] use proper encoding for psutil.Process.username() and
psutil.users(). (patch by Sylvain Mouquet)
- #567: [Linux] in the alternative implementation of CPU affinity PyList_Append
and Py_BuildValue return values are not checked.
- #569: [FreeBSD] fix memory leak in psutil.cpu_count(logical=False).
- #571: [Linux] Process.open_files() might swallow AccessDenied exceptions and
return an incomplete list of open files.
|
$NetBSD: patch-psutil_arch_bsd_netbsd__socks.c,v 1.1 2015/12/01 14:07:36 ryoon Exp $
--- psutil/arch/bsd/netbsd_socks.c.orig 2015-11-30 15:55:46.000000000 +0000
+++ psutil/arch/bsd/netbsd_socks.c
@@ -0,0 +1,535 @@
+/*
+ * Copyright (c) 2009, Giampaolo Rodola'.
+ * Copyright (c) 2015, Ryo ONODERA.
+ * All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include <Python.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/sysctl.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <sys/cdefs.h>
+#include <arpa/inet.h>
+#include <sys/queue.h>
+#include <sys/un.h>
+#include <sys/file.h>
+
+// a signaler for connections without an actual status
+int PSUTIL_CONN_NONE = 128;
+
+/* Address family filter */
+enum af_filter {
+ INET,
+ INET4,
+ INET6,
+ TCP,
+ TCP4,
+ TCP6,
+ UDP,
+ UDP4,
+ UDP6,
+ UNIX,
+ ALL,
+};
+
+/* kinfo_file results */
+struct kif {
+ SLIST_ENTRY(kif) kifs;
+ struct kinfo_file *kif;
+};
+
+/* kinfo_file results list */
+SLIST_HEAD(kifhead, kif) kihead = SLIST_HEAD_INITIALIZER(kihead);
+
+
+/* kinfo_pcb results */
+struct kpcb {
+ SLIST_ENTRY(kpcb) kpcbs;
+ struct kinfo_pcb *kpcb;
+};
+
+/* kinfo_pcb results list */
+SLIST_HEAD(kpcbhead, kpcb) kpcbhead = SLIST_HEAD_INITIALIZER(kpcbhead);
+
+static void kiflist_init(void);
+static void kiflist_clear(void);
+static void kpcblist_init(void);
+static void kpcblist_clear(void);
+static int get_files(void);
+static int get_sockets(const char *name);
+static void get_info(int aff);
+
+/* Initialize kinfo_file results list */
+static void
+kiflist_init(void)
+{
+ SLIST_INIT(&kihead);
+ return;
+}
+
+/* Clear kinfo_file results list */
+static void
+kiflist_clear(void)
+{
+ while (!SLIST_EMPTY(&kihead)) {
+ SLIST_REMOVE_HEAD(&kihead, kifs);
+ }
+
+ return;
+}
+
+/* Initialize kinof_pcb result list */
+static void
+kpcblist_init(void)
+{
+ SLIST_INIT(&kpcbhead);
+ return;
+}
+
+/* Clear kinof_pcb result list */
+static void
+kpcblist_clear(void)
+{
+ while (!SLIST_EMPTY(&kpcbhead)) {
+ SLIST_REMOVE_HEAD(&kpcbhead, kpcbs);
+ }
+
+ return;
+}
+
+
+/*
+ * Get all open files including socket
+ */
+static int
+get_files(void)
+{
+ size_t len;
+ int mib[6];
+ char *buf;
+ off_t offset;
+ int j;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_FILE2;
+ mib[2] = KERN_FILE_BYFILE;
+ mib[3] = 0;
+ mib[4] = sizeof(struct kinfo_file);
+ mib[5] = 0;
+
+ if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
+ return -1;
+ offset = len % sizeof(off_t);
+ mib[5] = len / sizeof(struct kinfo_file);
+ if ((buf = malloc(len + offset)) == NULL)
+ return -1;
+ if (sysctl(mib, 6, buf + offset, &len, NULL, 0) == -1) {
+ free(buf);
+ return -1;
+ }
+
+ len /= sizeof(struct kinfo_file);
+ struct kinfo_file *ki = (struct kinfo_file *)(buf + offset);
+
+ for (j = 0; j < len; j++) {
+ struct kif *kif = malloc(sizeof(struct kif));
+ kif->kif = &ki[j];
+ SLIST_INSERT_HEAD(&kihead, kif, kifs);
+ }
+
+#if 0
+ /* debug */
+ struct kif *k;
+ SLIST_FOREACH(k, &kihead, kifs) {
+ printf("%d\n", k->kif->ki_pid);
+ }
+#endif
+
+ return 0;
+}
+
+/*
+ * Get open sockets
+ */
+static int
+get_sockets(const char *name)
+{
+ size_t namelen;
+ int mib[8];
+ int ret, j;
+ struct kinfo_pcb *pcb;
+ size_t len;
+
+ memset(mib, 0, sizeof(mib));
+
+ if (sysctlnametomib(name, mib, &namelen) == -1)
+ return -1;
+
+ if (sysctl(mib, __arraycount(mib), NULL, &len, NULL, 0) == -1)
+ return -1;
+
+ if ((pcb = malloc(len)) == NULL) {
+ free(pcb);
+ return -1;
+ }
+ memset(pcb, 0, len);
+
+ mib[6] = sizeof(*pcb);
+ mib[7] = len / sizeof(*pcb);
+
+ if (sysctl(mib, __arraycount(mib), pcb, &len, NULL, 0) == -1) {
+ return -1;
+ }
+
+ len /= sizeof(struct kinfo_pcb);
+ struct kinfo_pcb *kp = (struct kinfo_pcb *)pcb;
+
+ for (j = 0; j < len; j++) {
+ struct kpcb *kpcb = malloc(sizeof(struct kpcb));
+ kpcb->kpcb = &kp[j];
+ SLIST_INSERT_HEAD(&kpcbhead, kpcb, kpcbs);
+ }
+
+#if 0
+ /* debug */
+ struct kif *k;
+ struct kpcb *k;
+ SLIST_FOREACH(k, &kpcbhead, kpcbs) {
+ printf("ki_type: %d\n", k->kpcb->ki_type);
+ printf("ki_family: %d\n", k->kpcb->ki_family);
+ }
+#endif
+
+ return 0;
+}
+
+
+/*
+ * Collect connections by PID
+ */
+PyObject *
+psutil_proc_connections(PyObject *self, PyObject *args)
+{
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
+ PyObject *py_laddr = NULL;
+ PyObject *py_raddr = NULL;
+ pid_t pid;
+
+ if (! PyArg_ParseTuple(args, "l", &pid))
+ return NULL;
+
+ if (py_retlist == NULL)
+ return NULL;
+
+ kiflist_init();
+ kpcblist_init();
+ get_info(ALL);
+
+ struct kif *k;
+ SLIST_FOREACH(k, &kihead, kifs) {
+ struct kpcb *kp;
+ if (k->kif->ki_pid == pid) {
+ SLIST_FOREACH(kp, &kpcbhead, kpcbs) {
+ if (k->kif->ki_fdata == kp->kpcb->ki_sockaddr) {
+ pid_t pid;
+ int32_t fd;
+ int32_t family;
+ int32_t type;
+ char laddr[PATH_MAX];
+ int32_t lport;
+ char raddr[PATH_MAX];
+ int32_t rport;
+ int32_t status;
+
+ pid = k->kif->ki_pid;
+ fd = k->kif->ki_fd;
+ family = kp->kpcb->ki_family;
+ type = kp->kpcb->ki_type;
+ if (kp->kpcb->ki_family == AF_INET) {
+ struct sockaddr_in *sin_src =
+ (struct sockaddr_in *)&kp->kpcb->ki_src;
+ struct sockaddr_in *sin_dst =
+ (struct sockaddr_in *)&kp->kpcb->ki_dst;
+ if (inet_ntop(AF_INET, &sin_src->sin_addr, laddr,
+ sizeof(laddr)) != NULL)
+ lport = ntohs(sin_src->sin_port);
+ py_laddr = Py_BuildValue("(si)", laddr, lport);
+ if (inet_ntop(AF_INET, &sin_dst->sin_addr, raddr,
+ sizeof(raddr)) != NULL)
+ rport = ntohs(sin_dst->sin_port);
+ py_raddr = Py_BuildValue("(si)", raddr, rport);
+ if (kp->kpcb->ki_type == SOCK_STREAM) {
+ status = kp->kpcb->ki_tstate;
+ } else {
+ status = PSUTIL_CONN_NONE;
+ }
+
+ py_tuple = Py_BuildValue("(iiiNNi)", fd, AF_INET,
+ type, py_laddr, py_raddr, status);
+ if (!py_tuple) {
+ return 0;
+ }
+ if (PyList_Append(py_retlist, py_tuple))
+ return 0;
+ } else if (kp->kpcb->ki_family == AF_INET6) {
+ struct sockaddr_in6 *sin6_src =
+ (struct sockaddr_in6 *)&kp->kpcb->ki_src;
+ struct sockaddr_in6 *sin6_dst =
+ (struct sockaddr_in6 *)&kp->kpcb->ki_dst;
+ if (inet_ntop(AF_INET6, &sin6_src->sin6_addr, laddr,
+ sizeof(laddr)) != NULL)
+ lport = ntohs(sin6_src->sin6_port);
+ py_laddr = Py_BuildValue("(si)", laddr, lport);
+ if (inet_ntop(AF_INET6, &sin6_dst->sin6_addr, raddr,
+ sizeof(raddr)) != NULL)
+ rport = ntohs(sin6_dst->sin6_port);
+ py_raddr = Py_BuildValue("(si)", raddr, rport);
+ if (kp->kpcb->ki_type == SOCK_STREAM) {
+ status = kp->kpcb->ki_tstate;
+ } else {
+ status = PSUTIL_CONN_NONE;
+ }
+
+ py_tuple = Py_BuildValue("(iiiNNi)", fd, AF_INET6,
+ type, py_laddr, py_raddr, status);
+ if (!py_tuple) {
+ return 0;
+ }
+ if (PyList_Append(py_retlist, py_tuple))
+ return 0;
+ } else if (kp->kpcb->ki_family == AF_UNIX) {
+ struct sockaddr_un *sun_src =
+ (struct sockaddr_un *)&kp->kpcb->ki_src;
+ struct sockaddr_un *sun_dst =
+ (struct sockaddr_un *)&kp->kpcb->ki_dst;
+ strcpy(laddr, sun_src->sun_path);
+ strcpy(raddr, sun_dst->sun_path);
+ status = PSUTIL_CONN_NONE;
+
+ py_tuple = Py_BuildValue("(iiissi)", fd, AF_UNIX,
+ type, laddr, raddr, status);
+ if (!py_tuple) {
+ printf("Empty tuple\n");
+ return 0;
+ }
+ if (PyList_Append(py_retlist, py_tuple))
+ return 0;
+ } else if (kp->kpcb->ki_family == AF_UNIX) {
+ struct sockaddr_un *sun_src =
+ (struct sockaddr_un *)&kp->kpcb->ki_src;
+ struct sockaddr_un *sun_dst =
+ (struct sockaddr_un *)&kp->kpcb->ki_dst;
+ strcpy(laddr, sun_src->sun_path);
+ strcpy(raddr, sun_dst->sun_path);
+ status = PSUTIL_CONN_NONE;
+
+ py_tuple = Py_BuildValue("(iiissi)", fd, AF_UNIX,
+ type, laddr, raddr, status);
+ if (!py_tuple) {
+ printf("Empty tuple\n");
+ return 0;
+ }
+ if (PyList_Append(py_retlist, py_tuple))
+ return 0;
+ }
+
+
+ }
+ }}
+ }
+
+ kiflist_clear();
+ kpcblist_clear();
+ return py_retlist;
+
+
+}
+
+
+/*
+ * Collect open file and connections
+ */
+static void
+get_info(int aff)
+{
+ get_files();
+
+ switch (aff) {
+ case INET:
+ get_sockets("net.inet.tcp.pcblist");
+ get_sockets("net.inet.udp.pcblist");
+ get_sockets("net.inet6.tcp6.pcblist");
+ get_sockets("net.inet6.udp6.pcblist");
+ break;
+ case INET4:
+ get_sockets("net.inet.tcp.pcblist");
+ get_sockets("net.inet.udp.pcblist");
+ break;
+ case INET6:
+ get_sockets("net.inet6.tcp6.pcblist");
+ get_sockets("net.inet6.udp6.pcblist");
+ break;
+ case TCP:
+ get_sockets("net.inet.tcp.pcblist");
+ get_sockets("net.inet6.tcp6.pcblist");
+ break;
+ case TCP4:
+ get_sockets("net.inet.tcp.pcblist");
+ break;
+ case TCP6:
+ get_sockets("net.inet6.tcp6.pcblist");
+ break;
+ case UDP:
+ get_sockets("net.inet.udp.pcblist");
+ get_sockets("net.inet6.udp6.pcblist");
+ break;
+ case UDP4:
+ get_sockets("net.inet.udp.pcblist");
+ break;
+ case UDP6:
+ get_sockets("net.inet6.udp6.pcblist");
+ break;
+ case UNIX:
+ get_sockets("net.local.stream.pcblist");
+ get_sockets("net.local.seqpacket.pcblist");
+ get_sockets("net.local.dgram.pcblist");
+ break;
+ case ALL:
+ get_sockets("net.inet.tcp.pcblist");
+ get_sockets("net.inet.udp.pcblist");
+ get_sockets("net.inet6.tcp6.pcblist");
+ get_sockets("net.inet6.udp6.pcblist");
+ get_sockets("net.local.stream.pcblist");
+ get_sockets("net.local.seqpacket.pcblist");
+ get_sockets("net.local.dgram.pcblist");
+ break;
+ }
+ return;
+}
+
+/*
+ * Collect system wide connections by address family filter
+ */
+PyObject *
+psutil_net_connections(PyObject *self, PyObject *args)
+{
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
+ PyObject *py_laddr = NULL;
+ PyObject *py_raddr = NULL;
+
+ if (py_retlist == NULL)
+ return NULL;
+
+ kiflist_init();
+ kpcblist_init();
+ get_info(ALL);
+
+ struct kif *k;
+ SLIST_FOREACH(k, &kihead, kifs) {
+ struct kpcb *kp;
+ SLIST_FOREACH(kp, &kpcbhead, kpcbs) {
+ if (k->kif->ki_fdata == kp->kpcb->ki_sockaddr) {
+ pid_t pid;
+ int32_t fd;
+ int32_t family;
+ int32_t type;
+ char laddr[PATH_MAX];
+ int32_t lport;
+ char raddr[PATH_MAX];
+ int32_t rport;
+ int32_t status;
+
+ pid = k->kif->ki_pid;
+ fd = k->kif->ki_fd;
+ family = kp->kpcb->ki_family;
+ type = kp->kpcb->ki_type;
+ if (kp->kpcb->ki_family == AF_INET) {
+ struct sockaddr_in *sin_src =
+ (struct sockaddr_in *)&kp->kpcb->ki_src;
+ struct sockaddr_in *sin_dst =
+ (struct sockaddr_in *)&kp->kpcb->ki_dst;
+ if (inet_ntop(AF_INET, &sin_src->sin_addr, laddr,
+ sizeof(laddr)) != NULL)
+ lport = ntohs(sin_src->sin_port);
+ py_laddr = Py_BuildValue("(si)", laddr, lport);
+ if (inet_ntop(AF_INET, &sin_dst->sin_addr, raddr,
+ sizeof(raddr)) != NULL)
+ rport = ntohs(sin_dst->sin_port);
+ py_raddr = Py_BuildValue("(si)", raddr, rport);
+ if (kp->kpcb->ki_type == SOCK_STREAM) {
+ status = kp->kpcb->ki_tstate;
+ } else {
+ status = PSUTIL_CONN_NONE;
+ }
+
+ py_tuple = Py_BuildValue("(iiiNNii)", fd, AF_INET,
+ type, py_laddr, py_raddr, status, pid);
+ if (!py_tuple) {
+ printf("Empty tuple\n");
+ return 0;
+ }
+ if (PyList_Append(py_retlist, py_tuple))
+ return 0;
+ } else if (kp->kpcb->ki_family == AF_INET6) {
+ struct sockaddr_in6 *sin6_src =
+ (struct sockaddr_in6 *)&kp->kpcb->ki_src;
+ struct sockaddr_in6 *sin6_dst =
+ (struct sockaddr_in6 *)&kp->kpcb->ki_dst;
+ if (inet_ntop(AF_INET6, &sin6_src->sin6_addr, laddr,
+ sizeof(laddr)) != NULL)
+ lport = ntohs(sin6_src->sin6_port);
+ py_laddr = Py_BuildValue("(si)", laddr, lport);
+ if (inet_ntop(AF_INET6, &sin6_dst->sin6_addr, raddr,
+ sizeof(raddr)) != NULL)
+ rport = ntohs(sin6_dst->sin6_port);
+ py_raddr = Py_BuildValue("(si)", raddr, rport);
+ if (kp->kpcb->ki_type == SOCK_STREAM) {
+ status = kp->kpcb->ki_tstate;
+ } else {
+ status = PSUTIL_CONN_NONE;
+ }
+
+ py_tuple = Py_BuildValue("(iiiNNii)", fd, AF_INET6,
+ type, py_laddr, py_raddr, status, pid);
+ if (!py_tuple) {
+ printf("Empty tuple\n");
+ return 0;
+ }
+ if (PyList_Append(py_retlist, py_tuple))
+ return 0;
+ } else if (kp->kpcb->ki_family == AF_UNIX) {
+ struct sockaddr_un *sun_src =
+ (struct sockaddr_un *)&kp->kpcb->ki_src;
+ struct sockaddr_un *sun_dst =
+ (struct sockaddr_un *)&kp->kpcb->ki_dst;
+ strcpy(laddr, sun_src->sun_path);
+ strcpy(raddr, sun_dst->sun_path);
+ status = PSUTIL_CONN_NONE;
+
+ py_tuple = Py_BuildValue("(iiissii)", fd, AF_UNIX,
+ type, laddr, raddr, status, pid);
+ if (!py_tuple) {
+ printf("Empty tuple\n");
+ return 0;
+ }
+ if (PyList_Append(py_retlist, py_tuple))
+ return 0;
+ }
+
+
+ }
+ }
+ }
+
+ kiflist_clear();
+ kpcblist_clear();
+ return py_retlist;
+}