2006.04.11 21:13
trying to compile tcpdstat

Recently I tried to compile tcpdstat tool, which is a part of tcpd-tools-0.9. It didn't compile, giving such errors:

$ make
cc -g -Wall -I.  -DINET6 -c stat.c
stat.c: In function 'main':
stat.c:123: warning: implicit declaration of function 'strcmp'
stat.c: In function 'show_stat':
stat.c:264: warning: implicit declaration of function 'localtime'
stat.c:264: warning: assignment makes pointer from integer without a cast
stat.c:265: error: dereferencing pointer to incomplete type
stat.c:265: error: dereferencing pointer to incomplete type
stat.c:266: error: dereferencing pointer to incomplete type
stat.c:266: error: dereferencing pointer to incomplete type
stat.c:266: error: dereferencing pointer to incomplete type
stat.c:267: warning: implicit declaration of function 'ctime'
stat.c:267: warning: format '%s' expects type 'char *', but argument 2 has type 'int'
stat.c:269: warning: format '%s' expects type 'char *', but argument 2 has type 'int'
make: *** [stat.o] Error 1

And such ones:

$ make
cc -g -Wall -I.  -DINET6 -c net_read.c
net_read.c:140: error: static declaration of 'packet_length' follows non-static declaration
tcpdstat.h:74: error: previous declaration of 'packet_length' was here
net_read.c: In function 'ether_encap_read':
net_read.c:316: error: 'ETHERTYPE_IPV6' undeclared (first use in this function)
net_read.c:316: error: (Each undeclared identifier is reported only once
net_read.c:316: error: for each function it appears in.)
net_read.c: In function 'atm_if_read':
net_read.c:435: error: 'ETHERTYPE_IPV6' undeclared (first use in this function)
net_read.c: In function 'ip_read':
net_read.c:553: error: 'struct tcphdr' has no member named 'th_sport'
net_read.c:554: error: 'struct tcphdr' has no member named 'th_dport'
net_read.c:562: error: 'struct udphdr' has no member named 'uh_sport'
net_read.c:563: error: 'struct udphdr' has no member named 'uh_dport'
net_read.c: In function 'ip6_read':
net_read.c:650: error: 'struct tcphdr' has no member named 'th_sport'
net_read.c:651: error: 'struct tcphdr' has no member named 'th_dport'
net_read.c:659: error: 'struct udphdr' has no member named 'uh_sport'
net_read.c:660: error: 'struct udphdr' has no member named 'uh_dport'
net_read.c: In function 'ip4f_cache':
net_read.c:875: error: 'struct udphdr' has no member named 'uh_sport'
net_read.c:875: error: 'struct udphdr' has no member named 'uh_sport'
net_read.c:876: error: 'struct udphdr' has no member named 'uh_dport'
net_read.c:876: error: 'struct udphdr' has no member named 'uh_dport'
net_read.c: In function 'ip4f_lookup':
net_read.c:885: warning: implicit declaration of function 'TAILQ_FIRST'
net_read.c:885: warning: assignment makes pointer from integer without a cast
net_read.c:886: warning: implicit declaration of function 'TAILQ_NEXT'
net_read.c:886: error: 'ip4f_chain' undeclared (first use in this function)
net_read.c:886: warning: assignment makes pointer from integer without a cast
make: *** [net_read.o] Error 1

etc. So I did such changes to sources:

diff -c --unidirectional-new-file tcpdstat.OLD/ethertype.h tcpdstat.NEW/ethertype.h
*** tcpdstat.OLD/ethertype.h	Thu Jan  1 01:00:00 1970
--- tcpdstat.NEW/ethertype.h	Tue Apr 11 20:25:18 2006
***************
*** 0 ****
--- 1,113 ----
+ /*
+  * Copyright (c) 1993, 1994, 1996
+  *	The Regents of the University of California.  All rights reserved.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that: (1) source code distributions
+  * retain the above copyright notice and this paragraph in its entirety, (2)
+  * distributions including binary code include the above copyright notice and
+  * this paragraph in its entirety in the documentation or other materials
+  * provided with the distribution, and (3) all advertising materials mentioning
+  * features or use of this software display the following acknowledgement:
+  * ``This product includes software developed by the University of California,
+  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+  * the University nor the names of its contributors may be used to endorse
+  * or promote products derived from this software without specific prior
+  * written permission.
+  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+  *
+  * @(#) $Header$ (LBL)
+  */
+ 
+ /*
+  * Ethernet types.
+  *
+  * We wrap the declarations with #ifdef, so that if a file includes
+  * , which may declare some of these, we don't
+  * get a bunch of complaints from the C compiler about redefinitions
+  * of these values.
+  *
+  * We declare all of them here so that no file has to include
+  *  if all it needs are ETHERTYPE_ values.
+  */
+ 
+ #ifndef ETHERTYPE_PUP
+ #define	ETHERTYPE_PUP		0x0200	/* PUP protocol */
+ #endif
+ #ifndef ETHERTYPE_IP
+ #define	ETHERTYPE_IP		0x0800	/* IP protocol */
+ #endif
+ #ifndef ETHERTYPE_ARP
+ #define ETHERTYPE_ARP		0x0806	/* Addr. resolution protocol */
+ #endif
+ #ifndef ETHERTYPE_REVARP
+ #define ETHERTYPE_REVARP	0x8035	/* reverse Addr. resolution protocol */
+ #endif
+ #ifndef ETHERTYPE_NS
+ #define ETHERTYPE_NS		0x0600
+ #endif
+ #ifndef	ETHERTYPE_SPRITE
+ #define	ETHERTYPE_SPRITE	0x0500
+ #endif
+ #ifndef ETHERTYPE_TRAIL
+ #define ETHERTYPE_TRAIL		0x1000
+ #endif
+ #ifndef	ETHERTYPE_MOPDL
+ #define	ETHERTYPE_MOPDL		0x6001
+ #endif
+ #ifndef	ETHERTYPE_MOPRC
+ #define	ETHERTYPE_MOPRC		0x6002
+ #endif
+ #ifndef	ETHERTYPE_DN
+ #define	ETHERTYPE_DN		0x6003
+ #endif
+ #ifndef	ETHERTYPE_LAT
+ #define	ETHERTYPE_LAT		0x6004
+ #endif
+ #ifndef ETHERTYPE_SCA
+ #define ETHERTYPE_SCA		0x6007
+ #endif
+ #ifndef ETHERTYPE_REVARP
+ #define ETHERTYPE_REVARP	0x8035
+ #endif
+ #ifndef	ETHERTYPE_LANBRIDGE
+ #define	ETHERTYPE_LANBRIDGE	0x8038
+ #endif
+ #ifndef	ETHERTYPE_DECDNS
+ #define	ETHERTYPE_DECDNS	0x803c
+ #endif
+ #ifndef	ETHERTYPE_DECDTS
+ #define	ETHERTYPE_DECDTS	0x803e
+ #endif
+ #ifndef	ETHERTYPE_VEXP
+ #define	ETHERTYPE_VEXP		0x805b
+ #endif
+ #ifndef	ETHERTYPE_VPROD
+ #define	ETHERTYPE_VPROD		0x805c
+ #endif
+ #ifndef ETHERTYPE_ATALK
+ #define ETHERTYPE_ATALK		0x809b
+ #endif
+ #ifndef ETHERTYPE_AARP
+ #define ETHERTYPE_AARP		0x80f3
+ #endif
+ #ifndef ETHERTYPE_8021Q
+ #define ETHERTYPE_8021Q		0x8100
+ #endif
+ #ifndef ETHERTYPE_IPX
+ #define ETHERTYPE_IPX		0x8137
+ #endif
+ #ifndef ETHERTYPE_IPV6
+ #define ETHERTYPE_IPV6		0x86dd
+ #endif
+ #ifndef ETHERTYPE_MPLS
+ #define ETHERTYPE_MPLS          0x8847
+ #endif
+ #ifndef ETHERTYPE_MPLS_MULTI
+ #define ETHERTYPE_MPLS_MULTI    0x8848
+ #endif
+ #ifndef	ETHERTYPE_LOOPBACK
+ #define	ETHERTYPE_LOOPBACK	0x9000
+ #endif
diff -c --unidirectional-new-file tcpdstat.OLD/ip_flow.c tcpdstat.NEW/ip_flow.c
*** tcpdstat.OLD/ip_flow.c	Mon Mar 26 08:48:56 2001
--- tcpdstat.NEW/ip_flow.c	Tue Apr 11 21:02:41 2006
***************
*** 42,47 ****
--- 42,51 ----
  #include 
  #include "tcpdstat.h"
  
+ #define LIST_FIRST(head)        ((head)->lh_first)
+ #define LIST_NEXT(elm, field)   ((elm)->field.le_next)
+ 
+ 
  struct flow {
  	int flow_af;		/* address family */
  	union {
diff -c --unidirectional-new-file tcpdstat.OLD/net_read.c tcpdstat.NEW/net_read.c
*** tcpdstat.OLD/net_read.c	Mon Mar 26 09:24:12 2001
--- tcpdstat.NEW/net_read.c	Tue Apr 11 21:05:21 2006
***************
*** 67,73 ****
  #include 
  #include 
  #include 
! #include 
  #include 
  #include 
  #include 
--- 67,73 ----
  #include 
  #include 
  #include 
! #include "tcp.h"
  #include 
  #include 
  #include 
***************
*** 87,92 ****
--- 87,93 ----
  #include 
  #endif
  #include "tcpdstat.h"
+ #include "ethertype.h"
  
  #define	NULL_HDRLEN 4	/* DLT_NULL header length */
  
***************
*** 102,107 ****
--- 103,111 ----
  #undef TAILQ_LAST
  #define	TAILQ_LAST(head, headname) \
  	(*(((struct headname *)((head)->tqh_last))->tqh_last))
+ #define TAILQ_FIRST(head)       ((head)->tqh_first)
+ #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+ 
  
  void net_read(int clientdata, int mask);
  static void dump_reader(u_char *user, const struct
diff -c --unidirectional-new-file tcpdstat.OLD/stat.c tcpdstat.NEW/stat.c
*** tcpdstat.OLD/stat.c	Mon Mar 26 09:24:11 2001
--- tcpdstat.NEW/stat.c	Tue Apr 11 20:13:30 2006
***************
*** 41,46 ****
--- 41,49 ----
  #include 
  #include 
  
+ #include 
+ #include 
+ 
  #include "tcpdstat.h"
  
  struct timeval start_time, end_time;
diff -c --unidirectional-new-file tcpdstat.OLD/tcp.h tcpdstat.NEW/tcp.h
*** tcpdstat.OLD/tcp.h	Thu Jan  1 01:00:00 1970
--- tcpdstat.NEW/tcp.h	Tue Apr 11 20:50:02 2006
***************
*** 0 ****
--- 1,225 ----
+ /*
+  * Copyright (c) 1982, 1986, 1993
+  *	The Regents of the University of California.  All rights reserved.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *    notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  * 4. Neither the name of the University nor the names of its contributors
+  *    may be used to endorse or promote products derived from this software
+  *    without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  * SUCH DAMAGE.
+  *
+  *	@(#)tcp.h	8.1 (Berkeley) 6/10/93
+  */
+ 
+ #ifndef _NETINET_TCP_H
+ #define _NETINET_TCP_H	1
+ 
+ #include 
+ #define __FAVOR_BSD
+ /*
+  * User-settable options (used with setsockopt).
+  */
+ #define	TCP_NODELAY	 1	/* Don't delay send to coalesce packets  */
+ #define	TCP_MAXSEG	 2	/* Set maximum segment size  */
+ #define TCP_CORK	 3	/* Control sending of partial frames  */
+ #define TCP_KEEPIDLE	 4	/* Start keeplives after this period */
+ #define TCP_KEEPINTVL	 5	/* Interval between keepalives */
+ #define TCP_KEEPCNT	 6	/* Number of keepalives before death */
+ #define TCP_SYNCNT	 7	/* Number of SYN retransmits */
+ #define TCP_LINGER2	 8	/* Life time of orphaned FIN-WAIT-2 state */
+ #define TCP_DEFER_ACCEPT 9	/* Wake up listener only when data arrive */
+ #define TCP_WINDOW_CLAMP 10	/* Bound advertised window */
+ #define TCP_INFO	 11	/* Information about this connection. */
+ #define	TCP_QUICKACK	 12	/* Bock/reenable quick ACKs.  */
+ 
+ #ifdef __USE_MISC
+ # include 
+ 
+ # ifdef __FAVOR_BSD
+ typedef	u_int32_t tcp_seq;
+ /*
+  * TCP header.
+  * Per RFC 793, September, 1981.
+  */
+ struct tcphdr
+   {
+     u_int16_t th_sport;		/* source port */
+     u_int16_t th_dport;		/* destination port */
+     tcp_seq th_seq;		/* sequence number */
+     tcp_seq th_ack;		/* acknowledgement number */
+ #  if __BYTE_ORDER == __LITTLE_ENDIAN
+     u_int8_t th_x2:4;		/* (unused) */
+     u_int8_t th_off:4;		/* data offset */
+ #  endif
+ #  if __BYTE_ORDER == __BIG_ENDIAN
+     u_int8_t th_off:4;		/* data offset */
+     u_int8_t th_x2:4;		/* (unused) */
+ #  endif
+     u_int8_t th_flags;
+ #  define TH_FIN	0x01
+ #  define TH_SYN	0x02
+ #  define TH_RST	0x04
+ #  define TH_PUSH	0x08
+ #  define TH_ACK	0x10
+ #  define TH_URG	0x20
+     u_int16_t th_win;		/* window */
+     u_int16_t th_sum;		/* checksum */
+     u_int16_t th_urp;		/* urgent pointer */
+ };
+ 
+ # else /* !__FAVOR_BSD */
+ struct tcphdr
+   {
+     u_int16_t source;
+     u_int16_t dest;
+     u_int32_t seq;
+     u_int32_t ack_seq;
+ #  if __BYTE_ORDER == __LITTLE_ENDIAN
+     u_int16_t res1:4;
+     u_int16_t doff:4;
+     u_int16_t fin:1;
+     u_int16_t syn:1;
+     u_int16_t rst:1;
+     u_int16_t psh:1;
+     u_int16_t ack:1;
+     u_int16_t urg:1;
+     u_int16_t res2:2;
+ #  elif __BYTE_ORDER == __BIG_ENDIAN
+     u_int16_t doff:4;
+     u_int16_t res1:4;
+     u_int16_t res2:2;
+     u_int16_t urg:1;
+     u_int16_t ack:1;
+     u_int16_t psh:1;
+     u_int16_t rst:1;
+     u_int16_t syn:1;
+     u_int16_t fin:1;
+ #  else
+ #   error "Adjust your  defines"
+ #  endif
+     u_int16_t window;
+     u_int16_t check;
+     u_int16_t urg_ptr;
+ };
+ # endif /* __FAVOR_BSD */
+ 
+ enum
+ {
+   TCP_ESTABLISHED = 1,
+   TCP_SYN_SENT,
+   TCP_SYN_RECV,
+   TCP_FIN_WAIT1,
+   TCP_FIN_WAIT2,
+   TCP_TIME_WAIT,
+   TCP_CLOSE,
+   TCP_CLOSE_WAIT,
+   TCP_LAST_ACK,
+   TCP_LISTEN,
+   TCP_CLOSING   /* now a valid state */
+ };
+ 
+ # define TCPOPT_EOL		0
+ # define TCPOPT_NOP		1
+ # define TCPOPT_MAXSEG		2
+ # define TCPOLEN_MAXSEG		4
+ # define TCPOPT_WINDOW		3
+ # define TCPOLEN_WINDOW		3
+ # define TCPOPT_SACK_PERMITTED	4		/* Experimental */
+ # define TCPOLEN_SACK_PERMITTED	2
+ # define TCPOPT_SACK		5		/* Experimental */
+ # define TCPOPT_TIMESTAMP	8
+ # define TCPOLEN_TIMESTAMP	10
+ # define TCPOLEN_TSTAMP_APPA	(TCPOLEN_TIMESTAMP+2) /* appendix A */
+ 
+ # define TCPOPT_TSTAMP_HDR	\
+     (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
+ 
+ /*
+  * Default maximum segment size for TCP.
+  * With an IP MSS of 576, this is 536,
+  * but 512 is probably more convenient.
+  * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
+  */
+ # define TCP_MSS	512
+ 
+ # define TCP_MAXWIN	65535	/* largest value for (unscaled) window */
+ 
+ # define TCP_MAX_WINSHIFT	14	/* maximum window shift */
+ 
+ # define SOL_TCP		6	/* TCP level */
+ 
+ 
+ # define TCPI_OPT_TIMESTAMPS	1
+ # define TCPI_OPT_SACK		2
+ # define TCPI_OPT_WSCALE	4
+ # define TCPI_OPT_ECN		8
+ 
+ /* Values for tcpi_state.  */
+ enum tcp_ca_state
+ {
+   TCP_CA_Open = 0,
+   TCP_CA_Disorder = 1,
+   TCP_CA_CWR = 2,
+   TCP_CA_Recovery = 3,
+   TCP_CA_Loss = 4
+ };
+ 
+ struct tcp_info
+ {
+   u_int8_t	tcpi_state;
+   u_int8_t	tcpi_ca_state;
+   u_int8_t	tcpi_retransmits;
+   u_int8_t	tcpi_probes;
+   u_int8_t	tcpi_backoff;
+   u_int8_t	tcpi_options;
+   u_int8_t	tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
+ 
+   u_int32_t	tcpi_rto;
+   u_int32_t	tcpi_ato;
+   u_int32_t	tcpi_snd_mss;
+   u_int32_t	tcpi_rcv_mss;
+ 
+   u_int32_t	tcpi_unacked;
+   u_int32_t	tcpi_sacked;
+   u_int32_t	tcpi_lost;
+   u_int32_t	tcpi_retrans;
+   u_int32_t	tcpi_fackets;
+ 
+   /* Times. */
+   u_int32_t	tcpi_last_data_sent;
+   u_int32_t	tcpi_last_ack_sent;	/* Not remembered, sorry.  */
+   u_int32_t	tcpi_last_data_recv;
+   u_int32_t	tcpi_last_ack_recv;
+ 
+   /* Metrics. */
+   u_int32_t	tcpi_pmtu;
+   u_int32_t	tcpi_rcv_ssthresh;
+   u_int32_t	tcpi_rtt;
+   u_int32_t	tcpi_rttvar;
+   u_int32_t	tcpi_snd_ssthresh;
+   u_int32_t	tcpi_snd_cwnd;
+   u_int32_t	tcpi_advmss;
+   u_int32_t	tcpi_reordering;
+ };
+ 
+ #endif /* Misc.  */
+ 
+ #endif /* netinet/tcp.h */
diff -c --unidirectional-new-file tcpdstat.OLD/tcpdstat.h tcpdstat.NEW/tcpdstat.h
*** tcpdstat.OLD/tcpdstat.h	Mon Mar 26 09:29:36 2001
--- tcpdstat.NEW/tcpdstat.h	Tue Apr 11 21:05:27 2006
***************
*** 71,77 ****
  extern int read_count;
  extern struct timeval start_time, end_time;
  extern struct pkt_cnt tcpdstat[PROTOTYPE_MAX];
! extern int packet_length;
  extern int caplen_total;
  extern int caplen_max;
  extern int use_ipflow;
--- 71,77 ----
  extern int read_count;
  extern struct timeval start_time, end_time;
  extern struct pkt_cnt tcpdstat[PROTOTYPE_MAX];
! //extern int packet_length;
  extern int caplen_total;
  extern int caplen_max;
  extern int use_ipflow;

Seems it works. The code compiles and seems to somehow work. Hope it will be useful to somebody.



komentarze:

ksywa:

tu wpisz cyfrę cztery: (tu wpisz cyfrę cztery: (to takie zabezpieczenie antyspamowe))

komentarze wulgarne albo co mi się nie spodobają będę kasował


powrót na stronę główną

RSS