2
* packETH - ethernet packet generator
3
* By Miha Jemec <jemcek@gmail.com>
4
* Copyright 2003 Miha Jemec, Iskratel
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
#include "loadpacket.h"
31
#include "callbacks.h"
32
//#include "libnet/libnet-headers.h"
33
//#include "headers.h"
35
static GtkWidget *w1, *w2, *w3, *w4, *w5, *w6, *w7, *w8;
44
protocol_type protokol;
46
/* this one loads the parameters from file into notebook2 (Gen-b page) */
47
int load_gen_b_data(GtkButton *button, FILE *file_p) {
54
w1 = lookup_widget(GTK_WIDGET (button), "radiobutton35");
55
w2 = lookup_widget(GTK_WIDGET (button), "radiobutton34");
56
w3 = lookup_widget(GTK_WIDGET (button), "optionmenu9");
57
w4 = lookup_widget(GTK_WIDGET (button), "entry109");
58
w5 = lookup_widget(GTK_WIDGET (button), "entry110");
59
w6 = lookup_widget(GTK_WIDGET(button), "checkbutton35");
60
w7 = lookup_widget(GTK_WIDGET(button), "checkbutton37");
61
/* we read the file ohh python, where are you... */
64
/* rules for config files:
65
* - comments start with #
66
* - there can be spaces and newlines
67
* - only digits and - are acceptable characters
70
/* we have to limit the lines we read paramters from */
71
while ( (c = fgetc( file_p )) != EOF ) {
72
/* all the comment lines, starting with # , no limit for comment lines*/
73
if ( (j==0) && (c == 35)) {
74
/* ok, read till the end of line */
75
while ( getc(file_p) != 10);
79
/* let's limit the size */
80
if ( (j > 9) || (k > 2) )
83
/* ok, it is not a comment line so the info: only digits and minus sign are acceptable */
84
if ( (isdigit(c) != 0) || (c == 45) ) {
89
/* no digit is it a newline? */
93
if (strlen(buff) == 0)
95
buff4[k] = strtol(buff, (char **)NULL, 10);
97
strncpy(&buffc[k][j], buff, 9);
100
/* not, ok this is an error */
107
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
108
else if (buff4[0] == 0)
109
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w1), 1);
114
/* adjusting parameters...
115
if ( (buff4[1] >= 0) && (buff4[1] <= 4) )
116
gtk_option_menu_set_history (GTK_OPTION_MENU (w3), buff4[1]);
121
if (buff4[1] == - 3) {
122
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 1);
123
gtk_entry_set_text(GTK_ENTRY(w4), "");
124
gtk_widget_set_sensitive (w4, FALSE);
126
else if ( (buff4[1] > 0) && (buff4[1] <= 9999999) ) {
127
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 0);
128
gtk_widget_set_sensitive (w4, TRUE);
129
gtk_entry_set_text(GTK_ENTRY(w4), &buffc[1][0]);
136
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w7), 1);
137
gtk_entry_set_text(GTK_ENTRY(w5), "");
138
gtk_widget_set_sensitive (w5, FALSE);
140
else if ( (buff4[2] >= 1) && (buff4[2] <= 999999999) ) {
141
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w7), 0);
142
gtk_widget_set_sensitive (w5, TRUE);
143
gtk_entry_set_text(GTK_ENTRY(w5), &buffc[2][0]);
154
/* this one loads the parameters from file into notebook2 (Gen-s page) */
155
int load_gen_s_data(GtkButton *button, FILE *file_p) {
161
char *ptr = NULL, *ptr2 = NULL;
167
/* rules for config files:
168
* - comments start with #
169
* - there can be spaces and newlines
170
* - only digits and - are acceptable characters
173
while ( (c = fgetc( file_p )) != EOF ) {
174
/* all the comment lines, starting with # */
175
if ( (j==0) && (c == 35)) {
176
while ( getc(file_p) != 10);
179
/* all blank lines */
180
if ( (j==0) && (c == 10))
182
/* read the whole lines */
183
if ((isascii(c) != 0) && (j<200) && (c!=10) && (k<11)) {
188
/* , or \n mean end of string */
198
w1 = lookup_widget(GTK_WIDGET (button), "radiobutton36");
199
w2 = lookup_widget(GTK_WIDGET (button), "radiobutton37");
200
w4 = lookup_widget(GTK_WIDGET (button), "entry151");
201
w5 = lookup_widget(GTK_WIDGET (button), "entry152");
202
w6 = lookup_widget(GTK_WIDGET(button), "checkbutton36");
204
/* first line should have three parameters */
205
/* first is absolute or relative delay, allowed values 0 and 1 */
206
if (strncmp(&buffc[0][0], "1", 1) == 0)
207
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w1), 1);
208
else if (strncmp(&buffc[0][0], "0", 1) == 0)
209
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
214
/* second is number of packets: -3 means infinite, or 1 till 9999999) */
215
if (strncmp(&buffc[0][2], "-3", 2) == 0) {
216
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 1);
217
gtk_entry_set_text(GTK_ENTRY(w4), "");
218
gtk_widget_set_sensitive (w4, FALSE);
222
if ( (ptr = strchr(&buffc[0][2], 44)) == NULL) {
226
buff4[0] = strtol(&buffc[0][2], (char **)NULL, 10);
228
if ( (buff4[0] >= 0) && (buff4[0] <= 9999999) ) {
229
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 0);
230
gtk_widget_set_sensitive (w4, TRUE);
231
gtk_entry_set_text(GTK_ENTRY(w4), &buffc[0][2]);
238
/* last parameter is delay between sequences */
239
buff4[0] = strtol(ptr+1, (char **)NULL, 10);
241
if ( (buff4[0] >= 0) && (buff4[0] <= 999999999) ) {
242
gtk_entry_set_text(GTK_ENTRY(w5), ptr+1);
248
/* we have to clean everything */
249
for (j = 0; j < 10; j++) {
250
snprintf(buff, 10, "entry%d", 111+j);
251
w2 = lookup_widget(GTK_WIDGET (button), buff);
252
gtk_entry_set_text(GTK_ENTRY(w2), "");
253
snprintf(buff, 100, "entry%d", 121+j);
254
w3 = lookup_widget(GTK_WIDGET (button), buff);
255
gtk_entry_set_text(GTK_ENTRY(w3), "");
256
snprintf(buff, 100, "entry%d", 131+j);
257
w3 = lookup_widget(GTK_WIDGET (button), buff);
258
gtk_entry_set_text(GTK_ENTRY(w3), "");
259
snprintf(buff, 100, "entry%d", 141+j);
260
w3 = lookup_widget(GTK_WIDGET (button), buff);
261
gtk_entry_set_text(GTK_ENTRY(w3), "");
262
snprintf(buff, 100, "checkbutton%d", 25+j);
263
w2 = lookup_widget(GTK_WIDGET(button), buff);
264
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 0);
267
/* and now all the rest */
268
for (j = 1; j < k; j++) {
269
/* first is packet name */
270
if ( (ptr2 = strchr(&buffc[j][0], 44)) == NULL)
273
if ( (strlen(&buffc[j][0]) > 0 ) && (strlen(&buffc[j][0]) < 70) ) {
274
snprintf(buff, 10, "entry%d", 110+j);
275
w2 = lookup_widget(GTK_WIDGET (button), buff);
276
gtk_entry_set_text(GTK_ENTRY(w2), &buffc[j][0]);
281
/* number of packets */
283
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
287
cc = strtol(ptr, (char **)NULL, 10);
288
if ( (cc < 0) || (cc > 9999999) ) {
291
snprintf(buff, 100, "entry%d", 120+j);
292
w3 = lookup_widget(GTK_WIDGET (button), buff);
293
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
295
/* delay between packets */
297
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
301
cc = strtol(ptr, (char **)NULL, 10);
302
if ( (cc < 0) || (cc > 999999999) ) {
305
snprintf(buff, 100, "entry%d", 130+j);
306
w3 = lookup_widget(GTK_WIDGET (button), buff);
307
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
311
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
315
cc = strtol(ptr, (char **)NULL, 10);
316
if ( (cc < 0) || (cc > 999999999) ) {
319
snprintf(buff, 100, "entry%d", 140+j);
320
w3 = lookup_widget(GTK_WIDGET (button), buff);
321
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
323
/* enable or disable */
325
snprintf(buff, 100, "checkbutton%d", 24+j);
326
w2 = lookup_widget(GTK_WIDGET(button), buff);
328
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 0);
329
else if (*ptr == '0')
330
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
341
/* opens the pcap file.
342
* if we call this function from the builder window only one - first, packet will be read
343
* from the Genp window, packets will be loaded untill EOF is reached */
344
int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets) {
347
struct pcaprec_hdr ph;
348
struct clist_hdr clh;
350
guint32 secu = 0, secb = 0;
351
guint32 usecu = 0, usecb = 0;
357
/* first we read the pcap file header */
358
freads = fread(pkt_temp, sizeof(fh), 1, file_p);
363
memcpy(&fh, pkt_temp, 24);
365
/* if magic number in NOK, exit */
366
if (fh.magic != PCAP_MAGIC)
369
/* hm, I forgot a little bit, but I assume 1 means builder here */
370
if (whocalled == 1) {
372
/* next the pcap packet header */
373
freads = fread(pkt_temp, sizeof(ph), 1, file_p);
379
/* copy the 16 bytes into ph structure */
380
memcpy(&ph, pkt_temp, 16);
382
/* and the packet itself, but only up to the capture length */
383
freads = fread(pkt_temp+sizeof(ph), ph.incl_len, 1, file_p);
389
/* convert the packet information from int to hex */
390
for(ji=0; ji<(sizeof(ph)+ph.incl_len); ji++)
391
c8(&field[2*ji], *(pkt_temp+ji));
392
field[2*ji+2] = '\0';
394
load_packet_disector(button, field, 1, &clh, ph.incl_len);
401
clis = lookup_widget(GTK_WIDGET (button), "clist2");
402
gtk_clist_clear(GTK_CLIST(clis));
404
for (j=0; j<howmanypackets; j++) {
406
/* next the pcap packet header */
407
fread(pkt_temp, sizeof(ph), 1, file_p);
413
/* copy the 16 bytes into ph structure */
414
memcpy(&ph, pkt_temp, 16);
416
/* and the packet itself, but only up to the capture length */
417
freads = fread(pkt_temp+sizeof(ph), ph.incl_len, 1, file_p);
423
/* convert the packet information from int to hex */
424
for(ji=0; ji<(sizeof(ph)+ph.incl_len); ji++)
425
c8(&field[2*ji], *(pkt_temp+ji));
426
field[2*ji+2] = '\0';
428
/* we have to dissect the packet to get information for the list */
429
load_packet_disector(button, field, 2, &clh, ph.incl_len);
430
//printf("tukaj3 %s\n", field);
432
/* calculate the time information */
440
timediff = ((double)((double)ph.ts_sec - (double)secu)*1000000 +
441
(double)((double)ph.ts_usec - (double)usecu)) / 1000000;
442
timebeg = ((double)((double)ph.ts_sec - (double)secb)*1000000 +
443
(double)((double)ph.ts_usec - (double)usecb)) / 1000000;
446
//printf("tukaj2 %s\n", field);
451
/* insert a new row into clist */
452
load_gen_p_data(button, clis, field, &ph, j+1, &clh, timediff, timebeg);
454
if (j == howmanypackets)
455
error("Only first 1000 packets loaded!\nTo change this modify #define on top of callbacks.c");
463
/* this one loads the parameters from file into notebook2 (Genp page) */
464
int load_gen_p_data(GtkButton *button, GtkWidget *clis, char *fieldek, struct pcaprec_hdr *ph2,
465
int pkt_nr, struct clist_hdr *clptr, double timediff, double timebeg) {
469
gchar field_p[1][3100];
471
datap[0]=&fieldp[0][0];
472
datap[1]=&fieldp[1][0];
473
datap[2]=&fieldp[2][0];
474
datap[3]=&fieldp[3][0];
475
datap[4]=&fieldp[4][0];
476
datap[5]=&fieldp[5][0];
477
datap[6]=&fieldp[6][0];
478
datap[7]=&field_p[0][0];
480
//printf("TUKAJ1:%s\n", fieldek);
481
g_snprintf(fieldp[0], 20, "%d", pkt_nr);
482
g_snprintf(fieldp[1], 20, "%f", timebeg);
483
g_snprintf(fieldp[2], 20, "%f", timediff);
485
if ( (*ph2).incl_len == (*ph2).orig_len )
486
g_snprintf(fieldp[3], 20, "%d", (*ph2).incl_len);
488
g_snprintf(fieldp[3], 20, "%d !", (*ph2).incl_len);
490
g_snprintf(fieldp[4], 40, "%s", clptr->src);
491
g_snprintf(fieldp[5], 40, "%s", clptr->dst);
495
g_snprintf(fieldp[6], 20, "Ethernet II");
499
g_snprintf(fieldp[6], 20, "Ethernet 802.3");
503
g_snprintf(fieldp[6], 20, "ARP");
507
g_snprintf(fieldp[6], 20, "IPv4");
511
g_snprintf(fieldp[6], 20, "IPv6");
515
g_snprintf(fieldp[6], 20, "TCP");
519
g_snprintf(fieldp[6], 20, "UDP");
523
g_snprintf(fieldp[6], 20, "IGMP");
527
g_snprintf(fieldp[6], 20, "ICMP");
532
g_snprintf(field_p[0], 2*(32+(*ph2).incl_len), "%s", fieldek);
534
gtk_clist_append(GTK_CLIST(clis), datap);
540
/* this routine was changed. it loads the packet into notebook2 (Builder page) or it checks the file containing the packets
541
* for loading into Genp window
542
* if who called = 1 - we load the contents into builder field
543
* if who called = 2 - we load the contenst into Genp window but we need the information for filling in the clist
545
int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct clist_hdr *clptr, int dolpaketa) {
552
//printf("\n:\n%s\n", fieldek);
553
//convert8field(ptrt, ptrf); insint(button, "entry179", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
554
//convert8field(ptrt, ptrf+8); insint(button, "entry180", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
555
//convert8field(ptrt, ptrf+16); insint(button, "entry181", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
556
//convert8field(ptrt, ptrf+24); insint(button, "entry182", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
560
/* what is the shortest length we still allow?
561
* we don't care if the packet is shorter than actually allowed to go on ethernet
562
* maybe the user just wanted to save packet even if it is to short, so why not load it?
563
* what we do demand is, that every layer must be completed
564
* ok, here at least 14 bytes: 6 dest mac, 6 source mac and 2 for type or length*/
566
error("Can't load packet: Ethernet header is not long enough!");
570
/* first there is destination mac */
571
w1 = lookup_widget(GTK_WIDGET(button), "L_dst_mac");
572
for (i=1; i<=18; i++, ptrt++) {
582
gtk_entry_set_text(GTK_ENTRY(w1), temp);
584
memcpy(clptr->dst, temp, 20);
588
w2 = lookup_widget(GTK_WIDGET(button), "L_src_mac");
589
for (i=1; i<=18; i++, ptrt++) {
599
gtk_entry_set_text(GTK_ENTRY(w2), temp);
601
memcpy(clptr->src, temp, 20);
603
/* next there is type or length field or 802.1q or QinQ! */
604
i = char2x(ptrf)*256 + char2x(ptrf+2);
606
remain = remain - 14;
608
/* in case of a vlan tag 0x8100 == 33024) */
609
w1 = lookup_widget(GTK_WIDGET(button), "bt_8021q");
610
w2 = lookup_widget(GTK_WIDGET(button), "frame6");
612
if ((i == 33024) || (i==34984) || (i==37120) || (i==37376)) {
613
w3 = lookup_widget(GTK_WIDGET(button), "L_optmenu2_bt");
614
w4 = lookup_widget(GTK_WIDGET(button), "checkbutton39");
615
w5 = lookup_widget(GTK_WIDGET(button), "checkbutton40");
616
w6 = lookup_widget(GTK_WIDGET(button), "L_vlan_id");
617
w7 = lookup_widget(GTK_WIDGET(button), "entry165");
618
w8 = lookup_widget(GTK_WIDGET(button), "optionmenu21");
620
//if we have 8100 after the next 4 bytes we do QinQ
621
if ( ((char2x(ptrf+8)*256 + char2x(ptrf+10))==33024) && remain>=8)
625
if (whocalled == 1) {
626
gtk_widget_set_sensitive (w7, TRUE);
627
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w5), TRUE);
629
gtk_option_menu_set_history (GTK_OPTION_MENU (w8), 0);
631
gtk_option_menu_set_history (GTK_OPTION_MENU (w8), 3);
633
gtk_option_menu_set_history (GTK_OPTION_MENU (w8), 1);
635
gtk_option_menu_set_history (GTK_OPTION_MENU (w8), 2);
637
inspar(button, "entry165", ptrf, 4);
642
i = char2x(ptrf)*256 + char2x(ptrf+2);
645
if (whocalled == 1) {
646
gtk_widget_set_sensitive (w7, FALSE);
647
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w5), FALSE);
653
error("Can't load packet: Ethernet VLAN field is not long enough!");
663
if (whocalled == 1) {
664
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
665
gtk_widget_set_sensitive (w2, TRUE);
667
gtk_option_menu_set_history (GTK_OPTION_MENU (w3), (i>>1));
670
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w4), FALSE);
672
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w4), TRUE);
674
inspar(button, "L_vlan_id", ptrf, 3);
679
i = char2x(ptrf)*256 + char2x(ptrf+2);
683
if (whocalled == 1) {
684
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
686
gtk_widget_set_sensitive (w2, FALSE);
690
/* c will tell us which ethernet type we have */
693
/* ok, from now one, we split the dissection in different routines, depending on what values */
694
/* now if length is <= 1500, we have 802.3 ethernet and this value means length of ethernet packet */
696
next_prot = ethernet_8023(button, whocalled);
697
/* Values between 1500 and 1536 are forbidden */
698
else if ( (i>1500) && (i<1536) ) {
699
error("Can't load packet: Wrong ethernet length/type field");
702
/* if i >= 1536 - ethernet ver II */
704
next_prot = ethernet_verII(button, whocalled);
707
/* ok, so we have dissected the ethernet layer and now move on two the next layer.
708
* if the ethernet dissector returns -1, this means an error and we quit
709
* otherwise, the return value can be 2048 == 0x0800 and this means the ipv4
710
* so we try to dissect ipv4 header. in case it is ok, we activate the ippkt_radibt
711
* and this one then calls the callback which fills in ethernet ver II type field
712
* and PID field in 802.3 LLC/SNAP field. It is the same for arp packets
713
* for other packets we will try to open the userdefined window */
715
/* we got an error? */
720
else if (next_prot == 2048) {
721
/* ok, ipv4 should follow, so we call the routine for parsing ipv4 header. */
722
next_prot = ipv4_header(button, whocalled, clptr);
726
/* if the return value from parsing ipv4 header was != 0, then the header parameters
727
* are ok and we can open ipv4 notebook page activate toggle button (button calls
728
* the callback then!!! */
729
w1 = lookup_widget(GTK_WIDGET(button), "ippkt_radibt");
730
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
732
/* here we do the further parsing: tcp, udp, icmp, ...*/
733
if (next_prot == 1) {
734
/* try to parse icmp header */
735
next_prot = icmp_header(button, whocalled);
736
/* not ok, return an error */
739
/* ok, lets activate the icmp notebook */
741
w1 = lookup_widget(GTK_WIDGET(button), "icmp_bt");
742
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
745
else if (next_prot == 2) {
746
/* try to parse igmp header */
747
next_prot = igmp_header(button, whocalled);
748
/* not ok, return an error */
751
/* ok, lets activate the igmp notebook */
753
w1 = lookup_widget(GTK_WIDGET(button), "igmp_bt");
754
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
757
else if (next_prot == 6) {
758
/* try to parse tcp header */
759
next_prot = tcp_header(button, whocalled);
760
/* not ok, return an error */
763
/* ok, lets activate the tcp notebook */
765
w1 = lookup_widget(GTK_WIDGET(button), "tcp_bt");
766
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
769
/* protocols on top of tcp would follow here */
772
else if (next_prot == 17) {
773
/* try to parse udp header */
774
next_prot = udp_header(button, whocalled);
775
/* not ok, return an error */
778
/* ok, lets activate the udp notebook */
780
w1 = lookup_widget(GTK_WIDGET(button), "udp_bt");
781
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
784
/* protocols on top of udp would follow here */
786
/* protocol we do not support yet; user defined window */
788
next_prot = usedef_insert(button, "text2", whocalled);
789
w1 = lookup_widget(GTK_WIDGET(button), "ip_user_data_bt");
790
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
794
else if (next_prot == 2054) {
795
/* ok, arp header follows */
796
next_prot = arp_header(button, whocalled);
800
w1 = lookup_widget(GTK_WIDGET(button), "arppkt_radiobt");
801
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
804
/* when ipv6 will be added, activate ipv6 button instead of userdef button */
805
else if (next_prot == 34525) {
807
/* ok, ipv6 should follow, so we call the routine for parsing ipv6 header. */
808
next_prot = ipv6_header(button, whocalled, clptr);
812
w1 = lookup_widget(GTK_WIDGET(button), "IPv6_rdbt");
813
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
815
/* here we do the further parsing: tcp, udp, icmp, ...*/
816
if (next_prot == 1) {
817
/* try to parse icmpv6 header */
818
next_prot = icmpv6_header(button, whocalled);
819
/* not ok, return an error */
822
/* ok, lets activate the icmpv6 notebook */
824
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton69");
825
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
828
else if (next_prot == 6) {
829
/* try to parse tcp header */
830
next_prot = tcp_header(button, whocalled);
831
/* not ok, return an error */
834
/* ok, lets activate the tcp notebook */
836
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton68");
837
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
840
else if (next_prot == 17) {
841
/* try to parse udp header */
842
next_prot = udp_header(button, whocalled);
843
/* not ok, return an error */
846
/* ok, lets activate the udp notebook */
848
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton67");
849
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
852
/* protocol we do not support yet; user defined window */
854
next_prot = usedef_insert(button, "text2", whocalled);
855
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton71");
856
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
860
/* anything else - user defined */
862
/* setting "usedef2_radibt" toggle button to true will call the callback which will clear
863
eth II type field and 802.3 pid field, so we have to fill this later */
864
w1 = lookup_widget(GTK_WIDGET(button), "usedef2_radibt");
865
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
867
/* we still have c to distinguish between ver II and 802.3 */
871
inspar(button, "L_ethtype", ptrf, 4);
873
/* 802.3 and with LLC SNAP */
874
else if (next_prot != -2) {
876
inspar(button, "L_pid", ptrf, 4);
879
next_prot = usedef_insert(button, "text1", whocalled);
886
int arp_header(GtkButton *button, int whocalled) {
896
/* arp header length == 28; but packet can be longer, f.e. to satisfy the min packet length */
898
error("Can't load packet: Packet length shorter than ARP header length!");
902
remain = remain - 28;
905
inspar(button, "A_hwtype", ptrf, 4);
908
inspar(button, "A_prottype", ptrf, 4);
911
inspar(button, "A_hwsize", ptrf, 2);
914
inspar(button, "A_protsize", ptrf, 2);
917
if ( (*ptrf == '0') && (*(ptrf+1) == '0') && (*(ptrf+2) == '0') && (*(ptrf+3) == '1') ) {
918
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton10");
919
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
922
else if ( (*ptrf == '0') && (*(ptrf+1) == '0') && (*(ptrf+2) == '0') && (*(ptrf+3) == '2') ) {
923
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton11");
924
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
928
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton17");
929
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
930
inspar(button, "entry81", ptrf, 4);
935
w1 = lookup_widget(GTK_WIDGET(button), "A_sendermac");
936
for (i=1; i<=18; i++, ptrt++) {
944
gtk_entry_set_text(GTK_ENTRY(w1), temp);
949
w1 = lookup_widget(GTK_WIDGET(button), "A_senderip");
950
for (i=1; i<=12; i++, ptrt++) {
954
snprintf(tmp, 4, "%d", x);
956
snprintf(tmp, 5, "%d.", x);
960
tmp[(i-1)%3] = *ptrf++;
963
gtk_entry_set_text(GTK_ENTRY(w1), temp);
967
w1 = lookup_widget(GTK_WIDGET(button), "A_targetmac");
968
for (i=1; i<=18; i++, ptrt++) {
976
gtk_entry_set_text(GTK_ENTRY(w1), temp);
981
w1 = lookup_widget(GTK_WIDGET(button), "A_targetip");
982
for (i=1; i<=12; i++, ptrt++) {
986
snprintf(tmp, 4, "%d", x);
988
snprintf(tmp, 5, "%d.", x);
992
tmp[(i-1)%3] = *ptrf++;
995
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1002
int igmp_header(GtkButton *button, int whocalled) {
1012
/* well normal igmp type should have at least 8 bytes, so this is min for us */
1014
error("Can't load packet: Packet length shorter than IGMP header length!");
1022
/* insert version */
1023
inspar(button, "entry166", ptrf, 2);
1025
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu20");
1026
w2 = lookup_widget(GTK_WIDGET(button), "notebook8");
1029
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 1);
1030
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 1);
1033
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 0);
1034
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1038
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 2);
1039
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1042
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 3);
1043
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1046
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 4);
1047
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 2);
1050
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 5);
1051
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1054
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 6);
1055
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1058
inspar(button, "entry167", ptrf, 2);
1060
/* set checksum button on auto */
1061
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton41");
1062
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1066
if ( (x == 17) && (remain>4) ) { /* IGMP V3 query */
1067
/*insert group ip */
1069
memset(temp, 0, 20);
1070
w1 = lookup_widget(GTK_WIDGET(button), "entry169");
1071
for (i=1; i<=12; i++, ptrt++) {
1075
snprintf(tmp, 4, "%d", x);
1077
snprintf(tmp, 5, "%d.", x);
1081
tmp[(i-1)%3] = *ptrf++;
1084
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1086
inspar(button, "entry171", ptrf, 4);
1087
x1 = (int)retint2(ptrf, 4);
1088
inspar(button, "entry172", ptrf, 4);
1089
/*#inspar(button, "entry173", ptrf, x1);*/
1090
inspar(button, "entry173", ptrf, remain);
1093
else if (x==22) { /*IGMP V3 report */
1094
inspar(button, "entry176", ptrf, 4);
1095
x1 = (int)retint2(ptrf, 4);
1096
inspar(button, "entry177", ptrf, 4);
1097
inspar(button, "entry178", ptrf, x1);
1100
else { /*all the other versions */
1101
/*insert group ip */
1103
memset(temp, 0, 20);
1104
w1 = lookup_widget(GTK_WIDGET(button), "entry175");
1105
for (i=1; i<=12; i++, ptrt++) {
1109
snprintf(tmp, 4, "%d", x);
1111
snprintf(tmp, 5, "%d.", x);
1115
tmp[(i-1)%3] = *ptrf++;
1118
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1126
int icmp_header(GtkButton *button, int whocalled) {
1135
/* well normal icmp type should have at least 8 bytes, so this is min for us */
1137
error("Can't load packet: Packet length shorter than ICMP header length!");
1145
/* insert version */
1146
inspar(button, "entry57", ptrf, 2);
1148
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu4");
1150
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 0);
1152
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 1);
1154
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 2);
1156
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 3);
1159
if (x == 0) { /* echo reply */
1160
/* insert code, checksum, identifier and seq number and data if there is some */
1161
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1162
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 0);
1163
inspar(button, "entry62", ptrf, 2);
1164
//inspar(button, "entry63", ptrf, 4);
1166
inspar(button, "entry64", ptrf, 4);
1167
inspar(button, "entry65", ptrf, 4);
1168
/* set checksum button on auto */
1169
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton16");
1170
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1172
inspar(button, "entry66", ptrf, remain * 2);
1174
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton17");
1175
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1178
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton17");
1179
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1183
else if (x == 3) { /* destination unreacheable */
1184
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1185
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 2);
1189
inspar(button, "entry58", ptrf, 2);
1191
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu5");
1192
if ( (x >= 0) && (x <= 15) )
1193
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), x);
1195
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 16);
1197
/* insert code, checksum, identifier and seq number and data if there is some */
1198
//inspar(button, "entry59", ptrf, 4);
1200
inspar(button, "entry60", ptrf, 8);
1201
/* set checksum button on auto */
1202
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton15");
1203
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1205
inspar(button, "entry61", ptrf, remain * 2);
1207
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton24");
1208
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1211
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton24");
1212
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1215
else if (x == 8) { /* echo request */
1216
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1217
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 5);
1218
/* insert code, checksum, identifier and seq number and data if there is some */
1219
inspar(button, "entry74", ptrf, 2);
1220
//inspar(button, "entry77", ptrf, 4);
1222
inspar(button, "entry75", ptrf, 4);
1223
inspar(button, "entry78", ptrf, 4);
1224
/* set checksum button on auto */
1225
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton20");
1226
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1228
inspar(button, "entry76", ptrf, remain * 2);
1230
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton19");
1231
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1234
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton19");
1235
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1239
else { /* all the rest */
1240
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1241
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 1);
1242
/* insert code, checksum and data if there is some */
1243
inspar(button, "entry157", ptrf, 2);
1244
//inspar(button, "entry158", ptrf, 4);
1246
/* set checksum button on auto */
1247
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton38");
1248
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1250
inspar(button, "entry159", ptrf, (remain + 4) * 2);
1258
int usedef_insert(GtkButton *button, char *entry, int whocalled) {
1266
/* get access to buffer of the text field */
1267
w2 = lookup_widget(GTK_WIDGET(button), entry);
1268
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1270
/* copy data to tmp field */
1271
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1272
tmp[i] = *ptrf++; i++;
1273
tmp[i] = *ptrf++; i++;
1274
/* we allow only 16 bytes in each row - looks nicer */
1275
if ((j % 16) == 0 && (j > 1)) {
1284
/* insert the text in the text field */
1285
gtk_text_buffer_set_text(buffer,tmp,-1);
1293
int tcp_header(GtkButton *button, int whocalled) {
1296
char tmp[4600], tmp2[3], ch;
1304
/* for standard header this is minimum length */
1306
error("Can't load packet: Packet length shorter than TCP header length!");
1310
/* ok, packet is long enough to fill in the standard header, but what is the header length?
1311
* we insert this later but need now to see that the packet is long enough */
1312
x = retint(ptrf+24);
1313
if ( (x * 4) > remain ) {
1314
error("Can't load packet:\nPacket length shorter than TCP header length!");
1318
error("Can't load packet:\nTCP header length shorter than 20 bytes!");
1323
insint(button, "entry46", ptrf, 4);
1325
/* destination port */
1326
insint(button, "entry47", ptrf, 4);
1328
/* sequence number */
1329
insint(button, "entry48", ptrf, 8);
1331
/* acknowledgement number */
1332
insint(button, "entry49", ptrf, 8);
1334
/* now we insert value for length */
1335
snprintf(tmp2, 3, "%d", x*4);
1336
w1 = lookup_widget(GTK_WIDGET(button), "entry50");
1337
gtk_entry_set_text(GTK_ENTRY(w1), tmp2);
1339
/* increase by one for length and for another one for 4 bits that are reserved */
1342
/* flags; next byte */
1343
ch = char2x(ptrf) % 0x0100;
1345
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton22");
1346
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x80) > 0 ? TRUE : FALSE);
1348
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton23");
1349
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x40) > 0 ? TRUE : FALSE);
1351
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton7");
1352
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x20) > 0 ? TRUE : FALSE);
1354
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton8");
1355
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x10) > 0 ? TRUE : FALSE);
1357
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton9");
1358
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x08) > 0 ? TRUE : FALSE);
1360
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton10");
1361
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x04) > 0 ? TRUE : FALSE);
1363
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton11");
1364
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x02) > 0 ? TRUE : FALSE);
1366
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton12");
1367
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x01) > 0 ? TRUE : FALSE);
1372
insint(button, "entry51", ptrf, 4);
1375
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton13");
1376
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1377
//inspar(button, "entry52", ptrf, 4);
1381
insint(button, "entry53", ptrf, 4);
1384
/* - 20 for standard header */
1385
inspar(button, "entry54", ptrf, ( (x*4) - 20) * 2);
1387
remain = remain - x*4;
1389
/* get access to buffer of the text field */
1390
w2 = lookup_widget(GTK_WIDGET(button), "text4");
1391
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1394
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton14");
1395
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1397
/* copy data to tmp field */
1398
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1399
tmp[i] = *ptrf++; i++;
1400
tmp[i] = *ptrf++; i++;
1401
/* we allow only 16 bytes in each row - looks nicer */
1402
if ((j % 16) == 0 && (j > 1)) {
1411
/* insert the text in the text field */
1412
gtk_text_buffer_set_text(buffer,tmp,-1);
1415
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton14");
1416
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1419
/* since tcp does not have any protocol field we could return destination port value which
1420
* usually describes next layer protocol; currently we return 1 */
1425
int udp_header(GtkButton *button, int whocalled) {
1435
/* for standard header this is minimum length */
1437
error("Can't load packet: Packet length shorter than UDP header length!");
1441
remain = remain - 8;
1444
insint(button, "entry56", ptrf, 4);
1446
/* destination port */
1447
insint(button, "entry41", ptrf, 4);
1450
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton3");
1451
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1452
//insint(button, "entry42", ptrf, 4);
1456
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton4");
1457
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1458
//inspar(button, "entry43", "", 4);
1461
/* get access to buffer of the text field */
1462
w2 = lookup_widget(GTK_WIDGET(button), "text3");
1463
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1466
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton5");
1467
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1469
/* copy data to tmp field */
1470
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1471
tmp[i] = *ptrf++; i++;
1472
tmp[i] = *ptrf++; i++;
1473
/* we allow only 16 bytes in each row - looks nicer */
1474
if ((j % 16) == 0 && (j > 1)) {
1483
/* insert the text in the text field */
1484
gtk_text_buffer_set_text(buffer,tmp,-1);
1487
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton5");
1488
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1491
/* since udp does not have any protocol field we could return destination port value which
1492
* usually describes next layer protocol; currently we return 1 */
1497
int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) {
1500
int x, header_l, prot;
1506
/* for standard header this is minimum length */
1508
error("Can't load packet: IPv4 header field is not long enough!");
1512
/* first comes version but we will first check the length and then insert version */
1515
/* check the header length */
1516
/* we don't need to check the return value here, it is already done when reading from file */
1517
header_l = retint(ptrf);
1518
/* header length is the number of 32-bit words in the header, including any options.
1519
* Since this is a 4-bit field, it limits the header to 60 bytes. So the remaining length
1520
* should be at least that long or we exit here */
1521
if ( (header_l * 4) < 20 ) {
1522
error("Can't load packet:\nIPv4 header length shorter than 20 bytes!");
1525
if ( (header_l * 4) > remain ) {
1526
error("Can't load packet:\nPacket length shorter than IPv4 header length!");
1532
/* insert version */
1533
inspar(button, "entry26", ptrf, 1);
1535
/* insert header length */
1536
inspar(button, "entry27", ptrf, 1);
1539
inspar(button, "entry28", ptrf, 2);
1541
/* insert total length */
1542
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton21");
1543
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1544
//insint(button, "entry29", ptrf, 4);
1552
/* insert identification */
1553
inspar(button, "entry30", ptrf, 4);
1559
*tmp = 0x30; /* 0x30 == 0 */
1562
x = x >> 1; /* use only first 3 bits */
1565
w1 = lookup_widget(GTK_WIDGET(button), "entry31");
1566
snprintf(tmp, 4, "%d", x);
1567
gtk_entry_set_text(GTK_ENTRY(w1), tmp);
1570
/* insert fragment offset */
1571
*tmp = 0x30; /* 0x30 == 0 */
1573
x = (char2x(tmp)%2); /* need only last bit */
1578
strncpy(tmp+1, ptrf+1, 3);
1581
insint(button, "entry32", tmp, 4);
1584
insint(button, "entry44", ptrf, 2);
1589
prot = char2x(ptrf);
1592
/* insert protocol */
1593
insint(button, "entry34", ptrf, 2);
1595
/* insert header checksum */
1596
w1 = lookup_widget(GTK_WIDGET(button), "ip_header_cks_cbt");
1597
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1598
//inspar(button, "entry35", ptrf, 4);
1605
/*insert source ip */
1607
memset(temp, 0, 20);
1609
w1 = lookup_widget(GTK_WIDGET(button), "entry38");
1610
for (i=1; i<=12; i++, ptrt++) {
1614
snprintf(tmp, 4, "%d", x);
1616
snprintf(tmp, 5, "%d.", x);
1620
tmp[(i-1)%3] = *ptrf++;
1625
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1627
memcpy(clptr->src, temp, 20);
1629
/*insert destination ip */
1631
memset(temp, 0, 20);
1633
w1 = lookup_widget(GTK_WIDGET(button), "entry37");
1634
for (i=1; i<=12; i++, ptrt++) {
1638
snprintf(tmp, 4, "%d", x);
1640
snprintf(tmp, 5, "%d.", x);
1644
tmp[(i-1)%3] = *ptrf++;
1648
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1650
memcpy(clptr->dst, temp, 20);
1652
/* insert ipv4 options
1653
* header_l * 4 == total header length, - 20 for standard header == options length in bytes*/
1655
inspar(button, "entry39", ptrf, ( (header_l*4) - 20) * 2);
1657
remain = remain - (header_l * 4);
1663
int ethernet_8023(GtkButton *button, int whocalled) {
1665
int dsap, lsap, ctrl;
1669
protokol = ETH_802_3;
1674
error("Can't load packet: Ethernet 802.3 LLC field is not long enough!");
1677
remain = remain - 3;
1679
w1 = lookup_widget(GTK_WIDGET(button), "bt_8023");
1680
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1682
//w2 = lookup_widget(GTK_WIDGET(button), "frame7");
1683
//gtk_widget_set_sensitive (w2, TRUE);
1684
//gtk_notebook_set_page(GTK_NOTEBOOK(w3), 1);
1686
w1 = lookup_widget(GTK_WIDGET(button), "entry5");
1687
//inspar(button, "entry5", ptrf, 4);
1689
gtk_widget_set_sensitive (w1, FALSE);
1691
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton2");
1692
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1694
/*now the LLC / LLC-SNAP part */
1695
/* we decode only RFC 1042 format, that means the following value:
1696
dsap == ssap == 0xAA
1700
dsap = char2x(ptrf);
1701
inspar(button, "L_dsap", ptrf, 2);
1702
lsap = char2x(ptrf);
1703
inspar(button, "L_ssap", ptrf, 2);
1704
ctrl = char2x(ptrf);
1705
inspar(button, "L_ctrl", ptrf, 2);
1707
/* in case dsap != ssap != 0xAA or ctrl != 0x03 or remain length < 5 bytes, we have only
1708
* LLC without SNAP and we return value for user defined next layer */
1709
if ( (dsap != 170 ) || (lsap != 170) || (ctrl != 3) || (remain < 5) ) {
1710
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llc_tbt");
1711
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1712
w1 = lookup_widget(GTK_WIDGET(button), "L_oui");
1713
w2 = lookup_widget(GTK_WIDGET(button), "L_pid");
1714
gtk_widget_set_sensitive (w1, FALSE);
1715
gtk_widget_set_sensitive (w2, FALSE);
1716
/* this means we insert all the data as user defined field */
1719
/* in this case everything is ok but oui in not 0 */
1720
/* <--------------this is oui---------------------> */
1721
else if ( (char2x(ptrf) + char2x(ptrf+2) + char2x(ptrf+4) != 0 ) ) {
1722
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llc_tbt");
1723
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1724
w1 = lookup_widget(GTK_WIDGET(button), "L_oui");
1725
w2 = lookup_widget(GTK_WIDGET(button), "L_pid");
1726
gtk_widget_set_sensitive (w1, FALSE);
1727
gtk_widget_set_sensitive (w2, FALSE);
1728
/* this means we insert all the data as user defined field */
1732
/* substract 3 for oui and 2 for pid */
1733
remain = remain - 5;
1735
/* ok, so we have dsap and ssap == 0xAA, Ctlr == 0x03, OUI == 0x0 and length is long enough */
1736
/* set llc-snap button */
1737
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llcsnap_tbt");
1738
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1740
/* insert 0x00 into oui field */
1741
inspar(button, "L_oui", ptrf, 6);
1742
pid = char2x(ptrf)*256 + char2x(ptrf+2);
1750
int ethernet_verII(GtkButton *button, int whocalled) {
1758
w1 = lookup_widget(GTK_WIDGET(button), "bt_ver2");
1759
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1762
pid = char2x(ptrf)*256 + char2x(ptrf+2);
1770
/* this one inserts (length) characters from (char *from) into entry named (char *entry). It adds \0
1771
at the end and in moves pointer ptrf (this one points the the next "data" to be inserted) by length */
1772
void inspar(GtkButton *button, char *entry, char *from, int length) {
1778
ptr = malloc(length * sizeof(char) + 1);
1780
widg = lookup_widget(GTK_WIDGET(button), entry);
1782
strncpy(ptr, from, length);
1784
gtk_entry_set_text(GTK_ENTRY(widg), ptr);
1785
ptrf = ptrf + length;
1791
/* this one reads (length) characters strating at (char *from), converts them to int and inserts them
1792
into field (*entry) as integer. f.e: 0x56 == (int)86 => writes into (*entry) 86
1793
note that max size for length is 10!!! when calling this routine */
1794
void insint(GtkButton *button, char *entry, char *from, int length) {
1798
unsigned long value = 0;
1800
unsigned char x = 0;
1802
widg = lookup_widget(GTK_WIDGET(button), entry);
1804
for (i = 0; i < length; i++) {
1805
if ( (*from >= '0') && (*from <= '9'))
1807
else if ((*from >= 'A') && (*from <= 'F'))
1809
else if ((*from >= 'a') && (*from <= 'f'))
1812
value = value + ((int)x) * ((unsigned long)1 << (4*(length-1-i)) );
1816
ptrf = ptrf + length;
1818
snprintf(tmp, 11, "%lu", value);
1819
gtk_entry_set_text(GTK_ENTRY(widg), tmp);
1823
/* from a character return int */
1824
signed int retint(char *ch) {
1828
if ( (*ch >= '0') && (*ch <= '9'))
1830
else if ((*ch >= 'A') && (*ch <= 'F'))
1832
else if ((*ch >= 'a') && (*ch <= 'f'))
1842
/* this one reads (length) characters strating at (*from), and returns integer (max 10 char length) */
1843
unsigned long retint2(char *from, int length) {
1845
unsigned long value = 0;
1847
unsigned char x = 0;
1849
for (i = 0; i < length; i++) {
1850
if ( (*from >= '0') && (*from <= '9'))
1852
else if ((*from >= 'A') && (*from <= 'F'))
1854
else if ((*from >= 'a') && (*from <= 'f'))
1857
value = value + ((int)x) * ((unsigned long)1 << (4*(length-1-i)) );
1865
/* i have newer really understood the endians... help appreciated...
1866
* this routines just converts the contents of a char field of size 8 chars
1867
* it works also, if destination and source are the same field*/
1869
void convert8field(char *to, char *from) {
1873
/* we copy first the source contents */
1874
memcpy(f1, from, 8);
1876
memcpy(to+0, f1+6,1);
1877
memcpy(to+1, f1+7,1);
1878
memcpy(to+2, f1+4,1);
1879
memcpy(to+3, f1+5,1);
1880
memcpy(to+4, f1+2,1);
1881
memcpy(to+5, f1+3,1);
1882
memcpy(to+6, f1+0,1);
1883
memcpy(to+7, f1+1,1);
1886
int ipv6_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) {
1889
int x, prot, header_l;
1895
/* for standard header this is minimum length */
1897
error("Can't load packet: IPv6 header field is not long enough!");
1902
/* insert version */
1903
inspar(button, "entry195", ptrf, 1);
1905
/* insert traffic class */
1906
inspar(button, "entry196", ptrf, 2);
1909
inspar(button, "entry197", ptrf, 5);
1911
/* insert total length */
1912
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton43");
1913
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1914
//insint(button, "entry29", ptrf, 4);
1922
prot = char2x(ptrf);
1925
/* insert next header */
1926
inspar(button, "entry199", ptrf, 2);
1932
/* insert hop limit */
1933
insint(button, "entry200", ptrf, 2);
1938
/*insert source ip */
1940
memset(temp6, 0, 40);
1943
w1 = lookup_widget(GTK_WIDGET(button), "entry201");
1945
for (i=1; i<8; i++) {
1946
strncpy(ptrt, ptrf, 4);
1952
strncpy(ptrt, ptrf, 4);
1956
gtk_entry_set_text(GTK_ENTRY(w1), temp6);
1958
memcpy(clptr->src, temp6, 40);
1960
/*insert destination ip */
1962
memset(temp6, 0, 40);
1964
w1 = lookup_widget(GTK_WIDGET(button), "entry202");
1966
for (i=1; i<8; i++) {
1967
strncpy(ptrt, ptrf, 4);
1973
strncpy(ptrt, ptrf, 4);
1977
gtk_entry_set_text(GTK_ENTRY(w1), temp6);
1979
memcpy(clptr->dst, temp6, 40);
1982
while ( (prot==0) || (prot==43) || (prot==44) || (prot==51) || (prot==50) || (prot==60) ) {
1983
prot = char2x(ptrf);
1984
header_l = retint2(ptrf+2, 2);
1985
inspar(button, "entry203", ptrf, header_l);
1992
int icmpv6_header(GtkButton *button, int whocalled) {