|
From: <sat...@us...> - 2010-03-29 15:06:58
|
Revision: 248
http://w-meter.svn.sourceforge.net/w-meter/?rev=248&view=rev
Author: sathakselva
Date: 2010-03-29 15:06:52 +0000 (Mon, 29 Mar 2010)
Log Message:
-----------
fix for ICMP checksum calculation
Modified Paths:
--------------
frame_injection_g/trunk/src/data_dataFrame.cpp
frame_injection_g/trunk/src/data_dataFrame.h
frame_injection_g/trunk/src/data_dataFrame.ui
frame_injection_g/trunk/src/data_dataframe_cpp.cpp
Modified: frame_injection_g/trunk/src/data_dataFrame.cpp
===================================================================
--- frame_injection_g/trunk/src/data_dataFrame.cpp 2010-03-23 13:19:18 UTC (rev 247)
+++ frame_injection_g/trunk/src/data_dataFrame.cpp 2010-03-29 15:06:52 UTC (rev 248)
@@ -343,53 +343,56 @@
lineedit_payload = new QLineEdit( groupBox3, "lineedit_payload" );
lineedit_payload->setGeometry( QRect( 360, 140, 230, 22 ) );
- lineedit_src_ip1 = new QLineEdit( groupBox3, "lineedit_src_ip1" );
- lineedit_src_ip1->setGeometry( QRect( 90, 149, 40, 28 ) );
- lineedit_src_ip1->setMaxLength( 3 );
+ lineedit_ip_ttl = new QLineEdit( groupBox3, "lineedit_ip_ttl" );
+ lineedit_ip_ttl->setGeometry( QRect( 90, 110, 60, 23 ) );
+ lineedit_msdu_size = new QLineEdit( groupBox3, "lineedit_msdu_size" );
+ lineedit_msdu_size->setGeometry( QRect( 490, 30, 90, 23 ) );
+
lineedit_TOS1 = new QLineEdit( groupBox3, "lineedit_TOS1" );
lineedit_TOS1->setGeometry( QRect( 90, 30, 17, 23 ) );
+ lineedit_TOS1->setMaxLength( 1 );
lineedit_TOS2 = new QLineEdit( groupBox3, "lineedit_TOS2" );
lineedit_TOS2->setGeometry( QRect( 110, 30, 17, 23 ) );
+ lineedit_TOS2->setMaxLength( 1 );
lineedit_TOS3 = new QLineEdit( groupBox3, "lineedit_TOS3" );
lineedit_TOS3->setGeometry( QRect( 130, 30, 17, 23 ) );
+ lineedit_TOS3->setMaxLength( 1 );
lineedit_TOS4 = new QLineEdit( groupBox3, "lineedit_TOS4" );
lineedit_TOS4->setGeometry( QRect( 150, 30, 17, 23 ) );
+ lineedit_TOS4->setMaxLength( 1 );
lineedit_TOS5 = new QLineEdit( groupBox3, "lineedit_TOS5" );
lineedit_TOS5->setGeometry( QRect( 170, 30, 17, 23 ) );
+ lineedit_TOS5->setMaxLength( 1 );
lineedit_TOS6 = new QLineEdit( groupBox3, "lineedit_TOS6" );
lineedit_TOS6->setGeometry( QRect( 190, 30, 17, 23 ) );
+ lineedit_TOS6->setMaxLength( 1 );
lineedit_TOS7 = new QLineEdit( groupBox3, "lineedit_TOS7" );
lineedit_TOS7->setGeometry( QRect( 210, 30, 17, 23 ) );
+ lineedit_TOS7->setMaxLength( 1 );
lineedit_TOS8 = new QLineEdit( groupBox3, "lineedit_TOS8" );
lineedit_TOS8->setGeometry( QRect( 230, 30, 17, 23 ) );
+ lineedit_TOS8->setMaxLength( 1 );
lineedit_flag1 = new QLineEdit( groupBox3, "lineedit_flag1" );
lineedit_flag1->setGeometry( QRect( 90, 70, 17, 23 ) );
+ lineedit_flag1->setMaxLength( 1 );
lineedit_flag2 = new QLineEdit( groupBox3, "lineedit_flag2" );
lineedit_flag2->setGeometry( QRect( 110, 70, 17, 23 ) );
+ lineedit_flag2->setMaxLength( 1 );
lineedit_flag3 = new QLineEdit( groupBox3, "lineedit_flag3" );
lineedit_flag3->setGeometry( QRect( 130, 70, 17, 23 ) );
+ lineedit_flag3->setMaxLength( 1 );
- lineedit_ip_ttl = new QLineEdit( groupBox3, "lineedit_ip_ttl" );
- lineedit_ip_ttl->setGeometry( QRect( 90, 110, 60, 23 ) );
-
- lineedit_msdu_size = new QLineEdit( groupBox3, "lineedit_msdu_size" );
- lineedit_msdu_size->setGeometry( QRect( 490, 30, 90, 23 ) );
-
- lineedit_src_ip2 = new QLineEdit( groupBox3, "lineedit_src_ip2" );
- lineedit_src_ip2->setGeometry( QRect( 130, 149, 40, 28 ) );
- lineedit_src_ip2->setMaxLength( 3 );
-
le_src_ip3 = new QLineEdit( groupBox3, "le_src_ip3" );
le_src_ip3->setGeometry( QRect( 170, 149, 40, 28 ) );
le_src_ip3->setMaxLength( 3 );
@@ -398,16 +401,24 @@
le_src_ip4->setGeometry( QRect( 210, 149, 40, 28 ) );
le_src_ip4->setMaxLength( 3 );
+ lineedit_src_ip2 = new QLineEdit( groupBox3, "lineedit_src_ip2" );
+ lineedit_src_ip2->setGeometry( QRect( 130, 149, 40, 28 ) );
+ lineedit_src_ip2->setMaxLength( 3 );
+
+ lineedit_src_ip1 = new QLineEdit( groupBox3, "lineedit_src_ip1" );
+ lineedit_src_ip1->setGeometry( QRect( 90, 149, 40, 28 ) );
+ lineedit_src_ip1->setMaxLength( 3 );
+
le_dest_ip2 = new QLineEdit( groupBox3, "le_dest_ip2" );
le_dest_ip2->setGeometry( QRect( 130, 188, 40, 28 ) );
le_dest_ip2->setMaxLength( 3 );
le_dest_ip3 = new QLineEdit( groupBox3, "le_dest_ip3" );
- le_dest_ip3->setGeometry( QRect( 170, 189, 40, 28 ) );
+ le_dest_ip3->setGeometry( QRect( 170, 188, 40, 28 ) );
le_dest_ip3->setMaxLength( 3 );
le_dest_ip4 = new QLineEdit( groupBox3, "le_dest_ip4" );
- le_dest_ip4->setGeometry( QRect( 210, 189, 40, 28 ) );
+ le_dest_ip4->setGeometry( QRect( 210, 188, 40, 28 ) );
le_dest_ip4->setMaxLength( 3 );
le_dest_ip1 = new QLineEdit( this, "le_dest_ip1" );
@@ -653,6 +664,10 @@
textLabel4_3->setText( tr2i18n( "Source IP" ) );
textLabel1_3->setText( tr2i18n( "MSDU size" ) );
QToolTip::add( lineedit_payload, tr2i18n( "Payload" ) );
+ lineedit_ip_ttl->setText( tr2i18n( "100" ) );
+ lineedit_msdu_size->setText( QString::null );
+ lineedit_msdu_size->setInputMask( tr2i18n( "0000; " ) );
+ QToolTip::add( lineedit_msdu_size, tr2i18n( "MSDU Size(0-2304)" ) );
lineedit_TOS1->setText( tr2i18n( "0" ) );
lineedit_TOS2->setText( tr2i18n( "0" ) );
lineedit_TOS3->setText( tr2i18n( "0" ) );
@@ -664,10 +679,14 @@
lineedit_flag1->setText( tr2i18n( "0" ) );
lineedit_flag2->setText( tr2i18n( "0" ) );
lineedit_flag3->setText( tr2i18n( "0" ) );
- lineedit_ip_ttl->setText( tr2i18n( "100" ) );
- lineedit_msdu_size->setText( QString::null );
- lineedit_msdu_size->setInputMask( tr2i18n( "0000; " ) );
- QToolTip::add( lineedit_msdu_size, tr2i18n( "MSDU Size(0-2304)" ) );
+ le_src_ip3->setText( tr2i18n( "000" ) );
+ le_src_ip4->setText( tr2i18n( "000" ) );
+ lineedit_src_ip2->setText( tr2i18n( "000" ) );
+ lineedit_src_ip1->setText( tr2i18n( "000" ) );
+ le_dest_ip2->setText( tr2i18n( "000" ) );
+ le_dest_ip3->setText( tr2i18n( "000" ) );
+ le_dest_ip4->setText( tr2i18n( "000" ) );
+ le_dest_ip1->setText( tr2i18n( "000" ) );
}
void data_dataFrame::data_run_click()
Modified: frame_injection_g/trunk/src/data_dataFrame.h
===================================================================
--- frame_injection_g/trunk/src/data_dataFrame.h 2010-03-23 13:19:18 UTC (rev 247)
+++ frame_injection_g/trunk/src/data_dataFrame.h 2010-03-29 15:06:52 UTC (rev 248)
@@ -108,7 +108,8 @@
QLabel* textLabel4_3;
QLabel* textLabel1_3;
QLineEdit* lineedit_payload;
- QLineEdit* lineedit_src_ip1;
+ QLineEdit* lineedit_ip_ttl;
+ QLineEdit* lineedit_msdu_size;
QLineEdit* lineedit_TOS1;
QLineEdit* lineedit_TOS2;
QLineEdit* lineedit_TOS3;
@@ -120,11 +121,10 @@
QLineEdit* lineedit_flag1;
QLineEdit* lineedit_flag2;
QLineEdit* lineedit_flag3;
- QLineEdit* lineedit_ip_ttl;
- QLineEdit* lineedit_msdu_size;
- QLineEdit* lineedit_src_ip2;
QLineEdit* le_src_ip3;
QLineEdit* le_src_ip4;
+ QLineEdit* lineedit_src_ip2;
+ QLineEdit* lineedit_src_ip1;
QLineEdit* le_dest_ip2;
QLineEdit* le_dest_ip3;
QLineEdit* le_dest_ip4;
Modified: frame_injection_g/trunk/src/data_dataFrame.ui
===================================================================
--- frame_injection_g/trunk/src/data_dataFrame.ui 2010-03-23 13:19:18 UTC (rev 247)
+++ frame_injection_g/trunk/src/data_dataFrame.ui 2010-03-29 15:06:52 UTC (rev 248)
@@ -1677,22 +1677,44 @@
</widget>
<widget class="QLineEdit">
<property name="name">
- <cstring>lineedit_src_ip1</cstring>
+ <cstring>lineedit_ip_ttl</cstring>
</property>
<property name="geometry">
<rect>
<x>90</x>
- <y>149</y>
- <width>40</width>
- <height>28</height>
+ <y>110</y>
+ <width>60</width>
+ <height>23</height>
</rect>
</property>
- <property name="maxLength">
- <number>3</number>
+ <property name="text">
+ <string>100</string>
</property>
</widget>
<widget class="QLineEdit">
<property name="name">
+ <cstring>lineedit_msdu_size</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>490</x>
+ <y>30</y>
+ <width>90</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ <property name="inputMask">
+ <string>0000; </string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>MSDU Size(0-2304)</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit">
+ <property name="name">
<cstring>lineedit_TOS1</cstring>
</property>
<property name="geometry">
@@ -1706,6 +1728,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1722,6 +1747,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1738,6 +1766,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1754,6 +1785,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1770,6 +1804,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1786,6 +1823,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1802,6 +1842,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1818,6 +1861,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1834,6 +1880,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1850,6 +1899,9 @@
<property name="text">
<string>0</string>
</property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
</widget>
<widget class="QLineEdit">
<property name="name">
@@ -1866,89 +1918,82 @@
<property name="text">
<string>0</string>
</property>
- </widget>
- <widget class="QLineEdit">
- <property name="name">
- <cstring>lineedit_ip_ttl</cstring>
+ <property name="maxLength">
+ <number>1</number>
</property>
- <property name="geometry">
- <rect>
- <x>90</x>
- <y>110</y>
- <width>60</width>
- <height>23</height>
- </rect>
- </property>
- <property name="text">
- <string>100</string>
- </property>
</widget>
<widget class="QLineEdit">
<property name="name">
- <cstring>lineedit_msdu_size</cstring>
+ <cstring>le_src_ip3</cstring>
</property>
<property name="geometry">
<rect>
- <x>490</x>
- <y>30</y>
- <width>90</width>
- <height>23</height>
+ <x>170</x>
+ <y>149</y>
+ <width>40</width>
+ <height>28</height>
</rect>
</property>
<property name="text">
- <string></string>
+ <string>000</string>
</property>
- <property name="inputMask">
- <string>0000; </string>
+ <property name="maxLength">
+ <number>3</number>
</property>
- <property name="toolTip" stdset="0">
- <string>MSDU Size(0-2304)</string>
- </property>
</widget>
<widget class="QLineEdit">
<property name="name">
- <cstring>lineedit_src_ip2</cstring>
+ <cstring>le_src_ip4</cstring>
</property>
<property name="geometry">
<rect>
- <x>130</x>
+ <x>210</x>
<y>149</y>
<width>40</width>
<height>28</height>
</rect>
</property>
+ <property name="text">
+ <string>000</string>
+ </property>
<property name="maxLength">
<number>3</number>
</property>
</widget>
<widget class="QLineEdit">
<property name="name">
- <cstring>le_src_ip3</cstring>
+ <cstring>lineedit_src_ip2</cstring>
</property>
<property name="geometry">
<rect>
- <x>170</x>
+ <x>130</x>
<y>149</y>
<width>40</width>
<height>28</height>
</rect>
</property>
+ <property name="text">
+ <string>000</string>
+ </property>
<property name="maxLength">
<number>3</number>
</property>
</widget>
<widget class="QLineEdit">
<property name="name">
- <cstring>le_src_ip4</cstring>
+ <cstring>lineedit_src_ip1</cstring>
</property>
<property name="geometry">
<rect>
- <x>210</x>
+ <x>90</x>
<y>149</y>
<width>40</width>
<height>28</height>
</rect>
</property>
+ <property name="text">
+ <string>000</string>
+ </property>
<property name="maxLength">
<number>3</number>
</property>
@@ -1965,6 +2010,9 @@
<height>28</height>
</rect>
</property>
+ <property name="text">
+ <string>000</string>
+ </property>
<property name="maxLength">
<number>3</number>
</property>
@@ -1976,11 +2024,14 @@
<property name="geometry">
<rect>
<x>170</x>
- <y>189</y>
+ <y>188</y>
<width>40</width>
<height>28</height>
</rect>
</property>
+ <property name="text">
+ <string>000</string>
+ </property>
<property name="maxLength">
<number>3</number>
</property>
@@ -1992,11 +2043,14 @@
<property name="geometry">
<rect>
<x>210</x>
- <y>189</y>
+ <y>188</y>
<width>40</width>
<height>28</height>
</rect>
</property>
+ <property name="text">
+ <string>000</string>
+ </property>
<property name="maxLength">
<number>3</number>
</property>
@@ -2015,6 +2069,9 @@
<height>28</height>
</rect>
</property>
+ <property name="text">
+ <string>000</string>
+ </property>
<property name="maxLength">
<number>3</number>
</property>
Modified: frame_injection_g/trunk/src/data_dataframe_cpp.cpp
===================================================================
--- frame_injection_g/trunk/src/data_dataframe_cpp.cpp 2010-03-23 13:19:18 UTC (rev 247)
+++ frame_injection_g/trunk/src/data_dataframe_cpp.cpp 2010-03-29 15:06:52 UTC (rev 248)
@@ -331,9 +331,6 @@
for (i = 0;i < 2;i++)
seq_ctrl_char[i] = * ( ( (unsigned char*) & seq_ctrl_int) + i);
- uint16_t temp_payload_size = lineedit_payload->text().length();
- const char *str_payload = lineedit_payload->text();
-
memcpy (frame, &frame_ctrl, sizeof (frame_ctrl));
frame += sizeof (frame_ctrl);
@@ -354,6 +351,7 @@
uint8_t llc_hdr[8] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00};
int msdu_size = lineedit_msdu_size->text().toInt();
+ const char *str_payload = lineedit_payload->text();
if (msdu_size == 0)
{
@@ -372,78 +370,86 @@
{
if ( (lineedit_src_ip1->text() != "") && (lineedit_src_ip1->text().toInt() < 256) && (lineedit_src_ip2->text() != "") && (lineedit_src_ip2->text().toInt() < 256) && (le_src_ip3->text() != "") && (le_src_ip3->text().toInt() < 256) && (le_src_ip4->text() != "") && (le_src_ip4->text().toInt() < 256))
{
-
if ( (le_dest_ip1->text() != "") && (le_dest_ip1->text().toInt() < 256) && (le_dest_ip2->text() != "") && (le_dest_ip2->text().toInt() < 256) && (le_dest_ip3->text() != "") && (le_dest_ip3->text().toInt() < 256) && (le_dest_ip4->text() != "") && (le_dest_ip4->text().toInt() < 256))
{
- uint8_t ttl = lineedit_ip_ttl->text().toInt();
- unsigned char icmp_hdr[] = {0x08, 0x00, 0xd5, 0x1a, 0x7b, 0x0e, 0x01, 0x30};
- unsigned char *ptr = (unsigned char *) & ip_hdr;
- int total_length = sizeof (icmp_hdr) + msdu_size + sizeof (ip_hdr);
+ if (lineedit_TOS1->text().toInt() <= 1 && lineedit_TOS1->text() != "" && lineedit_TOS2->text().toInt() <= 1 && lineedit_TOS2->text() != "" && lineedit_TOS3->text().toInt() <= 1 && lineedit_TOS3->text() != "" && lineedit_TOS4->text().toInt() <= 1 && lineedit_TOS4->text() != "" && lineedit_TOS5->text().toInt() <= 1 && lineedit_TOS5->text() != "" && lineedit_TOS6->text().toInt() <= 1 && lineedit_TOS6->text() != "" && lineedit_TOS7->text().toInt() <= 1 && lineedit_TOS7->text() != "" && lineedit_TOS8->text().toInt() <= 1 && lineedit_TOS8->text() != "")
+ {
+ if (radiobutton_user_defined->isChecked() == 1)
+ msdu_size = lineedit_payload->text().length();
- memset (&ip_hdr, 0, sizeof (ip_hdr));
+ uint8_t ttl = lineedit_ip_ttl->text().toInt();
+ unsigned char icmp_hdr[] = {0x08, 0x00, 0x00, 0x00, 0x7b, 0x0e, 0x01, 0x30};
+ unsigned char *ptr = (unsigned char *) & ip_hdr;
+ int total_length = sizeof (icmp_hdr) + msdu_size + sizeof (ip_hdr);
- ip_hdr.ver_len = 0x45;
- ip_hdr.dscp = 0x00;
- ip_hdr.total_len = ( (total_length >> 8) & 0x00ff) | ( (total_length << 8) & 0xff00);
- ip_hdr.id = 0x0000;
- ip_hdr.flag_offset = 0x0000;
- ip_hdr.ttl = ttl;
- ip_hdr.protocol = 0x01; // ICMP Protocol
+ memset (&ip_hdr, 0, sizeof (ip_hdr));
- ip_hdr.src_ip[0] = (unsigned char) lineedit_src_ip1->text().toInt();
- ip_hdr.src_ip[1] = (unsigned char) lineedit_src_ip2->text().toInt();
- ip_hdr.src_ip[2] = (unsigned char) le_src_ip3->text().toInt();
- ip_hdr.src_ip[3] = (unsigned char) le_src_ip4->text().toInt();
+ ip_hdr.ver_len = 0x45;
+ ip_hdr.dscp = mac.bits_to_byte (lineedit_TOS1->text(), lineedit_TOS2->text(), lineedit_TOS3->text(), lineedit_TOS4->text(), lineedit_TOS5->text(), lineedit_TOS6->text(), lineedit_TOS7->text(), lineedit_TOS8->text());
+ ip_hdr.total_len = htons (total_length);
+ ip_hdr.id = 0x0000;
+ ip_hdr.flag_offset = 0x0000;
+ ip_hdr.ttl = ttl;
+ ip_hdr.protocol = 0x01; // ICMP Protocol
- ip_hdr.dest_ip[0] = (unsigned char) le_dest_ip1->text().toInt();
- ip_hdr.dest_ip[1] = (unsigned char) le_dest_ip2->text().toInt();
- ip_hdr.dest_ip[2] = (unsigned char) le_dest_ip3->text().toInt();
- ip_hdr.dest_ip[3] = (unsigned char) le_dest_ip4->text().toInt();
+ ip_hdr.src_ip[0] = (unsigned char) lineedit_src_ip1->text().toInt();
+ ip_hdr.src_ip[1] = (unsigned char) lineedit_src_ip2->text().toInt();
+ ip_hdr.src_ip[2] = (unsigned char) le_src_ip3->text().toInt();
+ ip_hdr.src_ip[3] = (unsigned char) le_src_ip4->text().toInt();
- int check_sum = ip_check_sum (ptr, sizeof (ip_hdr));
- ip_hdr.checksum = ( (check_sum >> 8) & 0x00ff) | ( (check_sum << 8) & 0xff00);
- memcpy (frame, &ip_hdr, sizeof (ip_hdr));
- frame += sizeof (ip_hdr);
+ ip_hdr.dest_ip[0] = (unsigned char) le_dest_ip1->text().toInt();
+ ip_hdr.dest_ip[1] = (unsigned char) le_dest_ip2->text().toInt();
+ ip_hdr.dest_ip[2] = (unsigned char) le_dest_ip3->text().toInt();
+ ip_hdr.dest_ip[3] = (unsigned char) le_dest_ip4->text().toInt();
- /* TODO: Calculate ICMP header checksum here */
- // modify the length
+ int check_sum = ip_check_sum (ptr, sizeof (ip_hdr));
+ ip_hdr.checksum = htons (check_sum);
+ memcpy (frame, &ip_hdr, sizeof (ip_hdr));
+ frame += sizeof (ip_hdr);
- memcpy (frame, &icmp_hdr, sizeof (icmp_hdr));
- frame += sizeof (icmp_hdr);
- if (radiobutton_user_defined->isChecked() == 1)
- {
- memcpy (frame, str_payload, temp_payload_size);
- frame += temp_payload_size;
- frame_len = frame - &msg[0];
- func_data_call (msg, frame_len);
- }
- else if (radiobutton_user_defined->isChecked() == 0)
- {
- unsigned char icmp_payload[msdu_size];
+ unsigned char *icmp_packet;
+ int icmp_hdr_len = sizeof (icmp_hdr);
+ int icmp_len = msdu_size + icmp_hdr_len;
- for (int i = 0; i < msdu_size; i++)
- icmp_payload[i] = 'a';
+ icmp_packet = (unsigned char*) malloc (sizeof (unsigned char) * icmp_len );
+ if (icmp_packet == NULL)
+ {
+ printf ("Unable to allocate memory...\n");
+ exit (1);
+ }
- memcpy (frame, &icmp_payload, msdu_size);
- frame += msdu_size;
+ memcpy (icmp_packet, &icmp_hdr, sizeof (icmp_hdr));
+
+ if (radiobutton_user_defined->isChecked() == 1)
+ memcpy (icmp_packet+icmp_hdr_len, str_payload, msdu_size);
+ else
+ {
+ unsigned char icmp_payload[msdu_size];
+ memset (icmp_payload, 'a', msdu_size);
+ memcpy (icmp_packet+icmp_hdr_len, &icmp_payload, msdu_size);
+ }
+ int offset = 2;
+ unsigned short icmp_checksum = ip_check_sum (icmp_packet, icmp_len);
+ icmp_checksum = htons (icmp_checksum);
+ printf ("Checksum : %d\n", icmp_checksum);
+ for (i = 0;i < 2;i++)
+ icmp_packet[offset + i] = * ( ( (unsigned char*) & icmp_checksum) + i);
+ memcpy (frame, icmp_packet, icmp_len);
+ frame += icmp_len;
frame_len = frame - &msg[0];
func_data_call (msg, frame_len);
}
+ else
+ KMessageBox::error (this, "Invalid ToS field configuration");
}
else
- {
- KMessageBox::error (this, "Invalid Destination IP AddressT");
- }
+ KMessageBox::error (this, "Invalid Destination IP Address");
}
else
- {
KMessageBox::error (this, "Invalid source IP address");
- }
}
else
- {
KMessageBox::error (this, "TTL should be less than 256");
- }
}
}
else
@@ -695,11 +701,11 @@
fclose (fptr);
}
-unsigned short data_dataframe_cpp::ip_check_sum (unsigned char *buff, int len_ip_header)
+unsigned short data_dataframe_cpp::ip_check_sum (unsigned char *buff, int len)
{
unsigned short word16, i;
unsigned long sum = 0; // make 16 bit words out of every two adjacent 8 bit words in the packet and add them up
- for (i = 0;i < len_ip_header;i = i + 2)
+ for (i = 0;i < len;i = i + 2)
{
word16 = ( (buff[i] << 8) & 0xFF00) + (buff[i+1] & 0xFF);
sum = sum + (unsigned long) word16;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|