简体   繁体   中英

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)

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:

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. Problem 2 and 3 are pointer issues, but I'm not sure why they aren't correct. Thanks in advance :)

  • For the first problem, include the header defining TH_SYN and TH_ACK . On my system it's netinet/tcp.h
  • For the second problem, turn ipheader and tcpheader into pointers
  • For the third problem I think you need a strtoul but I'm unsure

For problem 1, you need

#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 *

For problem 3, optarg is a pointer, and needs to be dereferenced, so refer to it as *optarg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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