est / pypcap

Automatically exported from code.google.com/p/pypcap
Other
0 stars 0 forks source link

error: dereferencing pointer to incomplete type in solaris x86 #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
제 솔라리스 10 x86 환경에서 컴파일 해보는데.. 

bash-3.2$ wget http://pypcap.googlecode.com/files/pypcap-1.1.tar.gz
--11:26:03--  http://pypcap.googlecode.com/files/pypcap-1.1.tar.gz
           => `pypcap-1.1.tar.gz'
Resolving pypcap.googlecode.com... 66.102.1.82
Connecting to pypcap.googlecode.com|66.102.1.82|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22,951 (22K) [application/x-gzip]

100%[====================================>] 22,951        48.56K/s             

11:26:05 (48.49 KB/s) - `pypcap-1.1.tar.gz' saved [22951/22951]

bash-3.2$ gtar zxvf pypcap-1.1.tar.gz
bash-3.2$ pwd
/export/home/sandy/pypcap-1.1
bash-3.2$ ls -al
총 270
drwxr-xr-x   3 sandy    other        512  3월 10일  11:26 .
drwxr-xr-x  52 sandy    other       4096  3월 10일  11:26 ..
-rw-r--r--   1 sandy    other        508 2005년 10월 16일 CHANGES
-rw-r--r--   1 sandy    other       1431 2005년 10월 16일 LICENSE
-rw-r--r--   1 sandy    other        615 2005년 10월 16일 Makefile
-rw-r--r--   1 sandy    other        371 2005년 10월 16일 README
drwxr-xr-x   3 root     root         512  3월 10일  11:26 build
-rw-r--r--   1 sandy    other      98124 2005년 10월 16일 pcap.c
-rw-r--r--   1 sandy    other      11982 2005년 10월 16일 pcap.pyx
-rw-r--r--   1 sandy    other       6162 2005년 10월 16일 pcap_ex.c
-rw-r--r--   1 sandy    other        629 2005년  8월 29일 pcap_ex.h
-rw-r--r--   1 sandy    other       4002 2005년 10월 16일 setup.py
-rw-r--r--   1 sandy    other        468 2005년  1월 26일 test.pcap
-rwxr-xr-x   1 sandy    other       1431 2005년  9월 11일 test.py
-rwxr-xr-x   1 sandy    other        914 2005년  1월 26일 testsniff.py

bash-3.2$ cd py*
bash-3.2$ sudo python setup.py install
running install
running build
running build_ext
building 'pcap' extension
creating build
creating build/temp.solaris-2.10-i86pc-2.5
gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC
-I/usr/local/include/python2.5 -c pcap.c -o
build/temp.solaris-2.10-i86pc-2.5/pcap.o
pcap.c: In function `__pyx_f_4pcap_3bpf___dealloc__':
pcap.c:320: warning: label `__pyx_L1' defined but not used
pcap.c: In function `__pyx_f_4pcap_4pcap_dispatch':
pcap.c:1039: warning: passing arg 3 of `pcap_dispatch' from incompatible
pointer type
pcap.c: In function `__pyx_f_4pcap_4pcap_loop':
pcap.c:1142: warning: passing arg 3 of `pcap_ex_next' from incompatible
pointer type
pcap.c:1134: warning: label `__pyx_L2' defined but not used
pcap.c: In function `__pyx_f_4pcap_4pcap___iter__':
pcap.c:1305: warning: label `__pyx_L1' defined but not used
pcap.c: In function `__pyx_f_4pcap_4pcap___next__':
pcap.c:1338: warning: passing arg 3 of `pcap_ex_next' from incompatible
pointer type
pcap.c:1330: warning: label `__pyx_L2' defined but not used
pcap.c:1382: warning: label `__pyx_L3' defined but not used
pcap.c: In function `__pyx_f_4pcap_4pcap___dealloc__':
pcap.c:1433: warning: label `__pyx_L1' defined but not used
pcap.c: In function `__pyx_tp_new_4pcap_bpf':
pcap.c:1567: warning: unused variable `p'
pcap.c: In function `__pyx_tp_dealloc_4pcap_bpf':
pcap.c:1572: warning: unused variable `p'
pcap.c: In function `__pyx_tp_traverse_4pcap_bpf':
pcap.c:1586: warning: unused variable `e'
pcap.c:1587: warning: unused variable `p'
pcap.c: In function `__pyx_tp_clear_4pcap_bpf':
pcap.c:1592: warning: unused variable `p'
pcap.c: In function `__pyx_tp_new_4pcap_pcap':
pcap.c:1719: warning: unused variable `p'
pcap.c: In function `__pyx_tp_dealloc_4pcap_pcap':
pcap.c:1724: warning: unused variable `p'
pcap.c: In function `__pyx_tp_traverse_4pcap_pcap':
pcap.c:1738: warning: unused variable `e'
pcap.c:1739: warning: unused variable `p'
pcap.c: In function `__pyx_tp_clear_4pcap_pcap':
pcap.c:1744: warning: unused variable `p'
pcap.c: In function `__Pyx_GetStarArgs':
pcap.c:2253: warning: suggest explicit braces to avoid ambiguous `else'
pcap.c:2255: warning: suggest explicit braces to avoid ambiguous `else'
pcap.c: At top level:
pcap.c:14: warning: '__Pyx_UnpackItem' declared `static' but never defined
pcap.c:15: warning: '__Pyx_EndUnpack' declared `static' but never defined
pcap.c:16: warning: '__Pyx_PrintItem' declared `static' but never defined
pcap.c:17: warning: '__Pyx_PrintNewline' declared `static' but never defined
pcap.c:19: warning: '__Pyx_ReRaise' declared `static' but never defined
pcap.c:22: warning: '__Pyx_ArgTypeTest' declared `static' but never defined
pcap.c:23: warning: '__Pyx_TypeTest' declared `static' but never defined
pcap.c:27: warning: '__Pyx_ImportType' declared `static' but never defined
pcap.c:28: warning: '__Pyx_SetVtable' declared `static' but never defined
pcap.c:29: warning: '__Pyx_GetVtable' declared `static' but never defined
pcap.c:30: warning: '__Pyx_CreateClass' declared `static' but never defined
gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC
-I/usr/local/include/python2.5 -c pcap_ex.c -o
build/temp.solaris-2.10-i86pc-2.5/pcap_ex.o
pcap_ex.c:22:20: config.h: 해당 파일이나 디렉토리가 없음
pcap_ex.c: In function `pcap_ex_fileno':
pcap_ex.c:165: error: dereferencing pointer to incomplete type
pcap_ex.c: In function `pcap_ex_next':
pcap_ex.c:253: error: dereferencing pointer to incomplete type
pcap_ex.c: In function `pcap_ex_compile_nopcap':
pcap_ex.c:285: warning: implicit declaration of function `mktemp'
error: command 'gcc' failed with exit status 1

 음 문제가 뭘까요?

 21
    22  #include "config.h"
    23

 int
   156  pcap_ex_fileno(pcap_t *pcap)
   157  {
   158  #ifdef _WIN32
   159          /* XXX - how to handle savefiles? */
   160          return ((int)pcap_getevent(pcap));
   161  #else
   162  # ifdef HAVE_PCAP_FILE
   163          FILE *f = pcap_file(pcap);
   164  # else
   165          FILE *f = pcap->sf.rfile;
   166  # endif
   167          if (f != NULL)
   168                  return (fileno(f));
   169          return (pcap_fileno(pcap));
   170  #endif /* !_WIN32 */
   171  }

   226  /* return codes: 1 = pkt, 0 = timeout, -1 = error, -2 = EOF */
   227  int
   228  pcap_ex_next(pcap_t *pcap, struct pcap_pkthdr **hdr, u_char **pkt)
   229  {
   230  #ifdef _WIN32
   231          if (__pcap_ex_gotsig) {
   232                  __pcap_ex_gotsig = 0;
   233                  return (-1);
   234          }
   235          return (pcap_next_ex(pcap, hdr, pkt));
   236  #else
   237          static u_char *__pkt;
   238          static struct pcap_pkthdr __hdr;
   239          struct timeval tv = { 1, 0 };
   240          fd_set rfds;
   241          int fd, n;
   242
   243          fd = pcap_fileno(pcap);
   244          for (;;) {
   245                  if (__pcap_ex_gotsig) {
   246                          __pcap_ex_gotsig = 0;
   247                          return (-1);
   248                  }
   249                  if ((__pkt = (u_char *)pcap_next(pcap, &__hdr)) ==
NULL) {
   250  #ifdef HAVE_PCAP_FILE
   251                          if (pcap_file(pcap) != NULL)
   252  #else
   253                          if (pcap->sf.rfile != NULL)
   254  #endif
   255                                  return (-2);
   256                          FD_ZERO(&rfds);
   257                          FD_SET(fd, &rfds);
   258                          n = select(fd + 1, &rfds, NULL, NULL, &tv);
   259                          if (n <= 0)
   260                                  return (n);
   261                  } else
   262                          break;
   263          }
   264          *pkt = __pkt;
   265          *hdr = &__hdr;
   266
   267          return (1);
   268  #endif
   269  }
   270

271  int
   272  pcap_ex_compile_nopcap(int snaplen, int dlt, struct bpf_program
*fp, char *str,
   273      int optimize, unsigned int netmask)
   274  {
   275  #ifdef HAVE_PCAP_COMPILE_NOPCAP
   276          return (pcap_compile_nopcap(snaplen, dlt, fp, str,
optimize, netmask));
   277  #else
   278          FILE *f;
   279          struct pcap_file_header hdr;
   280          pcap_t *pc;
   281          char path[] = "/tmp/.pypcapXXXXXX.pcap";
   282          char ebuf[PCAP_ERRBUF_SIZE];
   283          int ret = -1;
   284
   285          mktemp(path);
   286          if ((f = fopen(path, "w")) != NULL) {
   287                  hdr.magic = 0xa1b2c3d4;
   288                  hdr.version_major = PCAP_VERSION_MAJOR;
   289                  hdr.version_minor = PCAP_VERSION_MINOR;
   290                  hdr.thiszone = 0;
   291                  hdr.snaplen = snaplen;
   292                  hdr.sigfigs = 0;
   293                  hdr.linktype = dlt;
   294                  fwrite(&hdr, sizeof(hdr), 1, f);
   295                  fclose(f);
   296
   297                  if ((pc = pcap_open_offline(path, ebuf)) != NULL) {
   298                          ret = pcap_compile(pc, fp, str, optimize,
netmask);
   299                          pcap_close(pc);
   300                  }
   301                  unlink(path);
   302          }
   303          return (ret);
   304  #endif
   305  }

제 환경입니다.
bash-3.2$ uname -a
SunOS gagemel 5.10 Generic_118844-20 i86pc i386 i86pc
bash-3.2$ python
Python 2.5 (r25:51908, Sep 20 2006, 03:11:51) 
[GCC 3.4.6] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Original issue reported on code.google.com by gage...@gmail.com on 10 Mar 2007 at 11:59

GoogleCodeExporter commented 9 years ago
what version of libpcap do you have installed? it looks like a missing 
pcap-int.h
header file.

can you show me the output for these commands?

   cat config.h

and in python:

>>> import cPickle
>>> cPickle.loads(open('config.pkl').read())

Original comment by dugsong on 11 Mar 2007 at 4:23

GoogleCodeExporter commented 9 years ago
thank you for your kind and quick comment, dugsong :0

i `v installed libpcap version 0.9.5.
there is no pcap-int.h in this version.
config.pkl
there `s no config.h or config.pkl too.
i have to go back libpcap version  with pcap-int.h?
for example libpcap version 0.7.1.

Original comment by gage...@gmail.com on 11 Mar 2007 at 6:54

GoogleCodeExporter commented 9 years ago
sorry dugsong,
i brought compiled binary version libpcap from sunfreeware.
but there "IS" definetely pcap-int.h in libpcap 0.9.5 source from tcpdump.org.
i`m lazy.very soory for that.

Original comment by gage...@gmail.com on 11 Mar 2007 at 7:04

GoogleCodeExporter commented 9 years ago
only after in the source directory do "gmake" ,cconfig.h or config.pkl came 
into view.

[07:16:04 sandy@gagemel pypcap-1.1]$ more config.h
#define HAVE_PCAP_SETNONBLOCK 1
#define HAVE_PCAP_FILE 1
#define HAVE_PCAP_INT_H 1
#define HAVE_PCAP_COMPILE_NOPCAP 1
[07:16:20 sandy@gagemel pypcap-1.1]$ python
Python 2.5 (r25:51908, Sep 20 2006, 03:11:51) 
[GCC 3.4.6] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import cPickle
>>> cPickle.loads(open('config.pkl').read())
{'libraries': ['pcap'], 'library_dirs': ['/usr/local/lib'], 'include_dirs':
['/usr/local/include']}
>>> 

Original comment by gage...@gmail.com on 11 Mar 2007 at 7:20

GoogleCodeExporter commented 9 years ago
and finally got pcap.so.only after " do gmake",everything goes 
well.interesting.:)

[07:36:46 sandy@gagemel pypcap-1.1]$ sudo python setup.py install
Password:
running install
running build
running build_ext
building 'pcap' extension
gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC
-I/usr/local/include/python2.5 -c pcap_ex.c -o
build/temp.solaris-2.10-i86pc-2.5/pcap_ex.o
creating build/lib.solaris-2.10-i86pc-2.5
gcc -shared build/temp.solaris-2.10-i86pc-2.5/pcap.o
build/temp.solaris-2.10-i86pc-2.5/pcap_ex.o -o 
build/lib.solaris-2.10-i86pc-2.5/pcap.so
running install_lib
copying build/lib.solaris-2.10-i86pc-2.5/pcap.so ->
/usr/local/lib/python2.5/site-packages
running install_egg_info
Writing /usr/local/lib/python2.5/site-packages/pcap-1.1-py2.5.egg-info
[07:36:51 sandy@gagemel pypcap-1.1]$ 

Original comment by gage...@gmail.com on 11 Mar 2007 at 7:39

GoogleCodeExporter commented 9 years ago
** final comment.
i`v copied pcap-int.h file from libpcap 0.9.5 source to /usr/local/include .
because gmake install only copied pcap.h,pcap-bpf.h,pcap-namedb.h.

[07:03:09 sandy@gagemel libpcap-0.9.5]$ sudo gmake install
Password:
[ -d /usr/local/lib ] || \
    (mkdir -p /usr/local/lib; chmod 755 /usr/local/lib)
/opt/csw/bin/ginstall -c -m 644 libpcap.a /usr/local/lib/libpcap.a
ranlib /usr/local/lib/libpcap.a
[ -d /usr/local/include ] || \
    (mkdir -p /usr/local/include; chmod 755 /usr/local/include)
/opt/csw/bin/ginstall -c -m 644 ./pcap.h /usr/local/include/pcap.h
/opt/csw/bin/ginstall -c -m 644 ./pcap-bpf.h \
    /usr/local/include/pcap-bpf.h
/opt/csw/bin/ginstall -c -m 644 ./pcap-namedb.h \
    /usr/local/include/pcap-namedb.h
[ -d /usr/local/man/man3 ] || \
        (mkdir -p /usr/local/man/man3; chmod 755 /usr/local/man/man3)
/opt/csw/bin/ginstall -c -m 644 ./pcap.3 \
    /usr/local/man/man3/pcap.3

Original comment by gage...@gmail.com on 11 Mar 2007 at 7:55

GoogleCodeExporter commented 9 years ago
ㅠㅠ . maybe there are some problems in compiled  pcap.so.

[09:43:31 sandy@gagemel ~]$ python scapy.py
scapy.py:3689: Warning: 'with' will become a reserved keyword in Python 2.6
scapy.py:3691: Warning: 'with' will become a reserved keyword in Python 2.6
ERROR: did not find pcap module
[09:43:40 sandy@gagemel ~]$ python
Python 2.5 (r25:51908, Sep 20 2006, 03:11:51) 
[GCC 3.4.6] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> help()

Welcome to Python 2.5!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> modules pcap

Here is a list of matching modules.  Enter any module name to get more help.

pcap 

help> pcap
problem in pcap - <type 'exceptions.ImportError'>: ld.so.1: python: 치명적: 
재할당 오
류: 파일 /usr/local/lib/python2.5/site-packages/pcap.so: 기호 bpf_filter: 
참조 기호가
없습니다.

Original comment by gage...@gmail.com on 11 Mar 2007 at 9:54

GoogleCodeExporter commented 9 years ago
[09:34:43 sandy@gagemel Numeric-24.2]$ python
Python 2.5 (r25:51908, Sep 20 2006, 03:11:51) 
[GCC 3.4.6] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ld.so.1: python: 치명적: 재할당 오류: 파일
/usr/local/lib/python2.5/site-packages/pcap.so: 기호 bpf_filter: 참조 
기호가 없습니다.
>>> 

Original comment by gage...@gmail.com on 11 Mar 2007 at 9:57

GoogleCodeExporter commented 9 years ago
dugsong!!

in my ubuntu box, there is same error.
so using Pyrex, fixed pcap.pyx.

pyrexc pcap.pyx
python setup.py build.

after that, nothing wrong happen.everything goes well.

but back to solaris box, that fix doesn`t work.

Original comment by gage...@gmail.com on 11 Mar 2007 at 1:52

GoogleCodeExporter commented 9 years ago
using Pyrex, fix pcap.pyx.
this is last solution.maybe.
on my solaris box , this fix worked.
thanks, dugsong.

Original comment by gage...@gmail.com on 11 Mar 2007 at 2:06

GoogleCodeExporter commented 9 years ago
yes, you have to 'make' or 'gmake' in order for 'python setup.py config' to be
executed. i should probably change this. :-(

the missing pcap-int.h in comment #6 can be worked around by modifying 
CONFIG_ARGS in
the Makefile to point to your libpcap build directory, instead of using an 
installed
version.

the missing bpf_filter symbol in comment #7 and #8 i don't understand - and i 
don't
understand how regenerating the pcap.c source using pyrex in comment #9 and #10 
would
have fixed it. but if it works, that's great! :-)

can you mail me your regenerated pcap.c file so i can compare? also, what 
version of
Pyrex are you using? i don't have access to a Solaris 10 x86 box right now, so i
cannot reproduce this easily.

thank you!

Original comment by dugsong on 11 Mar 2007 at 8:59

GoogleCodeExporter commented 9 years ago
i`m very sorry about symbol error in comment #7 and #8.
that was my ld setting error.i used /usr/ccs/bin/ld in error situation.
whem i use gnu ld , erorr message has gone. :)

Original comment by gage...@gmail.com on 11 Mar 2007 at 10:27

GoogleCodeExporter commented 9 years ago
well working pcap module.

[22:28:40 sandy@gagemel xchat-2.8.0]$ python
Python 2.5 (r25:51908, Sep 20 2006, 03:11:51) 
[GCC 3.4.6] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> help()

Welcome to Python 2.5!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> modules pcap

Here is a list of matching modules.  Enter any module name to get more help.

pcap 

help> pcap
Help on module pcap:

NAME
    pcap - packet capture library

FILE
    /usr/local/lib/python2.5/site-packages/pcap.so

DESCRIPTION
    This module provides a high level interface to packet capture systems.
    All packets on the network, even those destined for other hosts, are
    accessible through this mechanism.

CLASSES
    __builtin__.object
        bpf
        pcap

    class bpf(__builtin__.object)
     |  bpf(filter, dlt=DLT_RAW) -> BPF filter object
     |  
     |  Methods defined here:
     |  
     |  __init__(...)
     |      x.__init__(...) initializes x; see x.__class__.__doc__ for signature
     |  
     |  filter(...)
     |      Return boolean match for buf against our filter.
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |  
     |  __new__ = <built-in method __new__ of type object at 0xcf4a3700>
     |      T.__new__(S, ...) -> a new object with type S, a subtype of T

    class pcap(__builtin__.object)
     |  pcap(name=None, snaplen=65535, promisc=True, immediate=False) -> packet 
capture object
     |  

help> 

Original comment by gage...@gmail.com on 11 Mar 2007 at 10:32

GoogleCodeExporter commented 9 years ago
great!

i upgraded to Pyrex-0.9.5.1a and regenerated pcap.c for the package, and added 
a note
to the README about the build. sorry for any confusion.

the fix is in svn, and i'll cut a new version later, after some additional 
changes go
in...

Original comment by dugsong on 12 Mar 2007 at 2:37