QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3502|回复: 1

请教:如何根据pid找到对应进程正在使有的port

[复制链接]
发表于 2010-5-15 00:09:29 | 显示全部楼层 |阅读模式
最近在恶赶毕业设计,因为以前做的都是在用户态,现在要做成内核态的,所以要改代码。现在遇到一个问题:
    如何根据pid找port?
    说明一下,我不想用/proc,因为看是看了一下,还是对那个不太了解。
还望哪位读过源码的前辈指教,谢谢

[ 本帖最后由 zz_6_3 于 2010-5-16 21:44 编辑 ]
 楼主| 发表于 2010-5-16 21:43:57 | 显示全部楼层
在网上找了一下,现在换成由inode找也可以,由文件名找也可以。
有没有人知道啊?

我用的是Ubuntu9.10,内核是2.6.31-21generic
在网上许多文章说:
stuct inode
{     ......
      union
      {     .......
            struct socket socket_i
             .......
       }
       ........
}
所以看了一下里面的fs.h,但struct inode里面没那个,下面把struct inodu贴一下:
struct inode {
    struct hlist_node    i_hash;
    struct list_head    i_list;
    struct list_head    i_sb_list;
    struct list_head    i_dentry;
    unsigned long        i_ino;
    atomic_t        i_count;
    unsigned int        i_nlink;
    uid_t            i_uid;
    gid_t            i_gid;
    dev_t            i_rdev;
    u64            i_version;
    loff_t            i_size;
#ifdef __NEED_I_SIZE_ORDERED
    seqcount_t        i_size_seqcount;
#endif
    struct timespec        i_atime;
    struct timespec        i_mtime;
    struct timespec        i_ctime;
    blkcnt_t        i_blocks;
    unsigned int        i_blkbits;
    unsigned short          i_bytes;
    umode_t            i_mode;
    spinlock_t        i_lock;    /* i_blocks, i_bytes, maybe i_size */
    struct mutex        i_mutex;
    struct rw_semaphore    i_alloc_sem;
    const struct inode_operations    *i_op;
    const struct file_operations    *i_fop;    /* former ->i_op->default_file_ops */
    struct super_block    *i_sb;
    struct file_lock    *i_flock;
    struct address_space    *i_mapping;
    struct address_space    i_data;
#ifdef CONFIG_QUOTA
    struct dquot        *i_dquot[MAXQUOTAS];
#endif
    struct list_head    i_devices;
    union {
        struct pipe_inode_info    *i_pipe;
        struct block_device    *i_bdev;
        struct cdev        *i_cdev;
    };

    __u32            i_generation;

#ifdef CONFIG_FSNOTIFY
    __u32            i_fsnotify_mask; /* all events this inode cares about */
    struct hlist_head    i_fsnotify_mark_entries; /* fsnotify mark entries */
#endif

#ifdef CONFIG_INOTIFY
    struct list_head    inotify_watches; /* watches on this inode */
    struct mutex        inotify_mutex;    /* protects the watches list */
#endif

    unsigned long        i_state;
    unsigned long        dirtied_when;    /* jiffies of first dirtying */

    unsigned int        i_flags;

    atomic_t        i_writecount;
#ifdef CONFIG_SECURITY
    void            *i_security;
#endif
#ifdef CONFIG_FS_POSIX_ACL
    struct posix_acl    *i_acl;
    struct posix_acl    *i_default_acl;
#endif
    void            *i_private; /* fs or device private pointer */
};
fs.h中是这样定义的,应该是封装了,但是不知道在哪个结构里面,哪位看得出来封装到哪个里面了不?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-21 00:18 , Processed in 0.065483 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表