summaryrefslogtreecommitdiff
path: root/staging/modifications.c
blob: 1affbbbd1f33783ed3ca432168722afe04b52578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/*
 * Mausezahn - A fast versatile traffic generator
 * Copyright (C) 2008-2010 Herbert Haas
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the 
 * Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with 
 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
 * 
*/




// ***************************************************************************
// 
//    This sections contains functions to manipulate headers of 
//    Eth, MPLS, 802.1Q, IP, UDP, and TCP:
//    
//      int update_Eth_SA       (libnet_t *l, libnet_ptag_t t)
//      int update_IP_SA        (libnet_t *l, libnet_ptag_t t)
//      int update_IP_DA        (libnet_t *l, libnet_ptag_t t)
//      int update_IP6_SA       (libnet_t *l, libnet_ptag_t t)
//      int update_IP6_DA       (libnet_t *l, libnet_ptag_t t)
//      int update_DPORT        (libnet_t *l, libnet_ptag_t t)
//      int update_SPORT        (libnet_t *l, libnet_ptag_t t)
//      int update_TCP_SQNR     (libnet_t *l, libnet_ptag_t t)
//    
//    and finally:
//    
//      int print_frame_details()
//
// ***************************************************************************

#include "mz.h"
#include "mops.h"

///////////////////////////////////////////////////////////////////////////
// Applies another random Ethernet source address to a given Ethernet-PTAG.
// (The calling function should check 'tx.eth_src_rand' whether the SA 
// should be randomized.)
// 
int update_Eth_SA(libnet_t *l, libnet_ptag_t t)
{
   tx.eth_src[0] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256) & 0xFE; // keeps bcast-bit zero
   tx.eth_src[1] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
   tx.eth_src[2] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
   tx.eth_src[3] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
   tx.eth_src[4] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
   tx.eth_src[5] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
 
   t = libnet_build_ethernet (tx.eth_dst, 
			      tx.eth_src, 
			      tx.eth_type, 
			      NULL,              // the payload
			      0, 
			      l, 
			      t);

   if (t == -1)
     {
	fprintf(stderr, " mz/update_Eth_SA: Can't build Ethernet header: %s\n",
		libnet_geterror(l));
	exit(EXIT_FAILURE);
     }
   
   return 0;
}


// Update official timestamp, own timestamp and sequence number in the RTP header. 
// The actual RTP message is stored in tx.udp_payload.
int update_RTP(libnet_t *l, libnet_ptag_t t)
{
	u_int8_t *ptr;
	struct mz_timestamp ts;
	
	tx.rtp_sqnr++;
	tx.rtp_stmp+=160; // TODO: different values for different codecs
	
	// update SQNR
	ptr = (u_int8_t*) &tx.rtp_sqnr;
	tx.udp_payload[2] = *(ptr+1);
	tx.udp_payload[3] = *ptr;

	// update official timestamp
	ptr = (u_int8_t*) &tx.rtp_stmp;
	tx.udp_payload[4] = *(ptr+3);
	tx.udp_payload[5] = *(ptr+2);
	tx.udp_payload[6] = *(ptr+1);
	tx.udp_payload[7] = *ptr;

   
	// update own timestamp
	getcurtime(&ts); // Now add TX timestamp:
	mops_hton4 ((u_int32_t*) &ts.sec,  &tx.udp_payload[16]);
	mops_hton4 ((u_int32_t*) &ts.nsec, &tx.udp_payload[20]);
   
	t = libnet_build_udp(tx.sp, 
			     tx.dp, 
			     tx.udp_len, 
			     tx.udp_sum,
			     tx.udp_payload,
			     tx.udp_payload_s,
			     l, 
			     t);

	if (t == -1) {
		fprintf(stderr," mz/send_frame: RTP header update failed!\n");
		exit (1);
	}
	return 0;
}


///////////////////////////////////////////////////////////////////////////
// Applies another SOURCE IP address, 
//  - either a random one (tx.ip_src_rand==1)
//  - or from a specified range (tx.ip_src_isrange==1) 
// to a given IP-PTAG.
// 
// Note: tx.ip_src MUST be already initialized with tx.ip_src_start.
//       This is done by 'get_ip_range_src()' in tools.c.
// 
// 
// RETURNS '1' if tx.ip_src restarts
// 
int update_IP_SA (libnet_t *l, libnet_ptag_t t)
{
   u_int8_t *x, *y;  
   int i=0;
   
   if (ipv6_mode) {
	   return update_IP6_SA(l, t);
   }

   if (tx.ip_src_rand)
     {
	tx.ip_src_h  = (u_int32_t) ( ((float) rand()/RAND_MAX)*0xE0000000); //this is 224.0.0.0
	i=1;
     }
   else if (tx.ip_src_isrange)
     {
	tx.ip_src_h++;
	if (tx.ip_src_h > tx.ip_src_stop) // reached the end of the range => restart!
	  {
	     tx.ip_src_h = tx.ip_src_start;
	     i=1;
	  }
     }
   
   // Now convert "tx.ip_src_h" into "tx.ip_src" which is in 'Network Byte Order':
   x = (unsigned char*) &tx.ip_src_h;
   y = (unsigned char*) &tx.ip_src;
   
   *y = *(x+3);
   y++;
   *y = *(x+2);
   y++;
   *y = *(x+1);
   y++;
   *y = *x;
   
   // TODO: Omit certain IP addresses:
   //       E.g. if (rand_ip == tx.ip_src) goto rand_again;  // never use true interface IP
   // TODO: Check other address exceptions ...

   t = libnet_build_ipv4 (tx.ip_len, 
			  tx.ip_tos, 
			  tx.ip_id, 
			  tx.ip_frag,
			  tx.ip_ttl, 
			  tx.ip_proto,
			  tx.ip_sum, 
			  tx.ip_src,             // possibly now random
			  tx.ip_dst,
			  (mode==IP) ? (tx.ip_payload_s) ? tx.ip_payload : NULL : NULL,  // if e.g. mode=UDP ignore payload argument
			  (mode==IP) ? tx.ip_payload_s : 0,
			  l, 
			  t);

   if (t == -1)
     {
	fprintf(stderr," mz/update_IP_SA: IP address manipulation failed!\n");
	exit (1);
     }

   return i;
}


int
update_IP6_SA(libnet_t *l, libnet_ptag_t t)
{
	int i = 0;
	if (tx.ip_src_rand) {
		fprintf(stderr, "Random source addresses are not supported in IPv6 mode.\n");
		exit(1);
	} else if (tx.ip_src_isrange) {
		if (incr_in6_addr(tx.ip6_src, &tx.ip6_src)
		     || (in6_addr_cmp(tx.ip6_src, tx.ip6_src_stop) > 0))
		{
			tx.ip6_src = tx.ip6_src_start;
			i = 1;
		}
	}

	t = libnet_build_ipv6(tx.ip_tos,
			      tx.ip_flow,
			      tx.ip_len,
			      tx.ip_proto,
			      tx.ip_ttl,
			      tx.ip6_src,
			      tx.ip6_dst,
			      (mode==IP) ? (tx.ip_payload_s) ? tx.ip_payload : NULL : NULL,
			      (mode==IP) ? tx.ip_payload_s : 0,
			      l,
			      t);

	if (t == -1) {
		fprintf(stderr," mz/update_IP6_SA: IP address manipulation failed!\n");
		exit (1);
	}

	return i;
}


/////////////////////////////////////////////////////////////////////////////////////////
// Applies another DESTINATION IP address from a specified range (tx.ip_dst_isrange==1) 
// to a given IP-PTAG.
// 
// Note: tx.ip_dst MUST be already initialized with tx.ip_dst_start.
//       tx.ip_dst_h 'mirrors' tx.ip_dst 
//       (i. e. tx.ip_dst_h is NOT in network byte order => easy to count)
//       This is done by 'get_ip_range_dst()' in tools.c.
// 
// RETURN VALUE: '1' if tx.ip_dst restarts
// 
int update_IP_DA(libnet_t *l, libnet_ptag_t t)
{
   u_int8_t *x, *y;  
   int i=0;

   if (ipv6_mode) {
	   return update_IP6_DA(l, t);
   }

   if (tx.ip_dst_isrange)
     {
	tx.ip_dst_h++;
	if (tx.ip_dst_h > tx.ip_dst_stop) // we reached the end of the range => restart!
	  {
	     tx.ip_dst_h = tx.ip_dst_start;
	     i=1;
	  }
     }

   
   // Now convert "tx.ip_dst_h" into "tx.ip_dst" which is in 'Network Byte Order':

   x = (unsigned char*) &tx.ip_dst_h;
   y = (unsigned char*) &tx.ip_dst;
   
   *y = *(x+3);
   y++;
   *y = *(x+2);
   y++;
   *y = *(x+1);
   y++;
   *y = *x;

   
   // TODO: Omit certain IP addresses:
   //       E.g. if (rand_ip == tx.ip_src) goto rand_again;  // never use true interface IP
   // TODO: Check other address exceptions ...
   
   t = libnet_build_ipv4 (tx.ip_len, 
			  tx.ip_tos, 
			  tx.ip_id, 
			  tx.ip_frag,
			  tx.ip_ttl, 
			  tx.ip_proto,
			  tx.ip_sum, 
			  tx.ip_src, 
			  tx.ip_dst,
			  (mode==IP) ? (tx.ip_payload_s) ? tx.ip_payload : NULL : NULL,  // if e.g. mode=UDP ignore payload argument
			  (mode==IP) ? tx.ip_payload_s : 0,
			  l, 
			  t);

   if (t == -1)
     {
	fprintf(stderr," mz/update_IP_DA: IP address manipulation failed!\n");
	exit (1);
     }

   return i;
}


int
update_IP6_DA(libnet_t *l, libnet_ptag_t t)
{
	int i = 0;
	if (tx.ip_dst_isrange) {
		if (incr_in6_addr(tx.ip6_dst, &tx.ip6_dst)
		     || (in6_addr_cmp(tx.ip6_dst, tx.ip6_dst_stop) > 0))
		{
			tx.ip6_dst = tx.ip6_dst_start;
			i = 1;
		}
	}

	t = libnet_build_ipv6(tx.ip_tos,
			      tx.ip_flow,
			      tx.ip_len,
			      tx.ip_proto,
			      tx.ip_ttl,
			      tx.ip6_src,
			      tx.ip6_dst,
			      (mode==IP) ? (tx.ip_payload_s) ? tx.ip_payload : NULL : NULL,
			      (mode==IP) ? tx.ip_payload_s : 0,
			      l,
			      t);

	if (t == -1) {
		fprintf(stderr," mz/update_IP6_DA: IP address manipulation failed!\n");
		exit (1);
	}

	return i;
}



///////////////////////////////////////////////////////////////////////////////////////
//
// Applies another DESTINATION PORT from a specified range to a given UDP- or TCP-PTAG.
// 
// Note: tx.dp MUST be already initialized with tx.dp_start
//       This is done by 'get_port_range()' in tools.c.
//
// RETURN VALUE: '1' if tx.dp restarts
//      
int update_DPORT(libnet_t *l, libnet_ptag_t t)
{
  // u_int32_t DP;
   int i=0;
   
  // DP = (u_int32_t) tx.dp;
  // DP++;
   tx.dp++;

   
   // Exceeded range => restart:
   if ((tx.dp > tx.dp_stop) ||  // we exceeded the end of the range 
       (tx.dp == 65535) )       // or exceeded the 16-bit range
     {
	tx.dp = tx.dp_start;
	i=1;
     }
   
   
   if (mode==UDP)
     {
	t = libnet_build_udp(tx.sp, 
			     tx.dp, 
			     tx.udp_len, 
			     tx.udp_sum,
			     (tx.udp_payload_s) ? tx.udp_payload : NULL,
			     tx.udp_payload_s, 
			     l, 
			     t);

	if (t == -1)
	  {
	     fprintf(stderr," mz/send_frame: UDP header manipulation failed!\n");
	     exit (1);
	  }
     }
   else // TCP
     {
	t = libnet_build_tcp (tx.sp,
			      tx.dp,
			      tx.tcp_seq, 
			      tx.tcp_ack,
			      tx.tcp_control,
			      tx.tcp_win, 
			      tx.tcp_sum, 
			      tx.tcp_urg, 
			      tx.tcp_len,
			      (tx.tcp_payload_s) ? tx.tcp_payload : NULL,
			      tx.tcp_payload_s, 
			      l, 
			      t);
		  
	if (t == -1)
	  {
	     fprintf(stderr, " mz/update_DPORT: Can't build TCP header: %s\n", libnet_geterror(l));
	     exit (0);
	  }  
     }
   
   return i;
}

   
///////////////////////////////////////////////////////////////////////////////////
//
// Applies another SOURCE PORT from a specified range to a given UDP- or TCP-PTAG.
// 
// Note: tx.sp MUST be already initialized with tx.sp_start
//       This is done by 'get_port_range()' in tools.c.
//       
// RETURN VALUE: '1' if tx.sp restarts
//       
int update_SPORT(libnet_t *l, libnet_ptag_t t)
{
   
//   u_int32_t SP;
   int i=0;
   
//   SP = (u_int32_t) tx.sp;
//   SP++;
   tx.sp++;

   
   // Exceeded range => restart:
   if ((tx.sp > tx.sp_stop) ||  // we exceeded the end of the range 
       (tx.sp == 65535) )       // or exceeded the 16-bit range
     {
	tx.sp = tx.sp_start;
	i=1;
     }
     
   if (mode==UDP)
     {
	t = libnet_build_udp(tx.sp,
			     tx.dp, 
			     tx.udp_len, 
			     tx.udp_sum,
			     (tx.udp_payload_s) ? tx.udp_payload : NULL,
			     tx.udp_payload_s, 
			     l, 
			     t);

	if (t == -1)
	  {
	     fprintf(stderr," mz/send_frame: UDP header manipulation failed!\n");
	     exit (1);
	  }
     }
   else // TCP
     {
	t = libnet_build_tcp (tx.sp,
			      tx.dp, 
			      tx.tcp_seq, 
			      tx.tcp_ack,
			      tx.tcp_control,
			      tx.tcp_win, 
			      tx.tcp_sum, 
			      tx.tcp_urg, 
			      tx.tcp_len,
			      (tx.tcp_payload_s) ? tx.tcp_payload : NULL,
			      tx.tcp_payload_s, 
			      l, 
			      t);
		  
	if (t == -1)
	  {
	     fprintf(stderr, " mz/update_SPORT: Can't build TCP header: %s\n", libnet_geterror(l));
	     exit (0);
	  }  
     }
   
   return i;   
}

#define LIBNET_CKSUM_CARRY(x) \
    (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))

int update_USUM(libnet_t *l, libnet_ptag_t t)
{
     int sum = 0;
     unsigned int tmp;

     if (tx.udp_sum != 0)
	return 0;

     sum += libnet_in_cksum((u_int16_t *) &tx.ip6_src, 16);
     if (tx.ip_option_s && tx.ip6_segs)
       sum += libnet_in_cksum((u_int16_t *) &tx.ip_option[tx.ip_option_s - 16], 16); // Use last IP address
     else
       sum += libnet_in_cksum((u_int16_t *) &tx.ip6_dst, 16);

     tmp = htonl(tx.udp_len);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);
     tmp = htonl(IPPROTO_UDP);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     tmp = ((htons(tx.sp) << 16) + htons(tx.dp));
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     tmp = htons(tx.udp_len) << 16;
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     if (tx.udp_payload_s)
       sum += libnet_in_cksum((u_int16_t *) tx.udp_payload, tx.udp_payload_s);

     tx.udp_sum = ntohs(LIBNET_CKSUM_CARRY(sum));

     t = libnet_build_udp(tx.sp,
			  tx.dp,
			  tx.udp_len,
			  tx.udp_sum,
			  tx.udp_payload_s ? tx.udp_payload : NULL,
			  tx.udp_payload_s,
			  l,
			  t);
     tx.udp_sum = 0;
     return t;
}

int update_TSUM(libnet_t *l, libnet_ptag_t t)
{
     int sum = 0;
     unsigned int tmp;

     if (tx.tcp_sum != 0)
	return 0;

     sum += libnet_in_cksum((u_int16_t *) &tx.ip6_src, 16);
     if (tx.ip_option_s && tx.ip6_segs)
       sum += libnet_in_cksum((u_int16_t *) &tx.ip_option[tx.ip_option_s - 16], 16); // Use last IP address
     else
       sum += libnet_in_cksum((u_int16_t *) &tx.ip6_dst, 16);

     tmp = htonl(tx.tcp_len);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);
     tmp = htonl(IPPROTO_TCP);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     tmp = ((htons(tx.sp) << 16) + htons(tx.dp));
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     tmp = htonl(tx.tcp_seq);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);
     tmp = htonl(tx.tcp_ack);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     tmp = ((ntohs(((tx.tcp_offset) << 12) + tx.tcp_control) << 16) + htons(tx.tcp_win));
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     tmp = htonl(tx.tcp_urg);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     sum += tx.tcp_sum_part;

     if (tx.tcp_payload_s)
       sum += libnet_in_cksum((u_int16_t *) tx.tcp_payload, tx.tcp_payload_s);

     tx.tcp_sum = ntohs(LIBNET_CKSUM_CARRY(sum));

     t = libnet_build_tcp (tx.sp,
	                   tx.dp,
	                   tx.tcp_seq,
	                   tx.tcp_ack,
	                   tx.tcp_control,
	                   tx.tcp_win,
	                   tx.tcp_sum,
	                   tx.tcp_urg,
	                   tx.tcp_len,
	                   tx.tcp_payload_s ? tx.tcp_payload : NULL,
	                   tx.tcp_payload_s,
	                   l,
	                   t);
     tx.tcp_sum = 0;

   return t;
}

int update_ISUM(libnet_t *l, libnet_ptag_t t)
{
     int sum = 0;
     unsigned int tmp;

     if (tx.icmp_chksum != 0)
	return 0;

     sum += libnet_in_cksum((u_int16_t *) &tx.ip6_src, 16);
     if (tx.ip_option_s && tx.ip6_segs)
       sum += libnet_in_cksum((u_int16_t *) &tx.ip_option[tx.ip_option_s - 16], 16); // Use last IP address
     else
       sum += libnet_in_cksum((u_int16_t *) &tx.ip6_dst, 16);

     tmp = htonl(LIBNET_ICMPV6_H + tx.icmp_payload_s);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);
     tmp = htonl(IPPROTO_ICMP6);
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     tmp = htonl(((tx.icmp_type << 8) + tx.icmp_code));
     sum += libnet_in_cksum((u_int16_t *) &tmp, 4);

     if (tx.icmp_payload_s)
       sum += libnet_in_cksum((u_int16_t *) tx.icmp_payload, tx.icmp_payload_s);

     tx.icmp_chksum = ntohs(LIBNET_CKSUM_CARRY(sum));

     t = libnet_build_icmpv4_echo (tx.icmp_type,
				   tx.icmp_code,
				   tx.icmp_chksum,
				   tx.icmp_ident,
				   tx.icmp_sqnr,
				   tx.icmp_payload_s ? tx.icmp_payload : NULL,
				   tx.icmp_payload_s,
				   l,
				   t);
     tx.icmp_chksum = 0;

   return t;
}

///////////////////////////////////////////////////////////////////////
//
// Applies another TCP SQNR from a specified range to a given TCP-PTAG
// 
// RETURN VALUE: '1' if tx.txp_seq restarts
// 
int update_TCP_SQNR(libnet_t *l, libnet_ptag_t t)
{

   u_int32_t diff;
   int i=0;
   
   tx.tcp_seq += tx.tcp_seq_delta;
   diff = tx.tcp_seq_stop - tx.tcp_seq_start;

   if (diff < tx.tcp_seq_stop) // start < stop
     {
	if (tx.tcp_seq > tx.tcp_seq_stop)
	  {
	     tx.tcp_seq = tx.tcp_seq_start;
	     i=1;
	  }
     }
   else // stop < start
     {
	if ( (tx.tcp_seq<tx.tcp_seq_start) && 
	     (tx.tcp_seq>tx.tcp_seq_stop) )
	  {
	     tx.tcp_seq = tx.tcp_seq_start;
	     i=1;
	  }
	
     }
   
   t = libnet_build_tcp (tx.sp,
			 tx.dp, 
			 tx.tcp_seq, 
			 tx.tcp_ack,
			 tx.tcp_control,
			 tx.tcp_win, 
			 tx.tcp_sum, 
			 tx.tcp_urg, 
			 tx.tcp_len,
			 (tx.tcp_payload_s) ? tx.tcp_payload : NULL,
			 tx.tcp_payload_s, 
			 l, 
			 t);
   
   if (t == -1)
     {
	fprintf(stderr, " mz/update_TCP_SQNR: Can't build TCP header: %s\n", libnet_geterror(l));
	exit (0);
     }  
   
   return i;
}


////////////////////////////////////////////////////////////////////////
//
//

int print_frame_details(void)
{
   unsigned char *dum1, *dum2;
   char pld[65535];
   char sa[32], da[32];
   
   if (!tx.packet_mode)
     {
	bs2str(tx.eth_dst, da, 6);
	bs2str(tx.eth_src, sa, 6);
	fprintf(stderr, " Eth: DA = %s, SA = %s\n",da,sa);
     }
   
   
   if (tx.dot1Q)
     {
	fprintf(stderr, " 802.1Q VLAN-TAG = %s\n", tx.dot1Q_txt);
     }

   if (tx.mpls)
     {
	fprintf(stderr," MPLS labels (label:exp:bos:ttl): %s\n",tx.mpls_verbose_string);
	
     }

   
   dum1 =  (unsigned char*) &tx.ip_src_h;
   dum2 = (unsigned char*) &tx.ip_dst_h;
   if (mode==IP) {
     (void) bs2str(tx.ip_payload, pld, tx.ip_payload_s);
   } else {
     strcpy(pld, "[see next layer]");
   }

   if (ipv6_mode) {
     char src6[64]; char dst6[64];
     libnet_addr2name6_r(tx.ip6_src, LIBNET_DONT_RESOLVE, src6, 64);
     libnet_addr2name6_r(tx.ip6_dst, LIBNET_DONT_RESOLVE, dst6, 64);

     fprintf(stderr," IP:  ver=6, dscp=%u, flow=%u, len=%u, next=%u, hop=%u "
             "SA=%s, DA=%s\n      payload=%s\n", tx.ip_tos, tx.ip_flow,
	     tx.ip_len, tx.ip_proto, tx.ip_ttl, src6, dst6, pld);
   }
   else {
     fprintf(stderr," IP:  ver=4, len=%u, tos=%u, id=%u, frag=%u, ttl=%u, proto=%u, sum=%u, "
	     "SA=%u.%u.%u.%u, DA=%u.%u.%u.%u,\n"
	     "      payload=%s\n", tx.ip_len, tx.ip_tos,
	     tx.ip_id, tx.ip_frag, tx.ip_ttl, tx.ip_proto, tx.ip_sum,
	     *(dum1+3),*(dum1+2),*(dum1+1),*(dum1), *(dum2+3),*(dum2+2),*(dum2+1),*(dum2+0), pld);
   }
   
   if ((mode==UDP)||(mode==DNS)||(mode==RTP))
     {
	bs2str(tx.udp_payload, pld, tx.udp_payload_s);
	fprintf(stderr, " UDP: sp=%u, dp=%u, len=%u, sum=%u, \n"
		"      payload=%s\n", tx.sp, tx.dp, tx.udp_len, tx.udp_sum, pld);
     }
   if (mode==TCP) // TODO: Improve message details (flags, ...)
     {
	bs2str(tx.tcp_payload, pld, tx.tcp_payload_s);
	fprintf(stderr, " TCP: sp=%u, dp=%u, S=%u, A=%u, flags=%x, win=%u, len=%u, sum=%u, \n"
		"      payload=%s\n", 
		tx.sp, tx.dp, tx.tcp_seq, tx.tcp_ack, tx.tcp_control, tx.tcp_win, tx.tcp_len, tx.tcp_sum, pld);
     }
   
   // send_icmp must prepare the verbose string because there are many
   // different types of ICMP packets...
   if (mode==ICMP) 
     {
	fprintf(stderr, " %s\n", tx.icmp_verbose_txt);
     }

   if (mode==ICMP6)
     {
	fprintf(stderr, " %s\n", tx.icmp_verbose_txt);
     }
   
   // libnet_diag_dump_pblock(l);
   fprintf(stderr,"\n");

   if (simulate)
     {
	fprintf(stderr, "*** NOTE: Simulation only! Nothing has been sent! ***\n");
	exit(0);
     }
   
   
   return 0;
}