Getting the following errors in my program

/var/tmp//ccI1DooE.o(.text+0x102): In function `main':
: undefined reference to `copy_argv'
/var/tmp//ccI1DooE.o(.text+0x144): In function `main':
: undefined reference to `error'
/var/tmp//ccI1DooE.o(.text+0x190): In function `main':
: undefined reference to `error'
/var/tmp//ccI1DooE.o(.text+0x1c2): In function `main':
: undefined reference to `warning'
/var/tmp//ccI1DooE.o(.text+0x20b): In function `main':
: undefined reference to `warning'
/var/tmp//ccI1DooE.o(.text+0x258): In function `main':
: undefined reference to `error'
/var/tmp//ccI1DooE.o(.text+0x267): In function `main':
: undefined reference to `setsignal'
/var/tmp//ccI1DooE.o(.text+0x276): In function `main':
: undefined reference to `setsignal'
/var/tmp//ccI1DooE.o(.text+0x285): In function `main':
: undefined reference to `setsignal'
/var/tmp//ccI1DooE.o(.text+0x29e): In function `main':
: undefined reference to `setsignal'
/var/tmp//ccI1DooE.o(.text+0x2d0): In function `main':
: undefined reference to `error'


#define RETSIGTYPE void
#include <sys/types.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <pcap.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#ifndef setsignal_h
#define setsignal_h

RETSIGTYPE (*setsignal(int, RETSIGTYPE (*)(int)))(int);
#endif

/* Ethernet addresses are 6 bytes */
#define ETHER_ADDR_LEN 6
#define SIZE_ETHERNET 14
#define SIZE_IPHDR 20

/* Ethernet header */
struct sniff_ethernet {
u_char ether_dhost[ETHER_ADDR_LEN]; /* Destination host address */
u_char ether_shost[ETHER_ADDR_LEN]; /* Source host address */
u_short ether_type; /* IP? ARP? RARP? etc */
};

/* ARP packet */
struct sniff_arp {
u_short arp_hwtype;
u_short arp_proto;
u_char arp_addrlen;
u_char arp_protolen;
u_short arp_operation;
u_char arp_src[6];
u_char arp_src_proto_addr[4];
u_char arp_dst[6];
u_char arp_dst_proto_addr[4];
};

/* IP header */
struct sniff_ip {
u_char ip_vhl; /* version << 4 | header length >> 2 */
u_char ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off; /* fragment offset field */
#define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
u_char ip_src[4]; /* source port */
u_char ip_dst[4]; /* destination port */
// struct in_addr ip_src,ip_dst; /* source and dest address */
};

/* ICMP packet */
struct sniff_icmp {
u_char icmp_type;
u_char icmp_code;
u_short icmp_sum;
};

#define IP_HL(ip) (((ip)->ip_vhl) & 0x0f)
#define IP_V(ip) (((ip)->ip_vhl) >> 4)

/* TCP header */
struct sniff_tcp {
u_short srcprt; /* source port */
u_short destprt; /* destination port */
u_int seq; /* sequence number */
u_int ack; /* acknowledgement number */
u_char hdrlen; /* data offset, rsvd */
#define TH_OFF(th) (((th)->th_offx2 & 0xf0) >> 4)
u_char 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
#define TH_ECE 0x40
#define TH_CWR 0x80
#define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
u_short win; /* window */
u_short sum; /* checksum */
u_short urp; /* urgent pointer */
};

/* UDP header */
struct sniff_udp {
u_short udp_srcprt;
u_short udp_destprt;
u_short udp_len;
u_short udp_sum;
};

/* DNS header */
struct sniff_dns {
u_short id;
u_short flags;
u_short numQuestions;
u_short numAnswers;
u_short numAA;
u_short numAddRecs;
};

int nPackets = 1;
int nARP = 0;
int nIP = 0;
int nBroadcast = 0;
int nICMP = 0;
int nTCP = 0;
int nDNS = 0;
int nUDP = 0;
int nPOP = 0;
int nSMTP = 0;
int nIMAP = 0;
int nHTML = 0;

char cpre580f98[] = "netdump";

void raw_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p);

int packettype;

char *program_name;

/* Externs */
extern void bpf_dump(struct bpf_program *, int);

extern char *copy_argv(char **);

/* Forwards */
void program_ending(int);

/* Length of saved portion of packet. */
int snaplen = 1500;;

static pcap_t *pd;

extern int optind;
extern int opterr;
extern char *optarg;
int pflag = 0, aflag = 0;

int
main(int argc, char **argv)
{
int cnt, op, i, done = 0;
bpf_u_int32 localnet, netmask;
char *cp, *cmdbuf, *device;
struct bpf_program fcode;
void (*oldhandler)(int);
u_char *pcap_userdata;
char ebuf[PCAP_ERRBUF_SIZE];

cnt = -1;
device = NULL;

if ((cp = strrchr(argv[0], '/')) != NULL)
program_name = cp + 1;
else
program_name = argv[0];

opterr = 0;
while ((i = getopt(argc, argv, "pa")) != -1)
{
switch (i)
{
case 'p':
pflag = 1;
break;
case 'a':
aflag = 1;
break;
case '?':
default:
done = 1;
break;
}
if (done) break;
}
if (argc > (optind)) cmdbuf = copy_argv(&argv[optind]);
else cmdbuf = "";

if (device == NULL) {
device = pcap_lookupdev(ebuf);
if (device == NULL)
error("%s", ebuf);
}
pd = pcap_open_live(device, snaplen, 1, 1000, ebuf);
if (pd == NULL)
error("%s", ebuf);
i = pcap_snapshot(pd);
if (snaplen < i) {
warning("snaplen raised from %d to %d", snaplen, i);
snaplen = i;
}
if (pcap_lookupnet(device, &localnet, &netmask, ebuf) < 0) {
localnet = 0;
netmask = 0;
warning("%s", ebuf);
}
/*
* Let user own process after socket has been opened.
*/
setuid(getuid());

if (pcap_compile(pd, &fcode, cmdbuf, 1, netmask) < 0)
error("%s", pcap_geterr(pd));

(void)setsignal(SIGTERM, program_ending);
(void)setsignal(SIGINT, program_ending);
/* Cooperate with nohup(1) */
if ((oldhandler = setsignal(SIGHUP, program_ending)) != SIG_DFL)
(void)setsignal(SIGHUP, oldhandler);

if (pcap_setfilter(pd, &fcode) < 0)
error("%s", pcap_geterr(pd));
pcap_userdata = 0;
(void)fprintf(stderr, "%s: listening on %s\n", program_name, device);
if (pcap_loop(pd, cnt, raw_print, pcap_userdata) < 0) {
(void)fprintf(stderr, "%s: pcap_loop: %s\n",
program_name, pcap_geterr(pd));
exit(1);
}
pcap_close(pd);
exit(0);
}

You didn't link against a library containing the reported missing symbols. It doesn't seem to be any standard library. May be you're compiling/linking on MS-Windows?
Topic archived. No new replies allowed.