SOCKADDR_IN未声明的标识符 [英] sockaddr_in undeclared identifier

查看:4430
本文介绍了SOCKADDR_IN未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与beej指南联网沿以下,这已经持续真的很棒,因为我明白一切非常好,他解释它的伟大。然而,当我想测试出一些很酷的事情他向我展示,它不会工作! (

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!. :(

我不知道哪儿SOCKADDR_IN声明,但也许有人会在这里这么帮我出去!

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

下面是我到目前为止(测试出字符串形式的IP转换为IP为4个字节组成,反之亦然):

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!

编辑:我在一个叫薄荷的Linux发行版Debian的,是否可以帮助在所有

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

推荐答案

标准说:

头应规定SOCKADDR_IN结构

The header shall define the sockaddr_in structure

您必须包括&LT; netinet / in.h中&GT; 并声明是这样的:

You have to include <netinet/in.h> and declare sin like this:

struct sockaddr_in sin;
^^^^^^

要找出原因,你所需要的结构关键字,请参阅本 ç常见问题解答。长话短说,没有任何隐含的的typedef 用C

To find out why you need the struct keyword, see this C FAQ. Long story short, there's no implicit typedef in C.

这篇关于SOCKADDR_IN未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆