Skip to content

add dpsws2016 sample application #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added sample/dpsws2016/ICMP-captured.pcap
Binary file not shown.
Binary file added sample/dpsws2016/ICMP-generated.pcap
Binary file not shown.
7 changes: 7 additions & 0 deletions sample/dpsws2016/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all:
g++ -o dpsws2016-analyze -g -O0 -std=c++11 -I../../include/ dpsws2016-analyze.cc -L../../ -lpgen2
g++ -o dpsws2016-generate -g -O0 -std=c++11 -I../../include/ dpsws2016-generate.cc -L../../ -lpgen2

clean:
rm -rf a.out dpsws2016-analyze dpsws2016-create

44 changes: 44 additions & 0 deletions sample/dpsws2016/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# これは何

DPSWS2016田沢湖で発案した
アプリケーションのコードです

テキストで指定したフォーマットでパケットを解析するdpsws2016-analyzeと、
テキストで指定したデータメッセージのパケットを作成するdpsws2016-genereteのプロトタイプなプログラムです。

## Usage

```
$ make clean
$ make
$ sudo ./dpsws2016-analyze ICMP-captured.pcap < dpsws2016-fmt-ICMP.txt
$ sudo ./dpsws2016-generate ICMP-generated.pcap < dpsws2016-msg-ICMP.txt
```

### パケット指定用フォーマット

# フォーマット書式

description:dig|hex:bytes[:text]
.............

# フォーマット書式の解説

description = 任意のASCIIテキスト
dig|hex = データの表記方法の選択、dig=10進数表記、hex=16進数表記
bytes = データのバイト数、0または-1を指定すると無制限を指定
[text] = パケット生成時に投入するデータ自体、前記のデータ指定方法(dig|hex)に則って、1バイトずつ、スペース区切りで記載する

# サンプル

dpsws2016-fmt-ICMP.txt = ICMPパケットを解析するためのフォーマット書式例(データ無し)
dpsws2016-msg-ICMP.txt = ICMPパケットを作成するためのフォーマット書式例(データ有り)

#### 注意事項

現在のプロトタイプなプログラムでは、解析(dpsws2016-analyze)も作成(dpsws2016-generate)も、1パケットしか取り扱えません。
解析時に複数パケットが含まれるpcapファイルをしていた場合、先頭の1パケットだけを解析します。



Binary file added sample/dpsws2016/dpsws2016-analyze
Binary file not shown.
40 changes: 40 additions & 0 deletions sample/dpsws2016/dpsws2016-analyze.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

#include <pgen2.h>
#include <time.h>
#include "dpsws2016.h"

static const char* getnow()
{
static char str[32];
time_t now = time(NULL);
struct tm* p = localtime(&now);
sprintf(str, "%02d:%02d:%02d", p->tm_hour, p->tm_min, p->tm_sec);
return str;
}

int main(int argc, char** argv)
{
if (argc != 2) {
fprintf(stderr, "Usage: %s pcapfile \n", argv[0]);
return -1;
}

pgen::pcap_stream packet_stream(argv[1], pgen::open_mode::pcap_read);

uint8_t buf[10000];
size_t recvlen;
try {
recvlen = packet_stream.recv(buf, sizeof buf);
} catch (std::exception& e) {
return 0;
}

if ( is_dpsws2016_packet(buf, recvlen) ) {
dpsws2016 pack(buf, recvlen);
printf("[%s] 0x%04x: \n", getnow());
printf("%s\n", (pack.DPSWS2016.print_str()).c_str() );
}

return 0;
}

10 changes: 10 additions & 0 deletions sample/dpsws2016/dpsws2016-fmt-ICMP.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Ether no vlan skip :hex:14
IP skip:hex:9
IP Proto:dig:1
IP skip:hex:2
IP Src Addr:hex:4
IP Dst Addr:hex:4
ICMP Type:dig:1
ICMP Code:dig:1
ICMP Checksum:hex:2
ICMP Data:hex:-1
Binary file added sample/dpsws2016/dpsws2016-generate
Binary file not shown.
24 changes: 24 additions & 0 deletions sample/dpsws2016/dpsws2016-generate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#include <pgen2.h>
#include "dpsws2016.h"

int main(int argc, char** argv)
{

if (argc != 2) {
fprintf(stderr, "Usage: %s pcapfile \n", argv[0]);
return -1;
}

try {
dpsws2016 pack;
pack.compile();
pgen::pcap_stream pcap(argv[1], pgen::open_mode::pcap_write);
pcap << pack;
} catch (std::exception& e) {
printf("%s \n", e.what());
}

return 0;
}

10 changes: 10 additions & 0 deletions sample/dpsws2016/dpsws2016-msg-ICMP.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Ether no vlan skip :hex:14:00 00 00 00 00 00 00 00 00 00 00 00 08 00
IP skip:hex:9:45 00 00 54 13 E3 00 00 40
IP Proto:dig:1:1
IP skip:hex:2:68 C4
IP Src Addr:hex:4:7F 00 00 01
IP Dst Addr:hex:4:7F 00 00 01
ICMP Type:dig:1:0
ICMP Code:dig:1:0
ICMP Checksum:hex:2:BA A7
ICMP Data:hex:-1:25 80 00 01 49 2C 24 58 00 00 00 00 EE 7F 05 00 00 00 00 00 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37
Loading