亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問板塊 發(fā)新帖
查看: 22411 | 回復(fù): 4
打印 上一主題 下一主題

初學(xué)libnids庫(kù)問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2007-07-27 08:28 |只看該作者 |倒序?yàn)g覽
5可用積分
請(qǐng)各路高手幫忙解決問題:
當(dāng)前環(huán)境:redhat linux 9.0
第三方庫(kù):libpcap0.9.5、libnet1.0.2a、libnids1.21已經(jīng)安裝成功
測(cè)試程序?yàn)閘ibnids庫(kù)中帶的實(shí)例代碼如下:
include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include "nids.h"

#define int_ntoa(x)        inet_ntoa(*((struct in_addr *)&x))

// struct tuple4 contains addresses and port numbers of the TCP connections
// the following auxiliary function produces a string looking like
// 10.0.0.1,1024,10.0.0.2,23
char *
adres (struct tuple4 addr)
{
  static char buf[256];
  strcpy (buf, int_ntoa (addr.saddr));
  sprintf (buf + strlen (buf), ",%i,", addr.source);
  strcat (buf, int_ntoa (addr.daddr));
  sprintf (buf + strlen (buf), ",%i", addr.dest);
  return buf;
}

void
tcp_callback (struct tcp_stream *a_tcp, void ** this_time_not_needed)

{
  char buf[1024];
  strcpy (buf, adres (a_tcp->addr)); // we put conn params into buf
  if (a_tcp->nids_state == NIDS_JUST_EST)
    {
    // connection described by a_tcp is established
    // here we decide, if we wish to follow this stream
    // sample condition: if (a_tcp->addr.dest!=23) return;
    // in this simple app we follow each stream, so..
      a_tcp->client.collect++; // we want data received by a client
      a_tcp->server.collect++; // and by a server, too
      a_tcp->server.collect_urg++; // we want urgent data received by a
                                   // server
#ifdef WE_WANT_URGENT_DATA_RECEIVED_BY_A_CLIENT
      a_tcp->client.collect_urg++; // if we don't increase this value,
                                   // we won't be notified of urgent data
                                   // arrival
#endif
      fprintf (stderr, "%s established\n", buf);
      return;
    }
  if (a_tcp->nids_state == NIDS_CLOSE)
    {
      // connection has been closed normally
      fprintf (stderr, "%s closing\n", buf);
      return;
    }
  if (a_tcp->nids_state == NIDS_RESET)
    {
      // connection has been closed by RST
      fprintf (stderr, "%s reset\n", buf);
      return;
    }

  if (a_tcp->nids_state == NIDS_DATA)
    {
      // new data has arrived; gotta determine in what direction
      // and if it's urgent or not

      struct half_stream *hlf;

      if (a_tcp->server.count_new_urg)
      {
        // new byte of urgent data has arrived
        strcat(buf,"(urgent->");
        buf[strlen(buf)+1]=0;
        buf[strlen(buf)]=a_tcp->server.urgdata;
        write(1,buf,strlen(buf));
        return;
      }
      // We don't have to check if urgent data to client has arrived,
      // because we haven't increased a_tcp->client.collect_urg variable.
      // So, we have some normal data to take care of.
      if (a_tcp->client.count_new)
        {
          // new data for the client
          hlf = &a_tcp->client; // from now on, we will deal with hlf var,
                                // which will point to client side of conn
          strcat (buf, "(<"); // symbolic direction of data
        }
      else
        {
          hlf = &a_tcp->server; // analogical
          strcat (buf, "(->");
        }
    fprintf(stderr,"%s",buf); // we print the connection parameters
                              // (saddr, daddr, sport, dport) accompanied
                              // by data flow direction (-> or <

   write(2,hlf->data,hlf->count_new); // we print the newly arrived data
      
    }
  return ;
}

int
main ()

{
  // here we can alter libnids params, for instance:
  // nids_params.n_hosts=256;
  if (!nids_init ())
  {
          fprintf(stderr,"%s\n",nids_errbuf);
          exit(1);
  }
  nids_register_tcp (tcp_callback);
  nids_run ();
  return 0;
}


編譯命令:gcc -g -o sniffer main.c -lnids

報(bào)錯(cuò)如下:
/usr/local/lib/libnids.a(libnids.o)(.text+0x376): In function `nids_pcap_handler':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:335: undefined reference to `g_async_queue_lock'
/usr/local/lib/libnids.a(libnids.o)(.text+0x382):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:337: undefined reference to `g_async_queue_length_unlocked'
/usr/local/lib/libnids.a(libnids.o)(.text+0x3c5):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:343: undefined reference to `g_async_queue_push_unlocked'
/usr/local/lib/libnids.a(libnids.o)(.text+0x8d6): In function `open_live':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:515: undefined reference to `pcap_open_live'
/usr/local/lib/libnids.a(libnids.o)(.text+0x979):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:505: undefined reference to `pcap_lookupdev'
/usr/local/lib/libnids.a(libnids.o)(.text+0x9a2): In function `cap_queue_process_thread':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:560: undefined reference to `g_async_queue_pop'
/usr/local/lib/libnids.a(libnids.o)(.text+0x9da):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:566: undefined reference to `g_thread_exit'
/usr/local/lib/libnids.a(libnids.o)(.text+0xa1f): In function `nids_init':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:594: undefined reference to `pcap_compile'
/usr/local/lib/libnids.a(libnids.o)(.text+0xa37):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:596: undefined reference to `pcap_setfilter'
/usr/local/lib/libnids.a(libnids.o)(.text+0xa4d):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:599: undefined reference to `pcap_datalink'
/usr/local/lib/libnids.a(libnids.o)(.text+0xb06):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:665: undefined reference to `g_thread_init'
/usr/local/lib/libnids.a(libnids.o)(.text+0xb0b):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:666: undefined reference to `g_async_queue_new'
/usr/local/lib/libnids.a(libnids.o)(.text+0xbfb):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:584: undefined reference to `pcap_open_offline'
/usr/local/lib/libnids.a(libnids.o)(.text+0xc6b): In function `nids_run':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:682: undefined reference to `g_thread_create_full'
/usr/local/lib/libnids.a(libnids.o)(.text+0xc86):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:683: undefined reference to `pcap_loop'
/usr/local/lib/libnids.a(libnids.o)(.text+0xcaf):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:686: undefined reference to `g_async_queue_push'
/usr/local/lib/libnids.a(libnids.o)(.text+0xd2e): In function `nids_exit':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:701: undefined reference to `g_async_queue_length'
/usr/local/lib/libnids.a(libnids.o)(.text+0xd7e):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:709: undefined reference to `pcap_geterr'
/usr/local/lib/libnids.a(libnids.o)(.text+0xdb4):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:711: undefined reference to `pcap_close'
/usr/local/lib/libnids.a(libnids.o)(.text+0xdf1): In function `nids_getfd':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:721: undefined reference to `pcap_fileno'
/usr/local/lib/libnids.a(libnids.o)(.text+0xe2d): In function `nids_next':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:733: undefined reference to `pcap_next'
/usr/local/lib/libnids.a(libnids.o)(.text+0xe5e):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:739: undefined reference to `g_thread_create_full'
/usr/local/lib/libnids.a(libnids.o)(.text+0xe95):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:742: undefined reference to `g_async_queue_push'
/usr/local/lib/libnids.a(libnids.o)(.text+0xef9):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:735: undefined reference to `pcap_geterr'
/usr/local/lib/libnids.a(libnids.o)(.text+0xf57): In function `nids_dispatch':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:753: undefined reference to `g_thread_create_full'
/usr/local/lib/libnids.a(libnids.o)(.text+0xf73):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:754: undefined reference to `pcap_dispatch'
/usr/local/lib/libnids.a(libnids.o)(.text+0xf9f):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:760: undefined reference to `g_async_queue_push'
/usr/local/lib/libnids.a(libnids.o)(.text+0xfcb):/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:757: undefined reference to `pcap_geterr'
/usr/local/lib/libnids.a(libnids.o)(.text+0x3b6): In function `nids_pcap_handler':
/home/lius/hx_sniffer/libnids-1.22/src/libnids.c:345: undefined reference to `g_async_queue_unlock'
/usr/local/lib/libnids.a(killtcp.o)(.text+0x43): In function `nids_killtcp_seq':
/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:23: undefined reference to `libnet_build_ip'
/usr/local/lib/libnids.a(killtcp.o)(.text+0x84):/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:25: undefined reference to `libnet_build_tcp'
/usr/local/lib/libnids.a(killtcp.o)(.text+0x91):/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:30: undefined reference to `libnet_do_checksum'
/usr/local/lib/libnids.a(killtcp.o)(.text+0xa2):/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:31: undefined reference to `libnet_write_ip'
/usr/local/lib/libnids.a(killtcp.o)(.text+0xc4):/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:33: undefined reference to `libnet_build_ip'
/usr/local/lib/libnids.a(killtcp.o)(.text+0x105):/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:35: undefined reference to `libnet_build_tcp'
/usr/local/lib/libnids.a(killtcp.o)(.text+0x112):/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:41: undefined reference to `libnet_do_checksum'
/usr/local/lib/libnids.a(killtcp.o)(.text+0x123):/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:42: undefined reference to `libnet_write_ip'
/usr/local/lib/libnids.a(killtcp.o)(.text+0x15c): In function `raw_init':
/home/lius/hx_sniffer/libnids-1.22/src/killtcp.c:51: undefined reference to `libnet_open_raw_sock'
collect2: ld returned 1 exit status
make: *** [sniffer] Error 1

還望高手指點(diǎn)迷津,小弟不勝感激!

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2007-07-27 08:31 |只看該作者

小弟在線等,還請(qǐng)有用過libnids庫(kù)的朋友能慷慨相助!

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2007-07-30 00:44 |只看該作者
老大 還是把代碼放到code里面吧

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2007-08-01 15:24 |只看該作者

關(guān)于libnids庫(kù)的問題

libnids庫(kù)編譯的時(shí)候需要pcap和net庫(kù),所以你的編譯參數(shù)不對(duì)

應(yīng)該為 gcc -g -o sniffer main.c -lnids -lpcap -lnet

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2023-04-02 19:54 |只看該作者
我也遇到了這樣的問題,解決方法
要將 -lnet -lpcap  放在 -lnids 后面
g++ test.c -lnids -lnet -lpcap -lgthread-2.0 -lglib-2.0


您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP