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 1038089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:55:53+00:00 2026-05-16T14:55:53+00:00

I had this working previously, but I didn’t understand how, so I’m attempting to

  • 0

I had this working previously, but I didn’t understand how, so I’m attempting to rewrite a bit of code.

Everything seems to be going fine, except when I try to use getaddrinfo(), I’m getting back a result of -7, which translates into the error “ai_socktype not supported”.

I’m willing to bet it’s simply me still getting a handle on pointers. If someone can explain how/where I’m going wrong, I would appreciate it.

The code:

#define PORT "4400"
typedef struct {
    int port;
    fd_set *connections;
    int connections_count;
    int listener;
    struct addrinfo *address;
    struct addrinfo *socket_hints;
} Server;

void initialize_server(Server *passed_server, char *port) {
    struct addrinfo *temp;
    int status; // Get addrinfo status

    // Set up the server hints
    passed_server->socket_hints = malloc(sizeof passed_server->socket_hints);
    passed_server->socket_hints->ai_family = AF_UNSPEC;
    passed_server->socket_hints->ai_socktype = SOCK_STREAM;
    passed_server->socket_hints->ai_flags = AI_PASSIVE;

    if((status = getaddrinfo(NULL, port, passed_server->socket_hints, &temp)) != 0) {
        fprintf(stderr, "Error with getaddrinfo: %s\n", gai_strerror(status));
    }
    printf("Result: %d\n", status);
}

int main(int argc, char** argv) {
    // Set up socket stuff
    Server *server = malloc(sizeof *server); // Set up the server
    initialize_server(server, PORT);

    return (EXIT_SUCCESS);
}
  • 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-16T14:55:53+00:00Added an answer on May 16, 2026 at 2:55 pm

    After going back through the code, I realized I needed to change:

    passed_server->socket_hints = malloc(sizeof passed_server->socket_hints);
    

    to

    passed_server->socket_hints = malloc(sizeof *passed_server->socket_hints);
    

    I believe it’s because in the first one I’m getting the size of a memory location (type int). In the second one, I’m returning the sizeof the struct to which socket_hints is pointing.

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

Sidebar

Related Questions

I had this working in an old code that I didn’t end up using...
I had previously written a function that seems to work, but unfortunately I didn't
I am upgrading a project I had working previously. This code worked a few
Strangely I had this working before but I reinstalled my system, upgraded to w7
I had this sqlcmd snippet working in batch but when I converted to powershell,
So basically this code was working fine before. I had some computer issues and
I am working on this problem and had previously asked related question. Implementation of
Had this working; at one stage. The problem is the following text is now
So, thought I had this working last night, couldve sworn it. Now it no
Has anyone else had this issue and found a working solution? I've enabled 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.