简体   繁体   English

编译错误问题

[英]Trouble with compiling errors

I am getting some compilation errors I can't figure out, and although I'm sure they're quite stupid I can't find an answer that helps me much through other channels. 我遇到了一些我无法弄清的编译错误,尽管我确信它们很愚蠢,但我找不到其他途径可以帮助我的答案。

Problem 1: (These are a part of a TCP protocol) 问题1 :(这些是TCP协议的一部分)

error: ‘TH_SYN’ undeclared (first use in this function)
error: ‘TH_ACK’ undeclared (first use in this function)

tcp.tcph_flags = TH_SYN;
tcp.tcph_flags = TH_ACK;

Problem 2: 问题2:

error: conversion to non-scalar type requested

const int one = 1;
char buffer[PCKT_LEN];
struct sockaddr_in sin;
struct ipheader ip;
struct tcpheader tcp;

ip = (struct ipheader) buffer;                      /* ERROR POINTS HERE */
tcp = (struct tcpheader) buffer + ip.iph_ihl *4;    /* AND HERE */

Problem 3: 问题三:

warning: assignment makes integer from pointer without a cast

case 'i': dip = inet_addr(optarg);
          dstip = (optarg);  /* ERROR POINTS TO THIS LINE */
          break;

Now I hope I've copied enough relevant information on the errors for you to be able to help, but if I've left something out let me know. 现在,我希望我已经复制了足够的有关错误的信息,以便为您提供帮助,但是如果我遗漏了一些信息,请告诉我。 For problem 1, I believe I am missing a header file of some sort but I don't know which. 对于问题1,我相信我缺少某种头文件,但我不知道该头文件。 Problem 2 and 3 are pointer issues, but I'm not sure why they aren't correct. 问题2和3是指针问题,但是我不确定为什么它们不正确。 Thanks in advance :) 提前致谢 :)

  • For the first problem, include the header defining TH_SYN and TH_ACK . 对于第一个问题,包括定义TH_SYNTH_ACK的标头。 On my system it's netinet/tcp.h 在我的系统上是netinet/tcp.h
  • For the second problem, turn ipheader and tcpheader into pointers 对于第二个问题,将ipheadertcpheader转换为指针
  • For the third problem I think you need a strtoul but I'm unsure 对于第三个问题,我想你需要一个strtoul ,但我不能确定

For problem 1, you need 对于问题1,您需要

#include <netinet/tcp.h>

For problem 2, struct ipheader should be struct ipheader * in both your declaration and cast, as well as struct tcpheader should be struct tcpheader * 对于问题2, struct ipheader应该是struct ipheader *在你的宣言,并投两个,以及struct tcpheader应该是struct tcpheader *

For problem 3, optarg is a pointer, and needs to be dereferenced, so refer to it as *optarg 对于问题3,optarg是一个指针,需要取消引用,因此将其称为*optarg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM