(root)/
util-linux-2.39/
misc-utils/
lsfd-sock.h
       1  /*
       2   * lsfd(1) - list file descriptors
       3   *
       4   * Copyright (C) 2022 Red Hat, Inc. All rights reserved.
       5   * Written by Masatake YAMATO <yamato@redhat.com>
       6   *
       7   * Very generally based on lsof(8) by Victor A. Abell <abe@purdue.edu>
       8   * It supports multiple OSes. lsfd specializes to Linux.
       9   *
      10   * This program is free software; you can redistribute it and/or modify
      11   * it under the terms of the GNU General Public License as published by
      12   * the Free Software Foundation; either version 2 of the License, or
      13   * (at your option) any later version.
      14   *
      15   * This program is distributed in the hope that it would be useful,
      16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18   * GNU General Public License for more details.
      19   *
      20   * You should have received a copy of the GNU General Public License
      21   * along with this program; if not, write to the Free Software Foundation,
      22   * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      23   */
      24  #ifndef UTIL_LINUX_LSFD_SOCK_H
      25  #define UTIL_LINUX_LSFD_SOCK_H
      26  
      27  #include <stdbool.h>
      28  #include <sys/stat.h>
      29  
      30  #include "libsmartcols.h"
      31  
      32  /*
      33   * xinfo: eXtra inforation about sockets
      34   */
      35  struct sock_xinfo {
      36  	ino_t inode;		/* inode in sockfs */
      37  	ino_t netns_inode;	/* inode of netns where
      38  				   the socket belongs to */
      39  	const struct sock_xinfo_class *class;
      40  };
      41  
      42  struct sock {
      43  	struct file file;
      44  	char *protoname;
      45  	struct sock_xinfo *xinfo;
      46  };
      47  
      48  struct sock_xinfo_class {
      49  	/* Methods for filling socket related columns */
      50  	char * (*get_name)(struct sock_xinfo *, struct sock *);
      51  	char * (*get_type)(struct sock_xinfo *, struct sock *);
      52  	char * (*get_state)(struct sock_xinfo *, struct sock *);
      53  	bool (*get_listening)(struct sock_xinfo *, struct sock *);
      54  	/* Method for class specific columns.
      55  	 * Return true when the method fills the column. */
      56  	bool (*fill_column)(struct proc *,
      57  			    struct sock_xinfo *,
      58  			    struct sock *,
      59  			    struct libscols_line *,
      60  			    int,
      61  			    size_t,
      62  			    char **str);
      63  
      64  	void (*free)(struct sock_xinfo *);
      65  };
      66  
      67  void initialize_sock_xinfos(void);
      68  void finalize_sock_xinfos(void);
      69  
      70  struct sock_xinfo *get_sock_xinfo(ino_t netns_inode);
      71  
      72  #endif /* UTIL_LINUX_LSFD_SOCK_H */