Make libpcap shared

SVN-Revision: 476
This commit is contained in:
Nicolas Thill 2005-03-30 14:43:56 +00:00
parent 98920cbaec
commit 80d8f01d21
6 changed files with 208 additions and 14 deletions

View file

@ -1,6 +1,6 @@
config BR2_PACKAGE_LIBPCAP
bool "libpcap"
default n
tristate "libpcap (a low-level packet capture library)"
default m
help
A system-independent library for user-level network packet capture.

View file

@ -12,6 +12,8 @@ PKG_SOURCE_FILE := $(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_CAT := zcat
PKG_SOURCE_DIR := $(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_SOURCE_DIR)
PKG_IPK := $(PACKAGE_DIR)/$(PKG_NAME)_$(PKG_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk
PKG_IPK_DIR:=$(PKG_BUILD_DIR)/ipkg
$(DL_DIR)/$(PKG_SOURCE_FILE):
mkdir -p $(DL_DIR)
@ -20,7 +22,7 @@ $(DL_DIR)/$(PKG_SOURCE_FILE):
$(PKG_BUILD_DIR)/.patched: $(DL_DIR)/$(PKG_SOURCE_FILE)
mkdir -p $(TOOL_BUILD_DIR)
$(PKG_SOURCE_CAT) $(DL_DIR)/$(PKG_SOURCE_FILE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
$(PATCH) $(PKG_BUILD_DIR) . ./patches
$(PATCH) $(PKG_BUILD_DIR) ./patches
touch $(PKG_BUILD_DIR)/.patched
$(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.patched
@ -33,29 +35,57 @@ $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.patched
--target=$(GNU_TARGET_NAME) \
--host=$(GNU_TARGET_NAME) \
--build=$(GNU_HOST_NAME) \
--with-build-cc=$(HOSTCC) \
--disable-yydebug \
--program-prefix="" \
--program-suffix="" \
--prefix=/usr \
--exec-prefix=/usr \
--bindir=/usr/bin \
--datadir=/usr/share \
--includedir=/usr/include \
--infodir=/usr/share/info \
--libdir=/usr/lib \
--libexecdir=/usr/lib \
--localstatedir=/var \
--mandir=/usr/share/man \
--sbindir=/usr/sbin \
--sysconfdir=/etc \
--enable-shared \
--enable-static \
--disable-yydebug \
--with-build-cc=$(HOSTCC) \
--with-pcap=linux \
);
touch $(PKG_BUILD_DIR)/.configured
$(PKG_BUILD_DIR)/libpcap.a: $(PKG_BUILD_DIR)/.configured
$(MAKE) AR="$(TARGET_CROSS)ar" -C $(PKG_BUILD_DIR)
$(STAGING_DIR)/lib/libpcap.a: $(PKG_BUILD_DIR)/libpcap.a
$(MAKE) -C $(PKG_BUILD_DIR) \
prefix=$(STAGING_DIR) \
exec_prefix=$(STAGING_DIR) \
bindir=$(STAGING_DIR)/bin \
datadir=$(STAGING_DIR)/share \
$(TARGET_CONFIGURE_OPTS) \
CCOPT="$(TARGET_CFLAGS)" \
$(STAGING_DIR)/usr/lib/libpcap.a: $(PKG_BUILD_DIR)/libpcap.a
$(MAKE) -C $(PKG_BUILD_DIR) \
DESTDIR="$(STAGING_DIR)" \
install
$(PKG_IPK): $(STAGING_DIR)/usr/lib/libpcap.a
$(SCRIPT_DIR)/make-ipkg-dir.sh $(PKG_IPK_DIR) ./ipkg/$(PKG_NAME).control $(PKG_VERSION)-$(PKG_RELEASE) $(ARCH)
mkdir -p $(PKG_IPK_DIR)/usr/lib
cp -fpR $(STAGING_DIR)/usr/lib/libpcap.so.* $(PKG_IPK_DIR)/usr/lib/
$(STRIP) $(PKG_IPK_DIR)/usr/lib/*
mkdir -p $(PACKAGE_DIR)
$(IPKG_BUILD) $(PKG_IPK_DIR) $(PACKAGE_DIR)
$(IPKG_STATE_DIR)/info/$(PKG_NAME).list: $(PKG_IPK)
$(IPKG) install $(PKG_IPK)
source: $(DL_DIR)/$(PKG_SOURCE_FILE)
prepare: $(PKG_BUILD_DIR)/.patched
compile: $(STAGING_DIR)/lib/libpcap.a
install:
install: $(IPKG_STATE_DIR)/info/$(PKG_NAME).list
clean:
-$(MAKE) -C $(PKG_BUILD_DIR) \
DESTDIR="$(STAGING_DIR)" \
uninstall clean
rm -rf $(PKG_BUILD_DIR)
rm -f $(STAGING_DIR)/lib/libpcap*
rm -f $(PKG_IPK)

View file

@ -0,0 +1,8 @@
Package: libpcap
Priority: optional
Section: libs
Version: [TBDL]
Architecture: [TBDL]
Maintainer: Nico <nthill@free.fr>
Source: http://nthill.free.fr/openwrt/sources/libpcap/
Description: a low-level packet capture library

View file

@ -0,0 +1,117 @@
--- libpcap-0.8.3-orig/Makefile.in 2003-12-15 02:42:23.000000000 +0100
+++ libpcap-0.8.3-7/Makefile.in 2005-03-08 03:38:22.000000000 +0100
@@ -37,6 +37,15 @@
srcdir = @srcdir@
VPATH = @srcdir@
+# some defines for shared library compilation
+MAJ=0.8
+MIN=3
+VERSION=$(MAJ).$(MIN)
+LIBNAME=pcap
+LIBRARY=lib$(LIBNAME).a
+SOLIBRARY=lib$(LIBNAME).so
+SHAREDLIB=$(SOLIBRARY).$(VERSION)
+
#
# You shouldn't need to edit anything below.
#
@@ -49,6 +58,7 @@
# Standard CFLAGS
CFLAGS = $(CCOPT) $(INCLS) $(DEFS)
+CFLAGS_SHARED = -shared -Wl,-soname,$(SOLIBRARY).$(MAJ)
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
@@ -68,7 +78,11 @@
# problem if you don't own the file but can write to the directory.
.c.o:
@rm -f $@
- $(CC) $(CFLAGS) -c $(srcdir)/$*.c
+ $(CC) $(CFLAGS) -c -o $@ $(srcdir)/$*.c
+
+%_pic.o: %.c
+ @rm -f $@
+ $(CC) -fPIC $(CFLAGS) -c -o $@ $(srcdir)/$*.c
PSRC = pcap-@V_PCAP@.c
FSRC = fad-@V_FINDALLDEVS@.c
@@ -83,6 +97,7 @@
# We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
# hack the extra indirection
OBJ = $(PSRC:.c=.o) $(FSRC:.c=.o) $(CSRC:.c=.o) $(SSRC:.c=.o) $(GENSRC:.c=.o) $(LIBOBJS)
+OBJ_PIC = $(PSRC:.c=_pic.o) $(FSRC:.c=_pic.o) $(CSRC:.c=_pic.o) $(SSRC:.c=_pic.o) $(GENSRC:.c=_pic.o)
HDR = pcap.h pcap-int.h pcap-namedb.h pcap-nit.h pcap-pf.h \
ethertype.h gencode.h gnuc.h
GENHDR = \
@@ -94,15 +109,22 @@
TAGFILES = \
$(SRC) $(HDR) $(TAGHDR)
-CLEANFILES = $(OBJ) libpcap.a $(GENSRC) $(GENHDR) lex.yy.c
+CLEANFILES = $(OBJ) $(OBJ_PIC) libpcap.a $(GENSRC) $(GENHDR) lex.yy.c libpcap.so*
-all: libpcap.a
+all: libpcap.a $(SHAREDLIB)
libpcap.a: $(OBJ)
@rm -f $@
ar rc $@ $(OBJ) $(LIBS)
$(RANLIB) $@
+$(SHAREDLIB): $(OBJ_PIC)
+ -@rm -f $@
+ -@rm -f $(SOLIBRARY) $(SOLIBRARY).$(MAJ)
+ $(CC) $(CFLAGS_SHARED) -o $(SHAREDLIB) $(OBJ_PIC) -lc
+ ln -s $(SHAREDLIB) $(SOLIBRARY).$(MAJ)
+ ln -s $(SOLIBRARY).$(MAJ) $(SOLIBRARY)
+
scanner.c: $(srcdir)/scanner.l
@rm -f $@
$(LEX) -t $< > $$$$.$@; mv $$$$.$@ $@
@@ -110,6 +132,9 @@
scanner.o: scanner.c tokdefs.h
$(CC) $(CFLAGS) -c scanner.c
+scanner_pic.o: scanner.c tokdefs.h
+ $(CC) -fPIC $(CFLAGS) -o $@ -c scanner.c
+
pcap.o: version.h
tokdefs.h: grammar.c
@@ -123,9 +148,17 @@
@rm -f $@
$(CC) $(CFLAGS) -Dyylval=pcap_lval -c grammar.c
+grammar_pic.o: grammar.c
+ @rm -f $@
+ $(CC) -fPIC $(CFLAGS) -Dyylval=pcap_lval -o $@ -c grammar.c
+
version.o: version.c
$(CC) $(CFLAGS) -c version.c
+version_pic.o: version.c
+ $(CC) -fPIC $(CFLAGS) -c version.c -o $@
+
+
snprintf.o: $(srcdir)/missing/snprintf.c
$(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c
@@ -151,10 +184,16 @@
bpf_filter.o: bpf_filter.c
$(CC) $(CFLAGS) -c bpf_filter.c
+bpf_filter_pic.o: bpf_filter.c
+ $(CC) -fPIC $(CFLAGS) -c bpf_filter.c -o $@
+
install:
[ -d $(DESTDIR)$(libdir) ] || \
(mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
$(INSTALL_DATA) libpcap.a $(DESTDIR)$(libdir)/libpcap.a
+ $(INSTALL_DATA) $(SHAREDLIB) $(DESTDIR)$(libdir)/
+ ln -sf $(SHAREDLIB) $(DESTDIR)$(libdir)/$(SOLIBRARY).$(MAJ)
+ ln -sf $(SOLIBRARY).$(MAJ) $(DESTDIR)$(libdir)/$(SOLIBRARY)
$(RANLIB) $(DESTDIR)$(libdir)/libpcap.a
[ -d $(DESTDIR)$(includedir) ] || \
(mkdir -p $(DESTDIR)$(includedir); chmod 755 $(DESTDIR)$(includedir))

View file

@ -0,0 +1,39 @@
--- libpcap-0.8.3-orig/nametoaddr.c 2003-11-19 19:13:48.000000000 +0100
+++ libpcap-0.8.3-7/nametoaddr.c 2005-03-08 03:38:22.000000000 +0100
@@ -333,7 +333,7 @@
e = ep = (u_char *)malloc(6);
while (*s) {
- if (*s == ':')
+ if (*s == ':' || *s == '.')
s += 1;
d = xdtoi(*s++);
if (isxdigit((unsigned char)*s)) {
--- libpcap-0.8.3-orig/scanner.l 2004-03-28 23:45:33.000000000 +0200
+++ libpcap-0.8.3-7/scanner.l 2005-03-08 03:38:22.000000000 +0100
@@ -80,6 +80,7 @@
N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
B ([0-9A-Fa-f][0-9A-Fa-f]?)
W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
+X [0-9A-Fa-f]
%a 16000
%o 19000
@@ -296,7 +297,7 @@
{N} { yylval.i = stoi((char *)yytext); return NUM; }
({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
yylval.s = sdup((char *)yytext); return HID; }
-{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
+({B}:{B}:{B}:{B}:{B}:{B})|({B}\.{B}\.{B}\.{B}\.{B}\.{B}) { yylval.e = pcap_ether_aton((char *)yytext);
return EID; }
{V6} {
#ifdef INET6
@@ -314,6 +315,8 @@
#endif /*INET6*/
}
{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
+{X}{12} { yylval.e = pcap_ether_aton((char *)yytext); return EID;}
+
icmptype { yylval.i = 0; return NUM; }
icmpcode { yylval.i = 1; return NUM; }
icmp-echoreply { yylval.i = 0; return NUM; }