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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:57:38+00:00 2026-05-16T15:57:38+00:00

Good evening, everyone. I’ve now run into an odd warning, and for the life

  • 0

Good evening, everyone.

I’ve now run into an odd warning, and for the life of me I can’t figure out where it’s going wrong. I’ve tried so many different options I can’t remember.

The error is:

assignment from incompatible pointer type

Relative code:

// Server structure
typedef struct {
    struct addrinfo address;        // Address info
    char buffer[1024];              // Read biffer
    fd_set connections;             // Current connections
    int connections_max;            // Max file descriptor
    int listener;                   // Listener fd
    int port;                       // The port for the server to listen on
    struct addrinfo socket_hints;   // Server's socket hints
    struct timeval socket_timeout;  // When should the socket timeout?
    struct User *users;             // Currently connected users
} Server;

// User structure
typedef struct {
    struct sockaddr_storage address;    // User's address
    socklen_t address_length;           // Length of users address
    int fs_id;                          // ID to the socket they belong to
    char ip_address[INET6_ADDRSTRLEN];  // User's IP address
    char *name;                         // Pointer to the user's name
    struct User *nextUser;              // Next user in the list
} User;

/**
 * Handles sockets on the provided server
 */
void handle_sockets(Server *passed_server) {
    int current_fd;             // Current file descriptor
    int new_connection;         // Socket ID of new connections
    fd_set read_sockets;        // Sockets to read from
    FD_ZERO(&read_sockets);
    struct timeval timeout;     // Sets the timeout for select 

    // See if we have sockets to read
    read_sockets = passed_server->connections;
    timeout = passed_server->socket_timeout;
    if(select(passed_server->connections_max+1, &read_sockets, NULL, NULL, &timeout) == -1) {
        perror("Selecting sockets");
        exit(1);
    }

    // Loop through all of the sockets
    for(current_fd = 0; current_fd <= passed_server->connections_max; current_fd++) {
        if(!FD_ISSET(current_fd, &read_sockets)) {
            continue;
        }

        // Handle new connection
        if(current_fd == passed_server->listener) {
            User *new_user = malloc(sizeof *new_user); 
            memset(&new_user->address, 0, sizeof new_user->address);

            // Get the new address
            new_user->address_length = sizeof new_user->address;
            new_user->fs_id = accept(passed_server->listener, (struct sockaddr *)&new_user->address, &new_user->address_length);

            // Did we have an issue connecting?
            if(new_user->fs_id == -1) {
                free(new_user);
                perror("Accepting new connection");
                continue;
            }

            // Add the user socket to the master list
            FD_SET(new_user->fs_id, &passed_server->connections);
            if(new_user->fs_id > passed_server->connections_max) {
                passed_server->connections_max = new_user->fs_id;
            }

            // Add the user to the list

            //*******************
            // ERRORS IN THE NEXT TWO ASSIGNMENTS
            //*******************

            if(passed_server->users == NULL) {
                passed_server->users = new_user;
            } else {
                new_user->nextUser = passed_server->users;
                passed_server->users = new_user;
            }

            // Let them know we got one!
            printf("Server: New connection from %s on socket %d. Send hello.\n",
                    inet_ntop(
                            new_user->address.ss_family, 
                            get_address((struct sockaddr*)&new_user->address),
                            new_user->ip_address,
                            INET6_ADDRSTRLEN
                    ),
                    new_user->fs_id
            );

            // Can we get to the user from the server?
            //printf("Repeat, the IP address is %s\n", passed_server->users->ip_address);

            // Move on to the next file descriptor
            continue;
        }
    }
}

Full Code

  • 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-16T15:57:38+00:00Added an answer on May 16, 2026 at 3:57 pm
    typedef struct User {
        struct sockaddr_storage address;    // User's address
        socklen_t address_length;           // Length of users address
        int fs_id;                          // ID to the socket they belong to
        char ip_address[INET6_ADDRSTRLEN];  // User's IP address
        char *name;                         // Pointer to the user's name
        struct User *nextUser;              // Next user in the list
    } User;
    

    Add the “struct User” at the top so that you can reference it within the struct.

    Also, you need to swap the order of your declarations so that the Server struct knows about the User struct.

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

Sidebar

Related Questions

Good Evening everyone, I've been trying to figure out the most efficient way to
Good evening guys, how can I run a piece of jQuery/ajax when a certain
Good evening everyone, I was hoping you could help with an Objective-C question I
Good evening everyone. I am puzzling over the oddity that the jQuery Marquee plugin
Good evening, i hope you can help me with this problem, as I'm struggling
Good Evening (depending on where u are right now). I am a little confused
Good evening everyone, I am using a JavaScript to load/override content from an HTML-File
Good evening everyone. I'm having trouble creating a TFTP client for an assignment in
Good evening. I am doing a basic exercise to insert data into an Access
Good Evening StackOverflowers! I am running into what seems to be a catch 22

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.