0

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 :)

2 Answers 2

4
  • 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
5
  • @Woodrow Douglas thanks to both of you! The thing is though, I had already included <netinet/tcp.h>. I'm using Backtrack5, is it possible that the header files are different? Jul 27, 2012 at 14:07
  • Just did and it gives me this: ./dumbnet/tcp.h:#define TH_SYN 0x02 /* synchronize sequence numbers */ ./netinet/tcp.h:# define TH_SYN 0x02 I don't suppose the space between # and define in netinet is the problem? Jul 27, 2012 at 15:49
  • @youjustreadthis Maybe you're including netinet/tcp.h too "late".
    – cnicutar
    Jul 27, 2012 at 15:50
  • right at the top of the code along with all the other header files. Jul 27, 2012 at 15:58
  • nevermind, I'll create a separate question if I don't figure it out later today. thanks for the help =P Jul 27, 2012 at 16:42
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.