Skip to content

Commit

Permalink
fix #1105: can't compile psutil on freebsd 12
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Sep 8, 2017
1 parent de5f2f8 commit c15fb0d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ XXXX-XX-XX

- 1124_: documentation moved to http://psutil.readthedocs.io

**Big fixes**

- 1105_: [FreeBSD] psutil does not compile on FreeBSD 12.

**Compatibility notes**

- 1120_: .exe files for Windows are no longer uploaded on PYPI as per PEP-527;
Expand Down
36 changes: 36 additions & 0 deletions psutil/arch/freebsd/proc_socks.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,36 @@ psutil_search_tcplist(char *buf, struct kinfo_file *kif) {
if (kif->kf_sock_domain == AF_INET) {
if (!psutil_sockaddr_matches(
AF_INET, inp->inp_lport, &inp->inp_laddr,
#if __FreeBSD_version < 1200031
&kif->kf_sa_local))
#else
&kif->kf_un.kf_sock.kf_sa_local))
#endif
continue;
if (!psutil_sockaddr_matches(
AF_INET, inp->inp_fport, &inp->inp_faddr,
#if __FreeBSD_version < 1200031
&kif->kf_sa_peer))
#else
&kif->kf_un.kf_sock.kf_sa_peer))
#endif
continue;
} else {
if (!psutil_sockaddr_matches(
AF_INET6, inp->inp_lport, &inp->in6p_laddr,
#if __FreeBSD_version < 1200031
&kif->kf_sa_local))
#else
&kif->kf_un.kf_sock.kf_sa_local))
#endif
continue;
if (!psutil_sockaddr_matches(
AF_INET6, inp->inp_fport, &inp->in6p_faddr,
#if __FreeBSD_version < 1200031
&kif->kf_sa_peer))
#else
&kif->kf_un.kf_sock.kf_sa_peer))
#endif
continue;
}

Expand Down Expand Up @@ -243,19 +259,35 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
inet_ntop(
kif->kf_sock_domain,
psutil_sockaddr_addr(kif->kf_sock_domain,
#if __FreeBSD_version < 1200031
&kif->kf_sa_local),
#else
&kif->kf_un.kf_sock.kf_sa_local),
#endif
lip,
sizeof(lip));
inet_ntop(
kif->kf_sock_domain,
psutil_sockaddr_addr(kif->kf_sock_domain,
#if __FreeBSD_version < 1200031
&kif->kf_sa_peer),
#else
&kif->kf_un.kf_sock.kf_sa_peer),
#endif
rip,
sizeof(rip));
lport = htons(psutil_sockaddr_port(kif->kf_sock_domain,
#if __FreeBSD_version < 1200031
&kif->kf_sa_local));
#else
&kif->kf_un.kf_sock.kf_sa_local));
#endif
rport = htons(psutil_sockaddr_port(kif->kf_sock_domain,
#if __FreeBSD_version < 1200031
&kif->kf_sa_peer));
#else
&kif->kf_un.kf_sock.kf_sa_peer));
#endif

// construct python tuple/list
py_laddr = Py_BuildValue("(si)", lip, lport);
Expand Down Expand Up @@ -287,7 +319,11 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
else if (kif->kf_sock_domain == AF_UNIX) {
struct sockaddr_un *sun;

#if __FreeBSD_version < 1200031
sun = (struct sockaddr_un *)&kif->kf_sa_local;
#else
sun = (struct sockaddr_un *)&kif->kf_un.kf_sock.kf_sa_local;
#endif
snprintf(
path, sizeof(path), "%.*s",
(int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))),
Expand Down

0 comments on commit c15fb0d

Please sign in to comment.