From b241a9429863f17e8ae7e8d17f8912b14582b865 Mon Sep 17 00:00:00 2001 From: Nick Begg Date: Mon, 2 Mar 2026 00:23:36 +0100 Subject: [PATCH] Add basic support for Darwin PROX_FDTYPE_NETPOLICY, bringing us inline with Apple lsof. --- include/lsof.h | 1 + lib/dialects/darwin/dfile.c | 15 +++++++++++++++ lib/dialects/darwin/dproc.c | 3 +++ lib/dialects/darwin/dproto.h | 1 + lib/print.c | 3 +++ 5 files changed, 23 insertions(+) diff --git a/include/lsof.h b/include/lsof.h index 2dcbd1b8..277e1af7 100644 --- a/include/lsof.h +++ b/include/lsof.h @@ -212,6 +212,7 @@ enum lsof_file_type { type */ LSOF_FILE_SCO_SEMA, /**< SCO OpenServer Xenix semaphore file */ LSOF_FILE_SCO_SHARED, /**< SCO OpenServer Xenix shared data file */ + LSOF_FILE_NPOLICY, /**< Darwin Netpolicy */ LSOF_FILE_UNSUPPORTED, /**< unsupported file type */ /* types from struct vnode */ diff --git a/lib/dialects/darwin/dfile.c b/lib/dialects/darwin/dfile.c index a17f8cc8..486128f3 100644 --- a/lib/dialects/darwin/dfile.c +++ b/lib/dialects/darwin/dfile.c @@ -273,6 +273,20 @@ void process_fsevents(struct lsof_context *ctx, /* context */ Lf->type = LSOF_FILE_FSEVENTS; } +/* + * + * process_fsevents() -- process a network policy file + * see also - + https://github.com/apple-opensource/lsof/blob/da09c8c6436286e5bd8c400b42e86b54404f12a7/lsof/dialects/darwin/libproc/dnetpolicy.c + */ + +void process_netpolicy(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fp) /* fd */ +{ + Lf->type = LSOF_FILE_NPOLICY; +} + /* * process_kqueue() -- process a kernel queue file */ @@ -612,3 +626,4 @@ void process_fileport_vnode(struct lsof_context *ctx, /* context */ process_vnode_common(ctx, &vi); } #endif /* PROC_PIDLISTFILEPORTS */ + diff --git a/lib/dialects/darwin/dproc.c b/lib/dialects/darwin/dproc.c index 6e402ac6..6bf9fe07 100644 --- a/lib/dialects/darwin/dproc.c +++ b/lib/dialects/darwin/dproc.c @@ -537,6 +537,9 @@ static void process_fds(struct lsof_context *ctx, /* context */ case PROX_FDTYPE_VNODE: (void)process_vnode(ctx, pid, fdp->proc_fd); break; + case PROX_FDTYPE_NETPOLICY: + (void)process_netpolicy(ctx, pid, fdp->proc_fd); + break; default: (void)snpf(Namech, Namechl - 1, "unknown file type: %d", fdp->proc_fdtype); diff --git a/lib/dialects/darwin/dproto.h b/lib/dialects/darwin/dproto.h index 1157cec2..bb1bbbe1 100644 --- a/lib/dialects/darwin/dproto.h +++ b/lib/dialects/darwin/dproto.h @@ -52,6 +52,7 @@ extern void process_psem(struct lsof_context *ctx, int pid, int32_t fd); extern void process_pshm(struct lsof_context *ctx, int pid, int32_t fd); extern void process_socket(struct lsof_context *ctx, int pid, int32_t fd); extern void process_vnode(struct lsof_context *ctx, int pid, int32_t fd); +extern void process_netpolicy(struct lsof_context *ctx, int pid, int32_t fd); #if defined(PROC_PIDLISTFILEPORTS) extern void process_fileport_pipe(struct lsof_context *ctx, int pid, uint32_t fileport); diff --git a/lib/print.c b/lib/print.c index f9feef0c..d15c47bd 100644 --- a/lib/print.c +++ b/lib/print.c @@ -394,6 +394,9 @@ void file_type_to_string(enum lsof_file_type type, case LSOF_FILE_SCO_SHARED: (void)snpf(buf, buf_len, "XSD"); break; + case LSOF_FILE_NPOLICY: + (void)snpf(buf, buf_len, "NPOLICY"); + break; case LSOF_FILE_UNSUPPORTED: (void)snpf(buf, buf_len, "UNSP"); break;