# Get thread from within a module



## Farhan Khan (Aug 16, 2018)

Hi all,
I am doing some light experimentation with the kernel and am writing a module. I am trying to have a /dev file functions as a TCP listening socket. So if you do `cat /dev/tcp/5555`, it would be the equivalent of `nc -l 5555`.

My general strategy is to create a socket by jumping into the same path that a syscall takes, which is lands in kern_socket. The call is declared as follows:

```
int
kern_socket(struct thread *td, int domain, int type, int protocol)
```
I was not certain how to get the `td` pointer from within a kernel module's handler function. Is there a general approach to that? My read handler's header is as follows:

```
static int
tcpdev_read(struct cdev *dev, struct uio *uio, int flags)
```

I recognize that this is a redundant effort. My ultimate purpose is to experiment, run into problems and learn.
Thanks!


----------



## Bobi B. (Aug 17, 2018)

`curthread` perhaps, `struct thread *td = curthread;`?


----------



## Farhan Khan (Aug 20, 2018)

They are different, unfortunately.


----------

