2
* packETH - ethernet packet generator
3
* By Miha Jemec <m.jemec@iskratel.si>
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;
43
protocol_type protokol;
45
/* this one loads the parameters from file into notebook2 (Gen-b page) */
46
int load_gen_b_data(GtkButton *button, FILE *file_p) {
53
w1 = lookup_widget(GTK_WIDGET (button), "radiobutton35");
54
w2 = lookup_widget(GTK_WIDGET (button), "radiobutton34");
55
w3 = lookup_widget(GTK_WIDGET (button), "optionmenu9");
56
w4 = lookup_widget(GTK_WIDGET (button), "entry109");
57
w5 = lookup_widget(GTK_WIDGET (button), "entry110");
58
w6 = lookup_widget(GTK_WIDGET(button), "checkbutton35");
59
w7 = lookup_widget(GTK_WIDGET(button), "checkbutton37");
60
/* we read the file ohh python, where are you... */
63
/* rules for config files:
64
* - comments start with #
65
* - there can be spaces and newlines
66
* - only digits and - are acceptable characters
69
/* we have to limit the lines we read paramters from */
70
while ( (c = fgetc( file_p )) != EOF ) {
71
/* all the comment lines, starting with # , no limit for comment lines*/
72
if ( (j==0) && (c == 35)) {
73
/* ok, read till the end of line */
74
while ( getc(file_p) != 10);
78
/* let's limit the size */
79
if ( (j > 9) || (k > 2) )
82
/* ok, it is not a comment line so the info: only digits and minus sign are acceptable */
83
if ( (isdigit(c) != 0) || (c == 45) ) {
88
/* no digit is it a newline? */
92
if (strlen(buff) == 0)
94
buff4[k] = strtol(buff, (char **)NULL, 10);
96
strncpy(&buffc[k][j], buff, 9);
99
/* not, ok this is an error */
106
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
107
else if (buff4[0] == 0)
108
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w1), 1);
113
/* adjusting parameters...
114
if ( (buff4[1] >= 0) && (buff4[1] <= 4) )
115
gtk_option_menu_set_history (GTK_OPTION_MENU (w3), buff4[1]);
120
if (buff4[1] == - 3) {
121
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 1);
122
gtk_entry_set_text(GTK_ENTRY(w4), "");
123
gtk_widget_set_sensitive (w4, FALSE);
125
else if ( (buff4[1] > 0) && (buff4[1] <= 9999999) ) {
126
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 0);
127
gtk_widget_set_sensitive (w4, TRUE);
128
gtk_entry_set_text(GTK_ENTRY(w4), &buffc[1][0]);
135
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w7), 1);
136
gtk_entry_set_text(GTK_ENTRY(w5), "");
137
gtk_widget_set_sensitive (w5, FALSE);
139
else if ( (buff4[2] >= 1) && (buff4[2] <= 999999999) ) {
140
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w7), 0);
141
gtk_widget_set_sensitive (w5, TRUE);
142
gtk_entry_set_text(GTK_ENTRY(w5), &buffc[2][0]);
153
/* this one loads the parameters from file into notebook2 (Gen-s page) */
154
int load_gen_s_data(GtkButton *button, FILE *file_p) {
160
char *ptr = NULL, *ptr2 = NULL;
166
/* rules for config files:
167
* - comments start with #
168
* - there can be spaces and newlines
169
* - only digits and - are acceptable characters
172
while ( (c = fgetc( file_p )) != EOF ) {
173
/* all the comment lines, starting with # */
174
if ( (j==0) && (c == 35)) {
175
while ( getc(file_p) != 10);
178
/* all blank lines */
179
if ( (j==0) && (c == 10))
181
/* read the whole lines */
182
if ((isascii(c) != 0) && (j<200) && (c!=10) && (k<11)) {
187
/* , or \n mean end of string */
197
w1 = lookup_widget(GTK_WIDGET (button), "radiobutton36");
198
w2 = lookup_widget(GTK_WIDGET (button), "radiobutton37");
199
w4 = lookup_widget(GTK_WIDGET (button), "entry151");
200
w5 = lookup_widget(GTK_WIDGET (button), "entry152");
201
w6 = lookup_widget(GTK_WIDGET(button), "checkbutton36");
203
/* first line should have three parameters */
204
/* first is absolute or relative delay, allowed values 0 and 1 */
205
if (strncmp(&buffc[0][0], "1", 1) == 0)
206
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w1), 1);
207
else if (strncmp(&buffc[0][0], "0", 1) == 0)
208
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
213
/* second is number of packets: -3 means infinite, or 1 till 9999999) */
214
if (strncmp(&buffc[0][2], "-3", 2) == 0) {
215
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 1);
216
gtk_entry_set_text(GTK_ENTRY(w4), "");
217
gtk_widget_set_sensitive (w4, FALSE);
221
if ( (ptr = strchr(&buffc[0][2], 44)) == NULL) {
225
buff4[0] = strtol(&buffc[0][2], (char **)NULL, 10);
227
if ( (buff4[0] >= 0) && (buff4[0] <= 9999999) ) {
228
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 0);
229
gtk_widget_set_sensitive (w4, TRUE);
230
gtk_entry_set_text(GTK_ENTRY(w4), &buffc[0][2]);
237
/* last parameter is delay between sequences */
238
buff4[0] = strtol(ptr+1, (char **)NULL, 10);
240
if ( (buff4[0] >= 0) && (buff4[0] <= 999999999) ) {
241
gtk_entry_set_text(GTK_ENTRY(w5), ptr+1);
247
/* we have to clean everything */
248
for (j = 0; j < 10; j++) {
249
snprintf(buff, 10, "entry%d", 111+j);
250
w2 = lookup_widget(GTK_WIDGET (button), buff);
251
gtk_entry_set_text(GTK_ENTRY(w2), "");
252
snprintf(buff, 100, "entry%d", 121+j);
253
w3 = lookup_widget(GTK_WIDGET (button), buff);
254
gtk_entry_set_text(GTK_ENTRY(w3), "");
255
snprintf(buff, 100, "entry%d", 131+j);
256
w3 = lookup_widget(GTK_WIDGET (button), buff);
257
gtk_entry_set_text(GTK_ENTRY(w3), "");
258
snprintf(buff, 100, "entry%d", 141+j);
259
w3 = lookup_widget(GTK_WIDGET (button), buff);
260
gtk_entry_set_text(GTK_ENTRY(w3), "");
261
snprintf(buff, 100, "checkbutton%d", 25+j);
262
w2 = lookup_widget(GTK_WIDGET(button), buff);
263
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 0);
266
/* and now all the rest */
267
for (j = 1; j < k; j++) {
268
/* first is packet name */
269
if ( (ptr2 = strchr(&buffc[j][0], 44)) == NULL)
272
if ( (strlen(&buffc[j][0]) > 0 ) && (strlen(&buffc[j][0]) < 70) ) {
273
snprintf(buff, 10, "entry%d", 110+j);
274
w2 = lookup_widget(GTK_WIDGET (button), buff);
275
gtk_entry_set_text(GTK_ENTRY(w2), &buffc[j][0]);
280
/* number of packets */
282
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
286
cc = strtol(ptr, (char **)NULL, 10);
287
if ( (cc < 0) || (cc > 9999999) ) {
290
snprintf(buff, 100, "entry%d", 120+j);
291
w3 = lookup_widget(GTK_WIDGET (button), buff);
292
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
294
/* delay between packets */
296
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
300
cc = strtol(ptr, (char **)NULL, 10);
301
if ( (cc < 0) || (cc > 999999999) ) {
304
snprintf(buff, 100, "entry%d", 130+j);
305
w3 = lookup_widget(GTK_WIDGET (button), buff);
306
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
310
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
314
cc = strtol(ptr, (char **)NULL, 10);
315
if ( (cc < 0) || (cc > 999999999) ) {
318
snprintf(buff, 100, "entry%d", 140+j);
319
w3 = lookup_widget(GTK_WIDGET (button), buff);
320
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
322
/* enable or disable */
324
snprintf(buff, 100, "checkbutton%d", 24+j);
325
w2 = lookup_widget(GTK_WIDGET(button), buff);
327
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 0);
328
else if (*ptr == '0')
329
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
340
/* opens the pcap file.
341
* if we call this function from the builder window only one - first, packet will be read
342
* from the Genp window, packets will be loaded untill EOF is reached */
343
int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets) {
346
struct pcaprec_hdr ph;
347
struct clist_hdr clh;
349
guint32 secu = 0, secb = 0;
350
guint32 usecu = 0, usecb = 0;
356
/* first we read the pcap file header */
357
freads = fread(pkt_temp, sizeof(fh), 1, file_p);
362
memcpy(&fh, pkt_temp, 24);
364
/* if magic number in NOK, exit */
365
if (fh.magic != PCAP_MAGIC)
368
/* hm, I forgot a little bit, but I assume 1 means builder here */
369
if (whocalled == 1) {
371
/* next the pcap packet header */
372
freads = fread(pkt_temp, sizeof(ph), 1, file_p);
378
/* copy the 16 bytes into ph structure */
379
memcpy(&ph, pkt_temp, 16);
381
/* and the packet itself, but only up to the capture length */
382
freads = fread(pkt_temp+sizeof(ph), ph.incl_len, 1, file_p);
388
/* convert the packet information from int to hex */
389
for(ji=0; ji<(sizeof(ph)+ph.incl_len); ji++)
390
c8(&field[2*ji], *(pkt_temp+ji));
391
field[2*ji+2] = '\0';
393
load_packet_disector(button, field, 1, &clh, ph.incl_len);
400
clis = lookup_widget(GTK_WIDGET (button), "clist2");
401
gtk_clist_clear(GTK_CLIST(clis));
403
for (j=0; j<howmanypackets; j++) {
405
/* next the pcap packet header */
406
fread(pkt_temp, sizeof(ph), 1, file_p);
412
/* copy the 16 bytes into ph structure */
413
memcpy(&ph, pkt_temp, 16);
415
/* and the packet itself, but only up to the capture length */
416
freads = fread(pkt_temp+sizeof(ph), ph.incl_len, 1, file_p);
422
/* convert the packet information from int to hex */
423
for(ji=0; ji<(sizeof(ph)+ph.incl_len); ji++)
424
c8(&field[2*ji], *(pkt_temp+ji));
425
field[2*ji+2] = '\0';
427
/* we have to dissect the packet to get information for the list */
428
load_packet_disector(button, field, 2, &clh, ph.incl_len);
429
//printf("tukaj3 %s\n", field);
431
/* calculate the time information */
439
timediff = ((double)((double)ph.ts_sec - (double)secu)*1000000 +
440
(double)((double)ph.ts_usec - (double)usecu)) / 1000000;
441
timebeg = ((double)((double)ph.ts_sec - (double)secb)*1000000 +
442
(double)((double)ph.ts_usec - (double)usecb)) / 1000000;
445
//printf("tukaj2 %s\n", field);
450
/* insert a new row into clist */
451
load_gen_p_data(button, clis, field, &ph, j+1, &clh, timediff, timebeg);
453
if (j == howmanypackets)
454
error("Only first 1000 packets loaded!\nTo change this modify #define on top of callbacks.c");
462
/* this one loads the parameters from file into notebook2 (Genp page) */
463
int load_gen_p_data(GtkButton *button, GtkWidget *clis, char *fieldek, struct pcaprec_hdr *ph2,
464
int pkt_nr, struct clist_hdr *clptr, double timediff, double timebeg) {
468
gchar field_p[1][3100];
470
datap[0]=&fieldp[0][0];
471
datap[1]=&fieldp[1][0];
472
datap[2]=&fieldp[2][0];
473
datap[3]=&fieldp[3][0];
474
datap[4]=&fieldp[4][0];
475
datap[5]=&fieldp[5][0];
476
datap[6]=&fieldp[6][0];
477
datap[7]=&field_p[0][0];
479
//printf("TUKAJ1:%s\n", fieldek);
480
g_snprintf(fieldp[0], 20, "%d", pkt_nr);
481
g_snprintf(fieldp[1], 20, "%f", timebeg);
482
g_snprintf(fieldp[2], 20, "%f", timediff);
484
if ( (*ph2).incl_len == (*ph2).orig_len )
485
g_snprintf(fieldp[3], 20, "%d", (*ph2).incl_len);
487
g_snprintf(fieldp[3], 20, "%d !", (*ph2).incl_len);
489
g_snprintf(fieldp[4], 20, "%s", clptr->src);
490
g_snprintf(fieldp[5], 20, "%s", clptr->dst);
494
g_snprintf(fieldp[6], 20, "Ethernet II");
498
g_snprintf(fieldp[6], 20, "Ethernet 802.3");
502
g_snprintf(fieldp[6], 20, "ARP");
506
g_snprintf(fieldp[6], 20, "IPv4");
510
g_snprintf(fieldp[6], 20, "TCP");
514
g_snprintf(fieldp[6], 20, "UDP");
518
g_snprintf(fieldp[6], 20, "IGMP");
522
g_snprintf(fieldp[6], 20, "ICMP");
527
g_snprintf(field_p[0], 2*(32+(*ph2).incl_len), "%s", fieldek);
529
gtk_clist_append(GTK_CLIST(clis), datap);
535
/* this routine was changed. it loads the packet into notebook2 (Builder page) or it checks the file containing the packets
536
* for loading into Genp window
537
* if who called = 1 - we load the contents into builder field
538
* if who called = 2 - we load the contenst into Genp window but we need the information for filling in the clist
540
int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct clist_hdr *clptr, int dolpaketa) {
547
//printf("\n:\n%s\n", fieldek);
548
//convert8field(ptrt, ptrf); insint(button, "entry179", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
549
//convert8field(ptrt, ptrf+8); insint(button, "entry180", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
550
//convert8field(ptrt, ptrf+16); insint(button, "entry181", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
551
//convert8field(ptrt, ptrf+24); insint(button, "entry182", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
555
/* what is the shortest length we still allow?
556
* we don't care if the packet is shorter than actually allowed to go on ethernet
557
* maybe the user just wanted to save packet even if it is to short, so why not load it?
558
* what we do demand is, that every layer must be completed
559
* ok, here at least 14 bytes: 6 dest mac, 6 source mac and 2 for type or length*/
561
error("Can't load packet: Ethernet header is not long enough!");
565
/* first there is destination mac */
566
w1 = lookup_widget(GTK_WIDGET(button), "L_dst_mac");
567
for (i=1; i<=18; i++, ptrt++) {
577
gtk_entry_set_text(GTK_ENTRY(w1), temp);
579
memcpy(clptr->dst, temp, 20);
583
w2 = lookup_widget(GTK_WIDGET(button), "L_src_mac");
584
for (i=1; i<=18; i++, ptrt++) {
594
gtk_entry_set_text(GTK_ENTRY(w2), temp);
596
memcpy(clptr->src, temp, 20);
598
/* next there is type or length field or 802.1q */
599
i = char2x(ptrf)*256 + char2x(ptrf+2);
601
remain = remain - 14;
603
/* in case of a vlan tag 0x8100 == 33024) */
604
w1 = lookup_widget(GTK_WIDGET(button), "bt_8021q");
605
w2 = lookup_widget(GTK_WIDGET(button), "frame6");
608
error("Can't load packet: Ethernet VLAN field is not long enough!");
618
if (whocalled == 1) {
619
w3 = lookup_widget(GTK_WIDGET(button), "L_optmenu2_bt");
620
w4 = lookup_widget(GTK_WIDGET(button), "checkbutton39");
621
w5 = lookup_widget(GTK_WIDGET(button), "checkbutton40");
622
w6 = lookup_widget(GTK_WIDGET(button), "L_vlan_id");
623
w7 = lookup_widget(GTK_WIDGET(button), "entry165");
625
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
626
gtk_widget_set_sensitive (w2, TRUE);
628
gtk_option_menu_set_history (GTK_OPTION_MENU (w3), (i>>1));
631
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w4), FALSE);
633
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w4), TRUE);
635
inspar(button, "L_vlan_id", ptrf, 3);
640
i = char2x(ptrf)*256 + char2x(ptrf+2);
642
/* we support now vlan stacking, in case the protocol in once again 0x8100
643
* we just add next 4 bytes in a QinQ field and switch the toggle button */
646
error("Can't load packet: QinQ VLAN field is not long enough!");
653
if (whocalled == 1) {
654
gtk_widget_set_sensitive (w7, TRUE);
655
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w5), TRUE);
657
inspar(button, "entry165", ptrf, 4);
662
i = char2x(ptrf)*256 + char2x(ptrf+2);
665
if (whocalled == 1) {
666
gtk_widget_set_sensitive (w7, FALSE);
667
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w5), FALSE);
672
if (whocalled == 1) {
673
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
674
gtk_widget_set_sensitive (w2, FALSE);
678
/* c will tell us which ethernet type we have */
681
/* ok, from now one, we split the dissection in different routines, depending on what values */
682
/* now if length is <= 1500, we have 802.3 ethernet and this value means length of ethernet packet */
684
next_prot = ethernet_8023(button, whocalled);
685
/* Values between 1500 and 1536 are forbidden */
686
else if ( (i>1500) && (i<1536) ) {
687
error("Can't load packet: Wrong ethernet length/type field");
690
/* if i >= 1536 - ethernet ver II */
692
next_prot = ethernet_verII(button, whocalled);
695
/* ok, so we have dissected the ethernet layer and now move on two the next layer.
696
* if the ethernet dissector returns -1, this means an error and we quit
697
* otherwise, the return value can be 2048 == 0x0800 and this means the ipv4
698
* so we try to dissect ipv4 header. in case it is ok, we activate the ippkt_radibt
699
* and this one then calls the callback which fills in ethernet ver II type field
700
* and PID field in 802.3 LLC/SNAP field. It is the same for arp packets
701
* for other packets we will try to open the userdefined window */
703
/* we got an error? */
708
else if (next_prot == 2048) {
709
/* ok, ipv4 should follow, so we call the routine for parsing ipv4 header. */
710
next_prot = ipv4_header(button, whocalled, clptr);
714
/* if the return value from parsing ipv4 header was != 0, then the header parameters
715
* are ok and we can open ipv4 notebook page activate toggle button (button calls
716
* the callback then!!! */
717
w1 = lookup_widget(GTK_WIDGET(button), "ippkt_radibt");
718
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
720
/* here we do the further parsing: tcp, udp, icmp, ...*/
721
if (next_prot == 1) {
722
/* try to parse icmp header */
723
next_prot = icmp_header(button, whocalled);
724
/* not ok, return an error */
727
/* ok, lets activate the icmp notebook */
729
w1 = lookup_widget(GTK_WIDGET(button), "icmp_bt");
730
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
733
else if (next_prot == 2) {
734
/* try to parse igmp header */
735
next_prot = igmp_header(button, whocalled);
736
/* not ok, return an error */
739
/* ok, lets activate the igmp notebook */
741
w1 = lookup_widget(GTK_WIDGET(button), "igmp_bt");
742
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
745
else if (next_prot == 6) {
746
/* try to parse tcp header */
747
next_prot = tcp_header(button, whocalled);
748
/* not ok, return an error */
751
/* ok, lets activate the tcp notebook */
753
w1 = lookup_widget(GTK_WIDGET(button), "tcp_bt");
754
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
757
/* protocols on top of tcp would follow here */
760
else if (next_prot == 17) {
761
/* try to parse udp header */
762
next_prot = udp_header(button, whocalled);
763
/* not ok, return an error */
766
/* ok, lets activate the udp notebook */
768
w1 = lookup_widget(GTK_WIDGET(button), "udp_bt");
769
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
772
/* protocols on top of udp would follow here */
774
/* protocol we do not support yet; user defined window */
776
next_prot = usedef_insert(button, "text2", whocalled);
777
w1 = lookup_widget(GTK_WIDGET(button), "ip_user_data_bt");
778
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
782
else if (next_prot == 2054) {
783
/* ok, arp header follows */
784
next_prot = arp_header(button, whocalled);
788
w1 = lookup_widget(GTK_WIDGET(button), "arppkt_radiobt");
789
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
792
/* when ipv6 will be added, activate ipv6 button instead of userdef button */
793
else if (next_prot == 34525) {
794
//w1 = lookup_widget(GTK_WIDGET(button), "IPv6_rdbt");
795
//gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
796
w1 = lookup_widget(GTK_WIDGET(button), "usedef2_radibt");
797
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
800
inspar(button, "L_ethtype", ptrf, 4);
802
/* -2 means only llc without snap was used, so we don't insert the value in pid field */
803
if (next_prot != -2) {
805
inspar(button, "L_pid", ptrf, 4);
808
/* anything else - user defined */
810
/* setting "usedef2_radibt" toggle button to true will call the callback which will clear
811
eth II type field and 802.3 pid field, so we have to fill this later */
812
w1 = lookup_widget(GTK_WIDGET(button), "usedef2_radibt");
813
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
815
/* we still have c to distinguish between ver II and 802.3 */
819
inspar(button, "L_ethtype", ptrf, 4);
821
/* 802.3 and with LLC SNAP */
822
else if (next_prot != -2) {
824
inspar(button, "L_pid", ptrf, 4);
827
next_prot = usedef_insert(button, "text1", whocalled);
834
int arp_header(GtkButton *button, int whocalled) {
844
/* arp header length == 28; but packet can be longer, f.e. to satisfy the min packet length */
846
error("Can't load packet: Packet length shorter than ARP header length!");
850
remain = remain - 28;
853
inspar(button, "A_hwtype", ptrf, 4);
856
inspar(button, "A_prottype", ptrf, 4);
859
inspar(button, "A_hwsize", ptrf, 2);
862
inspar(button, "A_protsize", ptrf, 2);
865
if ( (*ptrf == '0') && (*(ptrf+1) == '0') && (*(ptrf+2) == '0') && (*(ptrf+3) == '1') ) {
866
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton10");
867
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
870
else if ( (*ptrf == '0') && (*(ptrf+1) == '0') && (*(ptrf+2) == '0') && (*(ptrf+3) == '2') ) {
871
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton11");
872
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
876
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton17");
877
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
878
inspar(button, "entry81", ptrf, 4);
883
w1 = lookup_widget(GTK_WIDGET(button), "A_sendermac");
884
for (i=1; i<=18; i++, ptrt++) {
892
gtk_entry_set_text(GTK_ENTRY(w1), temp);
897
w1 = lookup_widget(GTK_WIDGET(button), "A_senderip");
898
for (i=1; i<=12; i++, ptrt++) {
902
snprintf(tmp, 4, "%d", x);
904
snprintf(tmp, 5, "%d.", x);
908
tmp[(i-1)%3] = *ptrf++;
911
gtk_entry_set_text(GTK_ENTRY(w1), temp);
915
w1 = lookup_widget(GTK_WIDGET(button), "A_targetmac");
916
for (i=1; i<=18; i++, ptrt++) {
924
gtk_entry_set_text(GTK_ENTRY(w1), temp);
929
w1 = lookup_widget(GTK_WIDGET(button), "A_targetip");
930
for (i=1; i<=12; i++, ptrt++) {
934
snprintf(tmp, 4, "%d", x);
936
snprintf(tmp, 5, "%d.", x);
940
tmp[(i-1)%3] = *ptrf++;
943
gtk_entry_set_text(GTK_ENTRY(w1), temp);
950
int igmp_header(GtkButton *button, int whocalled) {
960
/* well normal igmp type should have at least 8 bytes, so this is min for us */
962
error("Can't load packet: Packet length shorter than IGMP header length!");
971
inspar(button, "entry166", ptrf, 2);
973
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu20");
974
w2 = lookup_widget(GTK_WIDGET(button), "notebook8");
977
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 1);
978
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 1);
981
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 0);
982
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
986
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 2);
987
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
990
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 3);
991
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
994
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 4);
995
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 2);
998
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 5);
999
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1002
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 6);
1003
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1006
inspar(button, "entry167", ptrf, 2);
1008
/* set checksum button on auto */
1009
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton41");
1010
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1014
if ( (x == 17) && (remain>4) ) { /* IGMP V3 query */
1015
/*insert group ip */
1017
memset(temp, 0, 20);
1018
w1 = lookup_widget(GTK_WIDGET(button), "entry169");
1019
for (i=1; i<=12; i++, ptrt++) {
1023
snprintf(tmp, 4, "%d", x);
1025
snprintf(tmp, 5, "%d.", x);
1029
tmp[(i-1)%3] = *ptrf++;
1032
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1034
inspar(button, "entry171", ptrf, 4);
1035
x1 = (int)retint2(ptrf, 4);
1036
inspar(button, "entry172", ptrf, 4);
1037
/*#inspar(button, "entry173", ptrf, x1);*/
1038
inspar(button, "entry173", ptrf, remain);
1041
else if (x==22) { /*IGMP V3 report */
1042
inspar(button, "entry176", ptrf, 4);
1043
x1 = (int)retint2(ptrf, 4);
1044
inspar(button, "entry177", ptrf, 4);
1045
inspar(button, "entry178", ptrf, x1);
1048
else { /*all the other versions */
1049
/*insert group ip */
1051
memset(temp, 0, 20);
1052
w1 = lookup_widget(GTK_WIDGET(button), "entry175");
1053
for (i=1; i<=12; i++, ptrt++) {
1057
snprintf(tmp, 4, "%d", x);
1059
snprintf(tmp, 5, "%d.", x);
1063
tmp[(i-1)%3] = *ptrf++;
1066
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1074
int icmp_header(GtkButton *button, int whocalled) {
1083
/* well normal icmp type should have at least 8 bytes, so this is min for us */
1085
error("Can't load packet: Packet length shorter than ICMP header length!");
1093
/* insert version */
1094
inspar(button, "entry57", ptrf, 2);
1096
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu4");
1098
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 0);
1100
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 1);
1102
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 2);
1104
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 3);
1107
if (x == 0) { /* echo reply */
1108
/* insert code, checksum, identifier and seq number and data if there is some */
1109
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1110
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 0);
1111
inspar(button, "entry62", ptrf, 2);
1112
//inspar(button, "entry63", ptrf, 4);
1114
inspar(button, "entry64", ptrf, 4);
1115
inspar(button, "entry65", ptrf, 4);
1116
/* set checksum button on auto */
1117
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton16");
1118
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1120
inspar(button, "entry66", ptrf, remain * 2);
1122
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton17");
1123
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1126
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton17");
1127
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1131
else if (x == 3) { /* destination unreacheable */
1132
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1133
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 2);
1137
inspar(button, "entry58", ptrf, 2);
1139
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu5");
1140
if ( (x >= 0) && (x <= 15) )
1141
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), x);
1143
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 16);
1145
/* insert code, checksum, identifier and seq number and data if there is some */
1146
//inspar(button, "entry59", ptrf, 4);
1148
inspar(button, "entry60", ptrf, 8);
1149
/* set checksum button on auto */
1150
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton15");
1151
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1153
inspar(button, "entry61", ptrf, remain * 2);
1155
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton24");
1156
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1159
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton24");
1160
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1163
else if (x == 8) { /* echo request */
1164
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1165
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 5);
1166
/* insert code, checksum, identifier and seq number and data if there is some */
1167
inspar(button, "entry74", ptrf, 2);
1168
//inspar(button, "entry77", ptrf, 4);
1170
inspar(button, "entry75", ptrf, 4);
1171
inspar(button, "entry78", ptrf, 4);
1172
/* set checksum button on auto */
1173
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton20");
1174
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1176
inspar(button, "entry76", ptrf, remain * 2);
1178
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton19");
1179
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1182
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton19");
1183
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1187
else { /* all the rest */
1188
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1189
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 1);
1190
/* insert code, checksum and data if there is some */
1191
inspar(button, "entry157", ptrf, 2);
1192
//inspar(button, "entry158", ptrf, 4);
1194
/* set checksum button on auto */
1195
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton38");
1196
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1198
inspar(button, "entry159", ptrf, (remain + 4) * 2);
1206
int usedef_insert(GtkButton *button, char *entry, int whocalled) {
1214
/* get access to buffer of the text field */
1215
w2 = lookup_widget(GTK_WIDGET(button), entry);
1216
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1218
/* copy data to tmp field */
1219
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1220
tmp[i] = *ptrf++; i++;
1221
tmp[i] = *ptrf++; i++;
1222
/* we allow only 16 bytes in each row - looks nicer */
1223
if ((j % 16) == 0 && (j > 1)) {
1232
/* insert the text in the text field */
1233
gtk_text_buffer_set_text(buffer,tmp,-1);
1241
int tcp_header(GtkButton *button, int whocalled) {
1244
char tmp[4600], tmp2[3], ch;
1252
/* for standard header this is minimum length */
1254
error("Can't load packet: Packet length shorter than TCP header length!");
1258
/* ok, packet is long enough to fill in the standard header, but what is the header length?
1259
* we insert this later but need now to see that the packet is long enough */
1260
x = retint(ptrf+24);
1261
if ( (x * 4) > remain ) {
1262
error("Can't load packet:\nPacket lenght shorter than TCP header length!");
1266
error("Can't load packet:\nTCP header length shorter than 20 bytes!");
1271
insint(button, "entry46", ptrf, 4);
1273
/* destination port */
1274
insint(button, "entry47", ptrf, 4);
1276
/* sequence number */
1277
insint(button, "entry48", ptrf, 8);
1279
/* acknowledgement number */
1280
insint(button, "entry49", ptrf, 8);
1282
/* now we insert value for length */
1283
snprintf(tmp2, 3, "%d", x*4);
1284
w1 = lookup_widget(GTK_WIDGET(button), "entry50");
1285
gtk_entry_set_text(GTK_ENTRY(w1), tmp2);
1287
/* increase by one for length and for another one for 4 bits that are reserved */
1290
/* flags; next byte */
1291
ch = char2x(ptrf) % 0x0100;
1293
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton22");
1294
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x80) > 0 ? TRUE : FALSE);
1296
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton23");
1297
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x40) > 0 ? TRUE : FALSE);
1299
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton7");
1300
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x20) > 0 ? TRUE : FALSE);
1302
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton8");
1303
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x10) > 0 ? TRUE : FALSE);
1305
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton9");
1306
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x08) > 0 ? TRUE : FALSE);
1308
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton10");
1309
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x04) > 0 ? TRUE : FALSE);
1311
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton11");
1312
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x02) > 0 ? TRUE : FALSE);
1314
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton12");
1315
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x01) > 0 ? TRUE : FALSE);
1320
insint(button, "entry51", ptrf, 4);
1323
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton13");
1324
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1325
//inspar(button, "entry52", ptrf, 4);
1329
insint(button, "entry53", ptrf, 4);
1332
/* - 20 for standard header */
1333
inspar(button, "entry54", ptrf, ( (x*4) - 20) * 2);
1335
remain = remain - x*4;
1337
/* get access to buffer of the text field */
1338
w2 = lookup_widget(GTK_WIDGET(button), "text4");
1339
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1342
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton14");
1343
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1345
/* copy data to tmp field */
1346
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1347
tmp[i] = *ptrf++; i++;
1348
tmp[i] = *ptrf++; i++;
1349
/* we allow only 16 bytes in each row - looks nicer */
1350
if ((j % 16) == 0 && (j > 1)) {
1359
/* insert the text in the text field */
1360
gtk_text_buffer_set_text(buffer,tmp,-1);
1363
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton14");
1364
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1367
/* since tcp does not have any protocol field we could return destination port value which
1368
* usually describes next layer protocol; currently we return 1 */
1373
int udp_header(GtkButton *button, int whocalled) {
1383
/* for standard header this is minimum length */
1385
error("Can't load packet: Packet length shorter than UDP header length!");
1389
remain = remain - 8;
1392
insint(button, "entry56", ptrf, 4);
1394
/* destination port */
1395
insint(button, "entry41", ptrf, 4);
1398
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton3");
1399
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1400
//insint(button, "entry42", ptrf, 4);
1404
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton4");
1405
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1406
//inspar(button, "entry43", "", 4);
1409
/* get access to buffer of the text field */
1410
w2 = lookup_widget(GTK_WIDGET(button), "text3");
1411
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1414
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton5");
1415
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1417
/* copy data to tmp field */
1418
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1419
tmp[i] = *ptrf++; i++;
1420
tmp[i] = *ptrf++; i++;
1421
/* we allow only 16 bytes in each row - looks nicer */
1422
if ((j % 16) == 0 && (j > 1)) {
1431
/* insert the text in the text field */
1432
gtk_text_buffer_set_text(buffer,tmp,-1);
1435
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton5");
1436
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1439
/* since udp does not have any protocol field we could return destination port value which
1440
* usually describes next layer protocol; currently we return 1 */
1445
int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) {
1448
int x, header_l, prot;
1454
/* for standard header this is minimum length */
1456
error("Can't load packet: IPv4 header field is not long enough!");
1460
/* first comes version but we will first check the length and then insert version */
1463
/* check the header length */
1464
/* we don't need to check the return value here, it is already done when reading from file */
1465
header_l = retint(ptrf);
1466
/* header length is the number of 32-bit words in the header, including any options.
1467
* Since this is a 4-bit field, it limits the header to 60 bytes. So the remaining length
1468
* should be at least that long or we exit here */
1469
if ( (header_l * 4) < 20 ) {
1470
error("Can't load packet:\nIPv4 header length shorter than 20 bytes!");
1473
if ( (header_l * 4) > remain ) {
1474
error("Can't load packet:\nPacket lenght shorter than IPv4 header length!");
1480
/* insert version */
1481
inspar(button, "entry26", ptrf, 1);
1483
/* insert header length */
1484
inspar(button, "entry27", ptrf, 1);
1487
inspar(button, "entry28", ptrf, 2);
1489
/* insert total length */
1490
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton21");
1491
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1492
//insint(button, "entry29", ptrf, 4);
1500
/* insert identification */
1501
inspar(button, "entry30", ptrf, 4);
1507
*tmp = 0x30; /* 0x30 == 0 */
1510
x = x >> 1; /* use only first 3 bits */
1513
w1 = lookup_widget(GTK_WIDGET(button), "entry31");
1514
snprintf(tmp, 4, "%d", x);
1515
gtk_entry_set_text(GTK_ENTRY(w1), tmp);
1518
/* insert fragment offset */
1519
*tmp = 0x30; /* 0x30 == 0 */
1521
x = (char2x(tmp)%2); /* need only last bit */
1526
strncpy(tmp+1, ptrf+1, 3);
1529
insint(button, "entry32", tmp, 4);
1532
insint(button, "entry44", ptrf, 2);
1537
prot = char2x(ptrf);
1540
/* insert protocol */
1541
insint(button, "entry34", ptrf, 2);
1543
/* insert header checksum */
1544
w1 = lookup_widget(GTK_WIDGET(button), "ip_header_cks_cbt");
1545
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1546
//inspar(button, "entry35", ptrf, 4);
1553
/*insert source ip */
1555
memset(temp, 0, 20);
1557
w1 = lookup_widget(GTK_WIDGET(button), "entry38");
1558
for (i=1; i<=12; i++, ptrt++) {
1562
snprintf(tmp, 4, "%d", x);
1564
snprintf(tmp, 5, "%d.", x);
1568
tmp[(i-1)%3] = *ptrf++;
1573
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1575
memcpy(clptr->src, temp, 20);
1577
/*insert destination ip */
1579
memset(temp, 0, 20);
1581
w1 = lookup_widget(GTK_WIDGET(button), "entry37");
1582
for (i=1; i<=12; i++, ptrt++) {
1586
snprintf(tmp, 4, "%d", x);
1588
snprintf(tmp, 5, "%d.", x);
1592
tmp[(i-1)%3] = *ptrf++;
1596
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1598
memcpy(clptr->dst, temp, 20);
1600
/* insert ipv4 options
1601
* header_l * 4 == total header length, - 20 for standard header == options length in bytes*/
1603
inspar(button, "entry39", ptrf, ( (header_l*4) - 20) * 2);
1605
remain = remain - (header_l * 4);
1611
int ethernet_8023(GtkButton *button, int whocalled) {
1613
int dsap, lsap, ctrl;
1617
protokol = ETH_802_3;
1622
error("Can't load packet: Ethernet 802.3 LLC field is not long enough!");
1625
remain = remain - 3;
1627
w1 = lookup_widget(GTK_WIDGET(button), "bt_8023");
1628
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1630
//w2 = lookup_widget(GTK_WIDGET(button), "frame7");
1631
//gtk_widget_set_sensitive (w2, TRUE);
1632
//gtk_notebook_set_page(GTK_NOTEBOOK(w3), 1);
1634
w1 = lookup_widget(GTK_WIDGET(button), "entry5");
1635
//inspar(button, "entry5", ptrf, 4);
1637
gtk_widget_set_sensitive (w1, FALSE);
1639
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton2");
1640
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1642
/*now the LLC / LLC-SNAP part */
1643
/* we decode only RFC 1042 format, that means the following value:
1644
dsap == ssap == 0xAA
1648
dsap = char2x(ptrf);
1649
inspar(button, "L_dsap", ptrf, 2);
1650
lsap = char2x(ptrf);
1651
inspar(button, "L_ssap", ptrf, 2);
1652
ctrl = char2x(ptrf);
1653
inspar(button, "L_ctrl", ptrf, 2);
1655
/* in case dsap != ssap != 0xAA or ctrl != 0x03 or remain length < 5 bytes, we have only
1656
* LLC without SNAP and we return value for user defined next layer */
1657
if ( (dsap != 170 ) || (lsap != 170) || (ctrl != 3) || (remain < 5) ) {
1658
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llc_tbt");
1659
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1660
w1 = lookup_widget(GTK_WIDGET(button), "L_oui");
1661
w2 = lookup_widget(GTK_WIDGET(button), "L_pid");
1662
gtk_widget_set_sensitive (w1, FALSE);
1663
gtk_widget_set_sensitive (w2, FALSE);
1664
/* this means we insert all the data as user defined field */
1667
/* in this case everything is ok but oui in not 0 */
1668
/* <--------------this is oui---------------------> */
1669
else if ( (char2x(ptrf) + char2x(ptrf+2) + char2x(ptrf+4) != 0 ) ) {
1670
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llc_tbt");
1671
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1672
w1 = lookup_widget(GTK_WIDGET(button), "L_oui");
1673
w2 = lookup_widget(GTK_WIDGET(button), "L_pid");
1674
gtk_widget_set_sensitive (w1, FALSE);
1675
gtk_widget_set_sensitive (w2, FALSE);
1676
/* this means we insert all the data as user defined field */
1680
/* substract 3 for oui and 2 for pid */
1681
remain = remain - 5;
1683
/* ok, so we have dsap and ssap == 0xAA, Ctlr == 0x03, OUI == 0x0 and lenght is long enough */
1684
/* set llc-snap button */
1685
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llcsnap_tbt");
1686
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1688
/* insert 0x00 into oui field */
1689
inspar(button, "L_oui", ptrf, 6);
1690
pid = char2x(ptrf)*256 + char2x(ptrf+2);
1698
int ethernet_verII(GtkButton *button, int whocalled) {
1706
w1 = lookup_widget(GTK_WIDGET(button), "bt_ver2");
1707
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1710
pid = char2x(ptrf)*256 + char2x(ptrf+2);
1718
/* this one inserts (length) characters from (char *from) into entry named (char *entry). It adds \0
1719
at the end and in moves pointer ptrf (this one points the the next "data" to be inserted) by length */
1720
void inspar(GtkButton *button, char *entry, char *from, int length) {
1726
ptr = malloc(length * sizeof(char) + 1);
1728
widg = lookup_widget(GTK_WIDGET(button), entry);
1730
strncpy(ptr, from, length);
1732
gtk_entry_set_text(GTK_ENTRY(widg), ptr);
1733
ptrf = ptrf + length;
1739
/* this one reads (length) characters strating at (char *from), converts them to int and inserts them
1740
into field (*entry) as integer. f.e: 0x56 == (int)86 => writes into (*entry) 86
1741
note that max size for length is 10!!! when calling this routine */
1742
void insint(GtkButton *button, char *entry, char *from, int length) {
1746
unsigned long value = 0;
1748
unsigned char x = 0;
1750
widg = lookup_widget(GTK_WIDGET(button), entry);
1752
for (i = 0; i < length; i++) {
1753
if ( (*from >= '0') && (*from <= '9'))
1755
else if ((*from >= 'A') && (*from <= 'F'))
1757
else if ((*from >= 'a') && (*from <= 'f'))
1760
value = value + ((int)x) * ((unsigned long)1 << (4*(length-1-i)) );
1764
ptrf = ptrf + length;
1766
snprintf(tmp, 11, "%lu", value);
1767
gtk_entry_set_text(GTK_ENTRY(widg), tmp);
1771
/* from a character return int */
1772
signed int retint(char *ch) {
1776
if ( (*ch >= '0') && (*ch <= '9'))
1778
else if ((*ch >= 'A') && (*ch <= 'F'))
1780
else if ((*ch >= 'a') && (*ch <= 'f'))
1790
/* this one reads (length) characters strating at (*from), and returns integer (max 10 char length) */
1791
unsigned long retint2(char *from, int length) {
1793
unsigned long value = 0;
1795
unsigned char x = 0;
1797
for (i = 0; i < length; i++) {
1798
if ( (*from >= '0') && (*from <= '9'))
1800
else if ((*from >= 'A') && (*from <= 'F'))
1802
else if ((*from >= 'a') && (*from <= 'f'))
1805
value = value + ((int)x) * ((unsigned long)1 << (4*(length-1-i)) );
1813
/* i have newer really understood the endians... help appreciated...
1814
* this routines just converts the contents of a char field of size 8 chars
1815
* it works also, if destination and source are the same field*/
1817
void convert8field(char *to, char *from) {
1821
/* we copy first the source contents */
1822
memcpy(f1, from, 8);
1824
memcpy(to+0, f1+6,1);
1825
memcpy(to+1, f1+7,1);
1826
memcpy(to+2, f1+4,1);
1827
memcpy(to+3, f1+5,1);
1828
memcpy(to+4, f1+2,1);
1829
memcpy(to+5, f1+3,1);
1830
memcpy(to+6, f1+0,1);
1831
memcpy(to+7, f1+1,1);