Print this page
XXXX adding PID information to netstat output
*** 35,44 ****
--- 35,45 ----
#include <sys/cmn_err.h>
#include <sys/stropts.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+ #include <sys/fcntl.h>
#define _SUN_TPI_VERSION 2
#include <sys/tihdr.h>
#include <sys/sockio.h>
#include <sys/kmem_impl.h>
*** 355,364 ****
--- 356,367 ----
nso->so_proto_handle, (sock_upper_handle_t)nso, cr)) != 0) {
(void) socket_close(nso, 0, cr);
socket_destroy(nso);
} else {
*nsop = nso;
+ if (!(curproc->p_flag & SSYS))
+ sonode_insert_pid(nso, curproc->p_pidp->pid_id);
}
}
SO_UNBLOCK_FALLBACK(so);
return (error);
*** 1551,1560 ****
--- 1554,1601 ----
struct sonode *so = (struct sonode *)sock_handle;
VN_RELE(SOTOV(so));
}
+ mblk_t *
+ so_get_sock_pid_mblk(sock_upper_handle_t sock_handle)
+ {
+ ulong_t sz, n;
+ mblk_t *mblk;
+ pid_node_t *pn;
+ pid_t *pids;
+ conn_pid_info_t *cpi;
+ struct sonode *so = (struct sonode *)sock_handle;
+
+ mutex_enter(&so->so_pid_tree_lock);
+
+ n = avl_numnodes(&so->so_pid_tree);
+ sz = sizeof (conn_pid_info_t);
+ sz += (n > 1) ? ((n - 1) * sizeof (pid_t)) : 0;
+ if ((mblk = allocb(sz, BPRI_HI)) == NULL) {
+ mutex_exit(&so->so_pid_tree_lock);
+ return (NULL);
+ }
+ mblk->b_wptr += sz;
+ cpi = (conn_pid_info_t *)mblk->b_datap->db_base;
+
+ cpi->cpi_magic = CONN_PID_INFO_MGC;
+ cpi->cpi_contents = CONN_PID_INFO_SOC;
+ cpi->cpi_pids_cnt = n;
+ cpi->cpi_tot_size = sz;
+ cpi->cpi_pids[0] = 0;
+
+ if (cpi->cpi_pids_cnt > 0) {
+ pids = cpi->cpi_pids;
+ for (pn = avl_first(&so->so_pid_tree); pn != NULL;
+ pids++, pn = AVL_NEXT(&so->so_pid_tree, pn))
+ *pids = pn->pn_pid;
+ }
+ mutex_exit(&so->so_pid_tree_lock);
+ return (mblk);
+ }
+
void
so_zcopy_notify(sock_upper_handle_t sock_handle)
{
struct sonode *so = (struct sonode *)sock_handle;
*** 1951,1957 ****
so_set_prop,
so_txq_full,
so_signal_oob,
so_zcopy_notify,
so_set_error,
! so_closed
};
--- 1992,1999 ----
so_set_prop,
so_txq_full,
so_signal_oob,
so_zcopy_notify,
so_set_error,
! so_closed,
! so_get_sock_pid_mblk
};