Cristóbal D.
Cristóbal D.

Reputation: 1

Can a descriptor created by socket() be mapped to a memory buffer?

Is there a way to map a descriptor created by socket() to a memory buffer?

The reason why I am looking for this is because I want to make an existing application to read from the memory buffer I created instead of its associated TCP buffer. I shouldn't modify the application, so I want to map a fd returned by the application to a buffer I created.

I found a similar question: Can descriptors for sockets be converted to File Pointers?

But I don't know if fdopen() can be used for my purpose because fdopen() takes only two arguments (fd and mode) and I don't know how to re-associate the fd to a memory I create with malloc().

Upvotes: 0

Views: 418

Answers (1)

user207421
user207421

Reputation: 311039

Is there a way to map a descriptor created by socket() to a memory buffer?

No. It doesn't make sense. A mapped file makes sense because of the virtual memory system. A mapped socket doesn't.

I want to map a fd returned by the application to a buffer I created.

You will have to write code to read from the socket into your buffer.

Upvotes: 0

Related Questions