Alex Rivera | Logout

sockaddr_in undeclared identifier

Asked 2012-02-01T20:03:44.327
13

I am following along with beej's guide to networking and it's been going REALLY good because I understand everything very well and he explains it great. however, when I want to test out some of the cool things he's showing me, it won't work!. :(

I am not sure where exactly sockaddr_in is declared but maybe somebody here will so help me out!

Here is what I have so far (testing out converting an ip in string form to an ip to a 4 byte integral and vice versa):

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

int main(void)
{
  sockaddr_in sin;

  inet_pton(AF_INET, "192.168.2.1", &sin.in_addr);
  char ip[INET_ADDRSTRLEN];
  inet_ntop(AF_INET, &sin.in_addr, ip, INET_ADDRSTRLEN);
  printf("%s\n", ip);

  return 0;
}

Again I am completely clueless as to where everything is so if it's something really stupid on my part, sorry!

Edit: I'm on a Linux Debian distro called Mint if that helps at all?

Edit
Report

1 Answer

6

According to ip(7) man page, you also need

   #include <sys/socket.h>
   #include <netinet/in.h>
   #include <netinet/ip.h> 
answered 2012-02-01T20:08:14.483

Your Answer