sngrep icon indicating copy to clipboard operation
sngrep copied to clipboard

Master wont compile on FreeBSD

Open dunst0 opened this issue 10 years ago • 23 comments

While trying the new 1.4.0-rc2 I found out that master branch no longer compiles under FreeBSD.

  CC       option.o
option.c:55:17: warning: implicit declaration of function 'get_current_dir_name' is invalid in C99 [-Wimplicit-function-declaration]
    char *pwd = get_current_dir_name();
                ^
option.c:55:11: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
    char *pwd = get_current_dir_name();
          ^     ~~~~~~~~~~~~~~~~~~~~~~
  CCLD     sngrep
option.o: In function `init_options':
option.c:(.text+0x22): undefined reference to `get_current_dir_name'
cc: error: linker command failed with exit code 1 (use -v to see invocation)

just a quick grep get_current_dir_name /usr/include/unistd.h shows that this function is not defined in unistd.h on FreeBSD.

Just reporting back because I still would like to use it on FreeBSD systems, because I helps a lot.

dunst0 avatar Aug 09 '16 12:08 dunst0

Sorry, that was introduced in the last commit, thanks a lot for testing the release candidate to detect this kind of bugs!!

Kaian avatar Aug 09 '16 12:08 Kaian

Could you please give it a try to the latest commit? (rc3)

Kaian avatar Aug 09 '16 12:08 Kaian

Compiles but throws segfault

#0  0x000000080208f080 in getcwd () from /lib/libc.so.7
#1  0x000000000040fbc5 in init_options ()
#2  0x000000000040f0c6 in main ()

dunst0 avatar Aug 09 '16 13:08 dunst0

Umm quite strange, it works in my testing bsd environment.

The documentation says:

The ability to specify a NULL pointer and have getcwd() allocate memory as
 necessary is an extension.

I will ignore that and allocate the memory to store the path myself :)

Kaian avatar Aug 09 '16 14:08 Kaian

I can start it up on a freebsd machine of mine running 11-stable. I don't have any sip traffic on this computer so I don't know when the segfault happens.

jungle-boogie avatar Aug 09 '16 15:08 jungle-boogie

For these systems, I usually check with the pcap file in tests directory called aaa.pcap :angel:

Thanks for the input jungle!

Kaian avatar Aug 09 '16 15:08 Kaian

Strange it will segfault with just right away with any kind of parameters, even with none. Will test it tomorrow with clean fresh checkout again, maybe some error on my side.

dunst0 avatar Aug 09 '16 16:08 dunst0

Just to check: Is your current path longer than 1024 chars? Thats the max path value that can be stored in the savepath setting

Kaian avatar Aug 09 '16 16:08 Kaian

Fresh clean checkout from git, build, test ... segfault. I think /root shouldn't be the problem.

dunst0 avatar Aug 10 '16 12:08 dunst0

Btw: the version 10.3-RELEASE-p1

dunst0 avatar Aug 10 '16 12:08 dunst0

It seems clear that the getcwd function is the problem, but this little snippet is more or less the way the function is used in sngrep, and seems to work in my testing environment. If It crashes for you, then I will try to install a 10.3 to see if I can reproduce the error or look for another way to implement it.

[root@freebsd /tmp/freebsdtest]# freebsd-version 
10.2-RELEASE
[root@freebsd /tmp/freebsdtest]# cat getcurdir.c 
/*
    gcc -o getcurdir getcurdir.c ; ./getcurdir
*/

#include <unistd.h>
#include <stdio.h>

#define BUFSIZE 1024

int main()
{
    char buf[BUFSIZE];
    printf("Current directory: %s\n", getcwd(buf, BUFSIZE));
    return 0;
}
[root@freebsd /tmp/freebsdtest]# gcc -o getcurdir getcurdir.c ; ./getcurdir
Current directory: /tmp/freebsdtest

Kaian avatar Aug 10 '16 14:08 Kaian

This snippet works for me, strange.

dunst0 avatar Aug 10 '16 20:08 dunst0

I am going to make a debug build tomorrow and will debug what is happening there.

dunst0 avatar Aug 10 '16 20:08 dunst0

@dunst0,

what's your config options? Are you using the native compiler (clang)?

BTW, I'd recommend upgrading to the latest patches. There's been many patches since p1.

I tried on 11-stable and @Kaian has used 10.1. I'll try a 10.3 machine I have.

jungle-boogie avatar Aug 10 '16 23:08 jungle-boogie

@jungle-boogie right now it is a test environment, so I didn't kept it updated all the time

Native clang compiler

# clang --version
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: x86_64-unknown-freebsd10.3
Thread model: posix

configure options:

# env CFLAGS="-I/usr/include -I/usr/local/include" LDFLAGS="-L/usr/lib -L/usr/local/lib" ./configure --enable-ipv6 --enable-eep --with-openssl --with-pcre

And right now I found the problem could be the C and LD flags

dunst0 avatar Aug 11 '16 12:08 dunst0

Without --with-pcre and the flags it didn't crash, sad because the pcre was nice

dunst0 avatar Aug 11 '16 12:08 dunst0

Don't be sad. Once it worked. We'll make it work again :smile: :eyes:

Thanks for all the debugging!!

Kaian avatar Aug 11 '16 12:08 Kaian

Thankyou for the wonderfull tool :+1:

Btw I have under FreeBSD incomplete packages captured.

dunst0 avatar Aug 11 '16 13:08 dunst0

It must be a problem related with 10.3 or something in your local dir. This is my build log: https://gist.github.com/Kaian/d33b496da89f19e4ec3bada9f9859e83

For the incomplete issue, if you can send me a pcap, we can make another issue and try to solve the problem. In some known cases, while using sngrep with bpf filters (port 5060 for example) and IP fragmentation occurs not all fragments are passed to the application by the libpcap library.

Kaian avatar Aug 11 '16 14:08 Kaian

Works fine for me on 10.3 p4 with the same config options.

configure: ======================================================
configure: GnuTLS Support               : no
configure: OpenSSL Support              : yes
configure: Unicode Support              : no
configure: Perl Expressions Support     : yes
configure: IPv6 Support                 : yes
configure: EEP Support                  : yes
configure: ======================================================

I'm able to open aaaa.pcap and run sngrep without a segfault.

Regarding pcre, we have this github issue that us three chatted about: https://github.com/irontec/sngrep/issues/88

jungle-boogie avatar Aug 11 '16 16:08 jungle-boogie