[완료]gcc -static -L/usr/local/lib -lnet -o test test.c 가 잘안됩니다.도와주세요.

k1d0bus3의 이미지

#include <stdio.h>
#include <libnet.h>
int main(){
    u_int32_t i;
    libnet_t *l;
    libnet_ptag_t t;
    u_int8_t *packet;
    u_int32_t packet_s;
    char errbuf[LIBNET_ERRBUF_SIZE];
        u_char enet_src[6] = {0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c};
        u_char enet_dst[6] = {0x00, 0x00, 0x00, 0x0d, 0x0e, 0x0f};
 
    l = libnet_init(
            LIBNET_LINK_ADV,
            "wlan0",
            errbuf);
    i = libnet_get_ipaddr4(l);
    t = libnet_autobuild_arp(
            ARPOP_REPLY,
            enet_src,
            (u_int8_t *)&i,
            enet_dst,
            (u_int8_t *)&i,
            l);
    t = libnet_autobuild_ethernet(
            enet_dst,
            ETHERTYPE_ARP,
            l);
    libnet_write(l);
    libnet_destroy(l);
 
    printf("wlan0 send complete!\n");
    return 0;
}

이렇게 libnet을 이용해서 커스텀패킷을 보내는 test.c를 만들었습니다.
라이브러리는 /usr/local/lib에 libnet.a 와 libnet.so 두개가 있습니다.

gcc -L/usr/local/lib -lnet -o test test.c
를 해서 libnet.so와 링크하여 만든 실행파일을 실행하니,
예상대로 패킷이 잘 나갑니다.

그런데 제가 원하는건 정적링크, libnet.a와 합체시키는 겁니다. 그래서
gcc -static -L/usr/local/lib -lnet -o test test.c
를 햇더니
/tmp/ccS0sbPQ.o: In function `main':
test.c:(.text+0x8d): undefined reference to `libnet_init'
test.c:(.text+0xa1): undefined reference to `libnet_get_ipaddr4'
test.c:(.text+0xe5): undefined reference to `libnet_autobuild_arp'
test.c:(.text+0x10b): undefined reference to `libnet_autobuild_ethernet'
test.c:(.text+0x11f): undefined reference to `libnet_write'
test.c:(.text+0x12d): undefined reference to `libnet_destroy'
collect2: ld returned 1 exit status
이렇게 자꾸 실패합니다.
무엇이 문제입니까?

익명 사용자의 이미지

/usr/local/lib/libnet.a 파일에 symbol이 제대로 등록되어있는지 먼저 확인해보세요.

nm /usr/local/lib/libnet.a |grep libnet_autobuild_arp 같은 식으로 해보면 압니다.
symbol이 정의가 안되있으면 잘못된 *.a 파일인 것이겠죠.

k1d0bus3의 이미지

root@KIN:/usr/local/lib# nm libnet.a|grep libnet_init
libnet_init.o:
00000190 T libnet_init
root@KIN:/usr/local/lib# nm libnet.a|grep libnet_get_ipaddr4
         U libnet_get_ipaddr4
000007a0 T libnet_get_ipaddr4
root@KIN:/usr/local/lib# nm libnet.a|grep libnet_autobuild_arp
00000240 T libnet_autobuild_arp
root@KIN:/usr/local/lib# nm libnet.a|grep libnet_autobuild_ethernet
00000000 T libnet_autobuild_ethernet
         U libnet_autobuild_ethernet
root@KIN:/usr/local/lib# nm libnet.a|grep libnet_write
         U libnet_write_link
         U libnet_write_raw_ipv4
libnet_write.o:
000001f0 T libnet_write
         U libnet_write_link
00000000 T libnet_write_raw_ipv4
000000f0 T libnet_write_raw_ipv6
000001b0 T libnet_write_link
root@KIN:/usr/local/lib# nm libnet.a|grep libnet_destroy
         U libnet_destroy
00000150 T libnet_destroy
익명 사용자의 이미지

"U" 라고 되어있는 것은 undefined입니다. libnet.a static 빌드옵션을 잘 못 주거나 제대로 빌드되지 않았을 가능성이 높네요.

혹은 dynamic하게 링크된 실행파일이 어떤 라이브러리를 쓰고 있는지 다시 한번 확인해보세요. ldd 실행파일 혹은 objdump --all-headers 실행파일 하면 실행파일이 필요로 하는 라이브러리 리스트를 좌악 보여줍니다.

익명 사용자의 이미지

음... 다시 보니 심볼이 모두 정의되어있네요. ld에 문제가 있는 듯...

익명 사용자의 이미지

bacon의 이미지

-lnet을 test.c로 보내면 될것요. 아마 링커가 심볼을 찾는 순서때문에 생기는 문제일거예요.

gcc -static -L/usr/local/lib -o test test.c -lnet

.

익명 사용자의 이미지

약간 버그성이기는 해도, 저 역시 심볼 없다는 오류가 날 때에 말씀하신 것처럼 링크 라이브러리 순서를 바꿔서 해결하곤 했습니다

k1d0bus3의 이미지

다들 감사합니다.
덕분에 해결했습니다.
이걸 버그성이라고 봐야하나요?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.