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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:14:59+00:00 2026-05-30T14:14:59+00:00

I am trying to learn the basics of socket programming and am using some

  • 0

I am trying to learn the basics of socket programming and am using some code from a guide I found but I am getting compile errors. The code and errors are shown below

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

#define PORT "21467"

int main(void)
{
int status;
struct addrinfo hints;
struct addrinfo *servinfo; // will point to the results
memset(&hints, 0, sizeof hints); // make sure the struct is empty

hints.ai_family = AF_INET; 
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
hints.ai_flags = AI_PASSIVE; // fill in my IP for me

if ((status = getaddrinfo(NULL, PORT, &hints, &servinfo)) != 0) {
    //fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
    exit(1);
}
// servinfo now points to a linked list of 1 or more struct addrinfos
// ... do everything until you don't need servinfo anymore ....
freeaddrinfo(servinfo); // free the linked-list

return 0;
}

Compile errors:

server.c: In function 'main':
server.c:16: warning: incompatible implicit declaration of built-in function 'memset'
server.c:24: warning: incompatible implicit declaration of built-in function 'exit'
Undefined                       first referenced
 symbol                             in file
getaddrinfo                         /var/tmp//ccU0yRDe.o
freeaddrinfo                        /var/tmp//ccU0yRDe.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

Any help would be greatly appreciated!

  • 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-30T14:15:01+00:00Added an answer on May 30, 2026 at 2:15 pm

    If you do a man memset, you will see that the manual page says #include <string.h> is required. Just put that at the top of the file. Do the same for exit

    EDIT

    Need -lnsl -lsocket for the linking (assuming linux)

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

Sidebar

Related Questions

I'm trying to learn jquery, I've some basics of javascript. I've written this piece
I'm trying to learn some basic regular expression and having a hard time getting
I'm trying to learn some basics of Ruby on Rails and encountered a problem
I'm trying to learn the basics of C++ by going through some Project Euler
I am trying to learn the basics of C, C++ programming, so I've started
I'm trying to learn some of the basics of developing OS X apps with
I'm starting to learn socket.io and node.js I'm trying to do some pretty basic
I'm trying to learn some basics of boost serialization. So I followed the tutorial
I'm from a Java/PHP background and I'm trying to learn Rails, but I'm finding
Ok, so I'm trying to learn gdb. I know most of the basics but

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.