Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6688795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:26:41+00:00 2026-05-26T05:26:41+00:00

I got a descriptor for a TCP socket in the following manner : int

  • 0

I got a descriptor for a TCP socket in the following manner :

int desc = accept(socket_descriptor, &client_address, &len)

Now from this descriptor desc I want to get a file pointer. Can fdopen() be used here ?

The reason I want to get a file pointer is because I am making changes to an existing code that writes data to a local file. Now, I want to extend its functionality so that it can alternatively write to a TCP client. I dont want to rewrite all functions and was thinking of somehow being able to use the existing infrastructure. The existing functions use the file pointer to write to the file. I was wondering if it was possible to make the same function write to a TCP stream without making any changes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:26:41+00:00Added an answer on May 26, 2026 at 5:26 am

    Yes, fdopen() is exactly what you need. Here is what man page is saying about it:

    The fdopen() function associates a stream with the existing file
    descriptor, fd. The mode of the stream (one of the values “r”, “r+”,
    “w”, “w+”, “a”, “a+”) must be compatible with the mode of the file
    descriptor. The file position indicator of the new stream is set to
    that belonging to fd, and the error and end-of-file indicators are
    cleared. Modes “w” or “w+” do not cause truncation of the file. The
    file descriptor is not dup’ed, and will be closed when the stream
    created by fdopen() is closed. The result of applying fdopen() to a
    shared memory object is undefined.

    But use it with caution when applying to socket descriptors. High-level I/O functions use buffering, and may send data differently (i.e. flush whenever \n is found in the stream, insert \r) etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I got a file descriptor (socket fd), how to check this fd is
i've got a XML similar to the following example: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE descriptor-layout
I've got the following JavaScript on my web page... 64 var description = new
Got a bluescreen in windows while cloning a mercurial repository. After reboot, I now
Got a bit of a mind freeze at the moment. I have the following
I've got the following JNLP: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE jnlp PUBLIC -//Sun Microsystems, Inc//DTD
I've got a server application using select.select(), and now I'm trying to add SSL
I am read from a file like this: #include <stdio.h> int main() { FILE
I've got a foo.war file from a third-party vendor. I've defined a context in
Description: I've got a project which is nearly finished now, but I've noticed the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.