LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Header Problem (https://www.linuxquestions.org/questions/linux-software-2/header-problem-637907/)

nasim751 04-25-2008 11:07 PM

Header Problem
 
hello,
I am using 2.6 Ubuntu. So i mentioned in my program #define _USE_BSD_ even though missing header information and getting this error. Can any one help me?

Quote:

‘struct tcphdr’ has no member named ‘th_flags’
tcpg.c:139: error: ‘struct tcphdr’ has no member named ‘th_flags’
tcpg.c:140: error: ‘struct tcphdr’ has no member named ‘th_seq’
tcpg.c:140: error: ‘struct tcphdr’ has no member named ‘th_seq’
tcpg.c: In function ‘tcpg_syn’:
tcpg.c:152: error: ‘struct tcphdr’ has no member named ‘th_flags’
tcpg.c:152: error: ‘struct tcphdr’ has no member named ‘th_flags’
tcpg.c:153: error: ‘struct tcphdr’ has no member named ‘th_sport’
tcpg.c:153: error: ‘struct tcphdr’ has no member named ‘th_dport’
Code:

#define TCPG_SYN

/* Log QUESO probes. */
#define TCPG_QUESO

/* SYN flooding detection. */
#define TCPG_SYNFLOOD

/* WinNuke detection. */
#define TCPG_OOB

/* Log LAND attacks. */
#define TCPG_LAND

/* Log HPing probes and port 0 connection packets. */
#define TCPG_HPING

/* Shell daemon default port probe detection. */
#define TCPG_PORTD

/* Kill connections to TCP port TCPG_KILL. */
#define TCPG_KILL        110

/* DON'T CHANGE ANYTHING BELOW THIS LINE !!!!!!!!!!!!!! */
/* DON'T CHANGE ANYTHING BELOW THIS LINE !!!!!!!!!!!!!! */
/* DON'T CHANGE ANYTHING BELOW THIS LINE !!!!!!!!!!!!!! */

/* Biggest list of includes you've ever seen, eh?! =;-) */
#include <libnet.h>
#include <syslog.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#define __USE_BSD_
#include <netinet/tcp.h>
/******************* Why not make all variables global ?!************************/
struct ippkt {
 struct iphdr ip;
 struct tcphdr tcp;
 char buffer[5000];
} pkt;

int s, lns;
struct in_addr src_addr;
u_char *buff;
u_int sport, dport;

void tcpg_syn();
void tcpg_hping();
void tcpg_synflood();
void tcpg_portd();
void tcpg_queso();
void tcpg_land();
void tcpg_oob();
void tcpg_die();
void tcpg_init();
void tcpg_kill(u_short);

problem in here...........

Code:

void tcpg_kill(u_short kport)
{
 u_long src_ip=0, dst_ip=0, ack;

 /* The following kills all TCP connections to port kport ! */
 /* WARNING: This part does not make any checks !!! */
 if(ntohs(pkt.tcp.th_dport)==kport)
 {
  sport=ntohs(pkt.tcp.th_sport);
  dport=ntohs(pkt.tcp.th_dport);
  src_ip=pkt.ip.daddr;
  dst_ip=pkt.ip.saddr;

  ack=ntohl(pkt.tcp.th_seq)+1;
  buff=malloc(TCP_H+IP_H);
  bzero(buff, TCP_H+IP_H);
  build_ip(TCP_H, IPTOS_LOWDELAY | IPTOS_THROUGHPUT, 242, 0, 64, IPPROTO_TCP, src_ip, dst_ip, NULL, 0, buff);
  build_tcp(sport, dport, ack, ack, TH_RST, 4096, 0, NULL, 0, buff+IP_H);
  do_checksum(buff, IPPROTO_TCP, TCP_H);
  lns=open_raw_sock(IPPROTO_RAW);
  syslog(LOG_INFO, "WARNING: Killing connection from %s to port %d.", inet_ntoa(src_addr), kport);
  write_ip(lns, buff, IP_H+TCP_H);
  close(lns);
 }
}


jschiwal 04-26-2008 12:28 AM

According to man feature_test_macros, there is a _BSD_SOURCE macro, but it doesn't list a _USE_BSD_ macro.

Also, I think a feature test macro should be defined before any other includes. The includes may differ depending on which you used. So some structures may be different then you want because when the include file was read in, _BSD_SOURCE wasn't defined.

The netinet/tcp.h header uses __FAVOR_BSD and not _USE_BSD_ in my version at least.
Look at your tcp.h file and see which it uses.

Using _BSD_SOURCE will define __USE_BSD.
Code:

#ifdef  _BSD_SOURCE
# define __USE_BSD      1
#endif

and __FAVOR_BSD:
Code:

/* If _BSD_SOURCE was defined by the user, favor BSD over POSIX.  */
#if defined _BSD_SOURCE && \
    !(defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || \
      defined _XOPEN_SOURCE || defined _XOPEN_SOURCE_EXTENDED || \
      defined _GNU_SOURCE || defined _SVID_SOURCE)
# define __FAVOR_BSD    1
#endif

So defining _BSD_SOURCE at the beginning of your program may fix your problem.


All times are GMT -5. The time now is 06:48 AM.