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

  • Home
  • SEARCH
  • 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 7503229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:08:55+00:00 2026-05-29T21:08:55+00:00

The following is the code snippet I’ve written for accepting connections from the client.

  • 0

The following is the code snippet I’ve written for accepting connections from the client. I wanted to print the remote host name. getnameinfo() fails with the error: ai_family not supported. I tried different options over the internet like specifying AF_UNSPEC. Nothing is working for me. I printed the sa_family field and it is 62752. Is this a valid value? What am I doing wrong. Any help appreciated.

socklen_t sin_size;
struct sockaddr client_addr;
int sockfd = accept(serv_sockfd,&client_addr, &sin_size);
if(sockfd == -1)
   error("Accept failed");

char remote_host[NI_MAXHOST];
cerr <<"sa_family" << client_addr.sa_family<<endl;

int en;
if ((en = getnameinfo(&client_addr, sin_size, remote_host, sizeof(remote_host),NULL, 0, NI_NAMEREQD))!=0)
cerr << "getnameinfo: " << gai_strerror(en);
else
   printf("host=%s\n", remote_host);
  • 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-29T21:08:55+00:00Added an answer on May 29, 2026 at 9:08 pm

    Your bug is earlier. The third argument to accept() is supposed to be:

    address_len

    Points to a socklen_t structure which on input specifies the length of
    the supplied sockaddr structure, and on output specifies the length of
    the stored address.

    Also, a struct sockaddr is too small to hold any actual address.

    Try:

    struct sockaddr_storage client_addr;
    socklen_t sin_size = sizeof(client_addr);
    int sockfd = accept(serv_sockfd, (struct sockaddr *)&client_addr, &sin_size);
    

    …and then the rest of your code as written.

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

Sidebar

Related Questions

The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk
Given the following code snippet from inside a method; NSBezierPath * tempPath = [NSBezierPath
I have the following code snippet from my PowerShell script that... Loops through a
the following code snippet taken from http://perldoc.perl.org/perlrequick.html#Search-and-replace gives me Bareword found where operator expected
I have the following code snippet, which loads data from a CSV file into
Consider the following code snippet: String input = Print this; System.out.println(input.matches(\\bthis\\b)); Output false What
The following code snippet is from book Effective C#, public event AddMessageEventHandler Log; public
The following code snippet is from the Silverlight SDK and I am trying to
Look at the following code snippet: <?php class A { function fn() { print
I have the following code snippet from a HTML file: <div id=rwImages_hidden style=display:none;> <img

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.