mausezahn: make needlessly global variables static
[netsniff-ng-new.git] / staging / mz.h
blob42e64cfc607ccdfcc413756533fbf564ce75ba11
1 /*
2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 Herbert Haas
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 * details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
21 #ifndef __MAUSEZAHN__
22 #define __MAUSEZAHN__
24 #define _GNU_SOURCE
25 #include <libnet.h>
26 #include <pcap/pcap.h>
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <errno.h>
32 #include <limits.h>
33 #include <sys/time.h>
34 #include <time.h>
35 #include <signal.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <arpa/inet.h>
39 #include <sys/ioctl.h>
40 #include <netinet/in.h>
41 #include <stdarg.h>
42 #include <math.h>
43 #include <stdint.h>
45 extern int verbose_level;
47 static inline void verbose_l1(const char *format, ...)
49 va_list vl;
51 if (verbose_level < 1)
52 return;
54 va_start(vl, format);
55 vfprintf(stderr, format, vl);
56 va_end(vl);
59 static inline void verbose_l2(const char *format, ...)
61 va_list vl;
63 if (verbose_level < 2)
64 return;
66 va_start(vl, format);
67 vfprintf(stderr, format, vl);
68 va_end(vl);
71 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
74 #define MAUSEZAHN_VERSION "Mausezahn 0.40 - (C) 2007-2010 by Herbert Haas - http://www.perihel.at/sec/mz/"
75 #define MAUSEZAHN_VERSION_SHORT "0.40"
78 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 // "Dies ist ein schrecklicher Ort."
83 #define MZ_DEFAULT_CONFIG_PATH "/etc/netsniff-ng/" // see also mz_default_config_path below
84 #define MZ_DEFAULT_LOG_PATH "/var/log/mausezahn/" // see also mz_default_log_path below
86 #define SLEEP usleep // The sleep function to use. Consider 'nanosleep' in future.
87 #define DEFAULT_DELAY 0
88 #define PCAP_READ_TIMEOUT_MSEC 1 // The read timeout for pcap_open_live()
89 #define MZ_MAX_DEVICES 10 // Max number of network devices supported
90 #define MAX_PAYLOAD_SIZE 3*8192
91 #define MAX_DNS_NAME 256
92 #define MAX_8021Q_TAGS 16
93 #define TIME_COUNT_MAX 10000 // the size of the timestamp arrays timeRX and timeTX upon creation
94 #define TIME_COUNT 100 // the default used-size of the timestamp arrays timeRX and timeTX
95 #define MAX_DATA_BLOCKS 1000 // how many data blocks of size TIME_COUNT-1 should be written per file
96 #define MAXBYTES_TO_READ 1500 // how many bytes the pcap routine should read from net
97 #define RCV_RTP_MAX_BAR_WIDTH 500 // max line-width printed in BAR mode (see rcv_rtp.c)
99 #define ETH_SRC 1 // These are only some symbols used by some functions. (Don't touch)
100 #define ETH_DST 2 // These are only some symbols used by some functions.
101 #define SRC_PORT 1 // These are only some symbols used by some functions.
102 #define DST_PORT 2 // These are only some symbols used by some functions.
104 #define TEST fprintf(stderr, "HERE at line %i in file %s\n", __LINE__,__FILE__ ); fflush(stderr);
107 // ----- PCAP-specific definitions: ---------------------
108 #define IPADDRSIZE 46
111 char mz_default_config_path[256];
112 char mz_default_log_path[256];
115 struct arp_table_struct {
116 int index; // an entry index (1, 2, ...) for easier user access
117 u_int8_t sa[6]; // sent by this MAC SA
118 u_int8_t smac[6]; // announced MAC
119 u_int8_t smac_prev[6]; // previously announced MAC
120 u_int8_t sip[4]; // announced IP
121 unsigned long int uni_rq; // count unidirectional ARP requests for this IP
122 unsigned long int bc_resp; // count broadcast ARP responses for this IP
123 unsigned long int uni_resp; // count normal (unidir) ARP responses for this IP
124 unsigned long int changed; // count how often the MAC address has changed!
125 int locked; // 1=this entry cannot be overidden anymore
126 int dynamic; // 1=learned dynamically, 0=configured by user
127 int flags; // anomaly information (length anomaly: bit 0, sa!=smac: bit 1 , ...)
128 int gw; // 1=Default GW
129 char when[10]; // human readable timestamp (e. g. "11:42:53")
130 u_int32_t sec, nsec; // timestamp of last ARP response
131 u_int32_t sec_prev, nsec_prev; // timestamp of previous ARP response
132 //-----------------//
133 struct arp_table_struct *next;
136 // Device list
137 struct device_struct
139 char dev[16]; // Device name
140 int index; // Device index (assigned by OS)
141 int phy; // 1 if physical, 0 if not (e. g. loopback)
142 int mtu;
143 int cli; // if set to 1 then the CLI connection must terminate here
144 int mgmt_only; // if set to 1 then no data traffic is allowed through that interface
145 // ---- MAC addresses ----
146 u_int8_t mac[6]; // Real MAC address
147 u_int8_t mac_mops[6]; // MAC address to be used
148 // ---- IP related -----
149 char ip_str[IPADDRSIZE+1]; // Real IP address as string in dotted decimal notation
150 u_int8_t ip[4]; // Real IP address
151 u_int8_t net[4]; // Real network
152 u_int8_t mask[4]; // Real mask
153 u_int8_t ip_mops[4]; // IP address to be used
154 // ---- Default Gateway per interface:
155 u_int8_t mac_gw[6]; // MAC address of default gateway
156 u_int8_t ip_gw[4]; // IP address of default gateway
157 // ---- various device-specific handles ----
158 pthread_t arprx_thread;
159 struct pcap *p_arp; // pcap handle
160 struct arp_table_struct *arp_table; // dedicated ARP table
161 int ps; // packet socket
162 } device_list[MZ_MAX_DEVICES];
164 int device_list_entries;
167 #pragma pack(1)
168 struct struct_ethernet
170 u_int8_t eth_da[6];
171 u_int8_t eth_sa[6];
172 u_int16_t eth_type;
175 struct struct_arp
177 u_int16_t arp_hrd; // hardware address format
178 u_int16_t arp_pro; // protocol address format
179 u_int8_t arp_hln; // hardware address length
180 u_int8_t arp_pln; // protocol address length
181 u_int16_t arp_op; // ARP operation type
182 u_int8_t arp_smac[6]; // sender's hardware address
183 u_int8_t arp_sip[4]; // sender's protocol address
184 u_int8_t arp_tmac[6]; // target hardware address
185 u_int8_t arp_tip[4]; // target protocol address
190 //#pragma pack(1)
191 struct struct_ip
193 u_int8_t
194 hlen :4,
195 ver :4;
196 u_int8_t
197 tos;
198 u_int16_t
199 len;
201 u_int16_t
202 id,
203 offset; // flags and fragment offset field
205 u_int8_t
206 ttl,
207 proto;
208 u_int16_t
209 sum;
211 u_int8_t src[4];
212 u_int8_t dst[4];
215 //#pragma pack(1)
216 struct struct_udp {
217 u_int16_t
220 len,
221 sum;
224 //#pragma pack(1)
225 struct struct_rtp {
226 u_int8_t
227 byte1,
228 ptype;
229 u_int16_t
230 sqnr;
231 u_int32_t
232 timestamp, // official timestamp, created by codecs
233 ssrc;
234 // csrc, // only used by mixers
235 u_int16_t
236 ext_id,
237 ext_len;
238 u_int32_t
239 time_sec,
240 time_nsec,
241 time_sec2,
242 time_nsec2;
245 // ---------End of PCAP-specific definitions---------------
250 // ************************************
252 // Global variables
254 // ************************************
256 enum operating_modes
258 BYTE_STREAM,
259 ARP,
260 BPDU,
262 ICMP,
263 ICMP6,
264 UDP,
265 TCP,
266 DNS,
267 CDP,
268 RTP,
269 RX_RTP,
270 SYSLOG,
271 LLDP,
272 IGMP
273 } mode;
276 int ipv6_mode;
277 int quiet; // don't even print 'important standard short messages'
278 int verbose; // report character
279 int simulate; // if 1 then don't really send frames
281 char path[256];
282 char filename[256];
283 FILE *fp, *fp2; // global multipurpose file pointer
285 long double total_d;
286 clock_t mz_start, mz_stop;
288 int mz_rand;
289 int bwidth;
291 struct mz_timestamp {
292 u_int32_t sec;
293 u_int32_t nsec;
296 int32_t
297 jitter[TIME_COUNT_MAX];
299 int
300 rtp_log,
301 time0_flag, // If set then time0 has valid data
302 sqnr0_flag;
304 u_int8_t
305 mz_ssrc[4]; // holds RTP stream identifier for rcv_rtp()
307 u_int16_t
308 sqnr_cur,
309 sqnr_last,
310 sqnr_next;
312 u_int32_t
313 gind, // a global index to run through deltaRX, deltaTX, and jitter
314 gind_max; // the amount of entries used in the (ugly oversized) arrays; per default set to TIME_COUNT
316 struct tx_struct
318 // Management issues for TX
319 char device[16]; // every packet could be sent through a different device
320 int packet_mode; // 0 means use LIBNET_LINK_ADV, 1 means LIBNET_RAW4
321 unsigned int count; // 0 means infinite, 1 is default
322 unsigned int delay; // Delay in microseconds, 0 means no delay (default)
323 unsigned int prio; // Socket priority, 0 is default
324 char arg_string[MAX_PAYLOAD_SIZE]; // Argument-string when -t is used
326 // Ethernet and 802.3 parameters
327 int eth_params_already_set; // if set to 1 then send_eth should only send the frame
328 u_int8_t eth_mac_own[6]; // Contains own interface MAC if needed by some modules
329 char eth_dst_txt[32]; // Text version of eth_dst (or keyword such as 'rand')
330 u_int8_t eth_dst[6];
331 int eth_dst_rand; // 1 if random
332 char eth_src_txt[32]; // Text version of eth_src (or keyword such as 'rand')
333 u_int8_t eth_src[6];
334 int eth_src_rand; // 1 if random
335 u_int16_t eth_type;
336 u_int16_t eth_len;
337 u_int8_t eth_payload[MAX_PAYLOAD_SIZE];
338 u_int32_t eth_payload_s;
339 unsigned int padding;
341 // CDP parameters
342 u_int8_t
343 cdp_version,
344 cdp_ttl,
345 cdp_payload[MAX_PAYLOAD_SIZE],
346 cdp_tlv_id[2048]; // The ID is the only required TLV
347 u_int16_t
348 cdp_sum;
349 u_int32_t
350 cdp_tlv_id_len,
351 cdp_payload_s;
353 // 802.1Q VLAN Tag
354 int dot1Q; // 1 if specified
355 char dot1Q_txt[32]; // contains 802.1p(CoS) and VLAN-ID ("5:130" or only VLAN "130")
356 u_int8_t dot1Q_CoS;
357 u_int16_t dot1Q_vlan;
358 u_int8_t dot1Q_header[256]; // Contains the complete 802.1Q/P headers (but NOT the Ethernet header!)
359 u_int8_t dot1Q_header_s;
360 int dot1Q_at_least_two_headers; // If '1' then we have at least QinQ (or more VLAN tags)
362 // ASCII PAYLOAD
363 int ascii; // 1 if specified
364 u_int8_t ascii_payload[MAX_PAYLOAD_SIZE];
366 // HEX PAYLOAD
367 u_int8_t hex_payload[MAX_PAYLOAD_SIZE];
368 u_int32_t hex_payload_s; // >0 if hex payload is specified
370 // MPLS Parameters
371 char mpls_txt[128]; // contains MPLS parameters (label, exp, S, TTL)
372 char mpls_verbose_string[1024]; // contains all labels for print_frame_details()
373 int mpls; // 1 if specified
374 u_int32_t mpls_label;
375 u_int8_t mpls_exp;
376 u_int8_t mpls_bos;
377 u_int8_t mpls_ttl;
379 // IP parameters
380 u_int32_t ip_src; // has always network byte order(!)
381 struct libnet_in6_addr ip6_src;
382 char ip_src_txt[256];
383 int ip_src_rand; // if set to 1 then SA should be random
384 u_int32_t ip_src_h; // mirror of ip_src (NOT network byte order => easy to count)
385 u_int32_t ip_src_start; // start of range (NOT network byte order => easy to count)
386 u_int32_t ip_src_stop; // stop of range (NOT network byte order => easy to count)
387 struct libnet_in6_addr ip6_src_start; // start of IPv6 range
388 struct libnet_in6_addr ip6_src_stop; // stop of IPv6 range
389 int ip_src_isrange; // if set to 1 then the start/stop values above are valid.
390 u_int32_t ip_dst; // has always network byte order(!)
391 struct libnet_in6_addr ip6_dst;
392 char ip_dst_txt[256];
393 u_int32_t ip_dst_h; // mirror of ip_dst (NOT network byte order => easy to count)
394 u_int32_t ip_dst_start; // start of range (NOT network byte order => easy to count)
395 u_int32_t ip_dst_stop; // stop of range (NOT network byte order => easy to count)
396 struct libnet_in6_addr ip6_dst_start; // start of IPv6 range
397 struct libnet_in6_addr ip6_dst_stop; // stop of IPv6 range
398 int ip_dst_isrange; // if set to 1 then the start/stop values above are valid.
399 u_int16_t
400 ip_len,
401 ip_id,
402 ip_frag, // Flags and Offset !!!
403 ip_sum;
404 u_int8_t
405 ip_tos,
406 ip_ttl,
407 ip6_rtype,
408 ip6_segs,
409 ip_proto;
410 u_int8_t
411 ip_option[1024],
412 ip_payload[MAX_PAYLOAD_SIZE];
413 u_int32_t
414 ip_flow,
415 ip6_id,
416 ip_option_s,
417 ip_payload_s;
419 // ICMP
420 char
421 icmp_verbose_txt[256]; // used for verbose messages in send.c
422 u_int8_t
423 icmp_type,
424 icmp_code;
425 u_int16_t icmp_ident; // ATTENTION: libnet.h already #defines 'icmp_id', 'icmp_sum', and 'icmp_num'
426 u_int16_t icmp_chksum; // therefore I needed a renaming here -- be careful in future...
427 u_int16_t icmp_sqnr; //
428 u_int32_t
429 icmp_gateway,
430 icmp_payload_s;
431 u_int8_t
432 icmp_payload[MAX_PAYLOAD_SIZE];
434 // General L4 parameters:
435 char *layer4;
436 u_int16_t
437 sp, dp,
438 sp_start, sp_stop,
439 dp_start, dp_stop;
440 int
441 sp_isrange, // if set to 1 then start/stop values above are valid
442 dp_isrange; // if set to 1 then start/stop values above are valid
444 // UDP parameters
445 u_int16_t
446 udp_len, // includes header size (8 bytes)
447 udp_sum;
448 u_int8_t
449 udp_payload[MAX_PAYLOAD_SIZE];
450 u_int32_t
451 udp_payload_s;
453 // TCP parameters
454 u_int32_t
455 tcp_seq,
456 tcp_seq_start,
457 tcp_seq_stop, // is always set! Usually seq_start = seq_stop (=no range)
458 tcp_seq_delta, // Also used instead of an 'isrange' variable
459 tcp_ack;
460 u_int8_t
461 tcp_offset,
462 tcp_control;
463 u_int16_t
464 tcp_win,
465 tcp_sum,
466 tcp_urg,
467 tcp_len; // only needed by libnet and must include header size
468 u_int8_t
469 tcp_payload[MAX_PAYLOAD_SIZE];
470 u_int32_t
471 tcp_sum_part,
472 tcp_payload_s;
474 // RTP parameters
475 u_int32_t
476 rtp_sqnr,
477 rtp_stmp;
479 } tx; // NOTE: tx elements are considered as default values for MOPS
481 // ************************************
483 // Prototypes: General Tools
485 // ************************************
487 void clean_up(int sig);
488 int getopts(int argc, char *argv[]);
489 int getarg(char *str, char *arg_name, char *arg_value);
490 unsigned long int str2int(char *str); // converts "65535" to 65535
491 unsigned long long int str2lint(char *str); // same but allows 64-bit integers
492 unsigned long int xstr2int(char *str); // converts "ffff" to 65535
493 unsigned long long int xstr2lint(char *str); // same but allows 64-bit integers
494 int mz_strisbinary(char *str);
495 int mz_strisnum(char *str);
496 int mz_strishex(char *str);
497 int str2bin8 (char *str);
498 long int str2bin16 (char *str);
499 int char2bits (char c, char *str);
500 int mz_strcmp(char* usr, char* str, int min);
501 int mz_tok(char * str, char * delim, int anz, ...);
502 int delay_parse (struct timespec *t, char *a, char *b);
503 int reset(void);
505 // ************************************
507 // Prototypes: Layer1
509 // ************************************
511 int send_eth(void);
512 libnet_ptag_t create_eth_frame (libnet_t *l, libnet_ptag_t t3, libnet_ptag_t t4);
514 // ************************************
516 // Prototypes: Layer 2
518 // ************************************
520 int send_arp (void);
521 int send_bpdu (void);
522 int send_cdp (void);
524 // ************************************
526 // Prototypes: Layer 3
528 // ************************************
531 libnet_t* get_link_context(void);
532 libnet_ptag_t create_ip_packet (libnet_t *l);
533 libnet_ptag_t create_ip6_packet (libnet_t *l);
534 int send_frame (libnet_t *l, libnet_ptag_t t3, libnet_ptag_t t4);
538 // ************************************
540 // Prototypes: Layer 4
542 // ************************************
543 libnet_ptag_t create_udp_packet(libnet_t *l);
544 libnet_ptag_t create_icmp_packet(libnet_t *l);
545 libnet_ptag_t create_icmp6_packet(libnet_t *l);
546 libnet_ptag_t create_tcp_packet(libnet_t *l);
547 libnet_ptag_t create_igmp_packet(libnet_t *l);
550 // ************************************
552 // Prototypes: Layer 7
554 // ************************************
555 int create_dns_packet (void);
556 int create_rtp_packet(void);
557 int create_syslog_packet(void);
559 // ************************************
561 // Prototypes: Helper functions for
562 // byte manipulation,
563 // address conversion,
564 // etc
566 // ************************************
568 // Converts MAC address specified in str into u_int8_t array
569 // Usage: str2hex_mac ( "00:01:02:aa:ff:ee", src_addr )
570 int str2hex_mac (char* str, u_int8_t *addr);
572 // Converts ascii hex values (string) into integer array, similarly as above but for any size.
573 // Example: "1a 00:00-2f" => {26, 0, 0, 47}
574 // Note: apply any improvements here and prefer this function in future!
575 // Return value: Number of converted elements (=length of array)
576 int str2hex (char* str, u_int8_t *hp, int n);
578 // Converts ascii numbers (string) into integer array
579 // Every byte can be specified as integers {0..255}
580 // For example "192.16.1.1" will be converted to {C0, 10, 01, 01}
581 int num2hex(char* str, u_int8_t *hp);
583 // Convert array of integers into string of hex. Useful for verification messages.
584 // Example: {0,1,10} => "00-01-0A"
585 // Usage: bs2str ( src_mac, src_mac_txt, 6 )
586 int bs2str (u_int8_t *bs, char* str, int len);
588 // Extract contiguous sequence of bytes from an array. First element has index 1 !!!
589 // Usage: getbytes (bs, da, 1, 6);
590 int getbytes(u_int8_t *source, u_int8_t *target, int from, int to);
592 // For any IP address given in 'dotted decimal' returns an unsigned 32-bit integer.
593 // Example: "192.168.0.1" => 3232235521
594 // Note: Result is in LITTLE ENDIAN but usually with IP you need BIG ENDIAN, see next.
595 u_int32_t str2ip32 (char* str);
597 // For any IP address given in 'dotted decimal' into an unsigned 32-bit integer
598 // This version does the same as str2ip32() but in BIG ENDIAN.
599 // Note: With netlib you need this one, not the previous function.
600 u_int32_t str2ip32_rev (char* str);
602 // Converts a 2-byte value (e. g. a EtherType field)
603 // into a nice string using hex notation.
604 // Useful for verification messages.
605 // Example: type2str (tx.eth_type, msg) may result in msg="08:00"
606 // Return value: how many hex digits have been found.
607 int type2str(u_int16_t type, char *str);
610 // Parses string 'arg' for an IP range and finds start and stop IP addresses.
611 // Return value: 0 upon success, 1 upon failure.
613 // NOTE: The results are written in the following variables:
615 // (u_int32_t) tx.ip_dst_start ... contains start value
616 // (u_int32_t) tx.ip_dst_stop ... contains stop value
617 // int tx.ip_dst_isrange ... set to 1 if above values valid
619 // The other function does the same for the source address!
621 // Possible range specifications:
623 // 1) 192.168.0.0-192.168.0.12
624 // 2) 10.2.11.0-10.55.13.2
625 // 3) 172.18.96.0/19
627 // That is:
629 // FIRST detect a range by scanning for the "-" OR "/" chars
630 // THEN determine start and stop value and store them as normal unsigned integers
632 int get_ip_range_dst (char *arg);
633 int get_ip_range_src (char *arg);
634 int get_ip6_range_src (char *arg, libnet_t *l);
635 int get_ip6_range_dst (char *arg, libnet_t *l);
637 // Sets a random SA for a given IP packet.
638 // Return value: 0 upon success, 1 upon failure
640 int set_rand_SA (libnet_t *l, libnet_ptag_t t3);
642 // Scans tx.eth_dst_txt or tx.eth_src_txt and sets the corresponding
643 // MAC addresses (tx.eth_dst or tx.eth_src) accordingly.
644 // Argument: What string should be checked, ETH_SRC or ETH_DST.
645 // Return value:
646 // 0 when a MAC address has been set or
647 // 1 upon failure.
648 // Currently eth_src|dst_txt can be:
649 // 'rand', 'own', 'bc'|'bcast', 'stp', 'pvst',
650 // or a real mac address.
652 int check_eth_mac_txt(int src_or_dst);
654 // Scans argument for a port number or range
655 // and sets the corresponding values in the
656 // tx struct.
658 // Arguments: sp_or_dp is either SRC_PORT or DST_PORT
659 // Return value: 0 on success, 1 upon failure
661 int get_port_range (int sp_or_dp, char *arg);
663 // Return a 4-byte unsigned int random number
664 u_int32_t mz_rand32 (void);
666 // Scans argument for TCP flags and sets
667 // tx.tcp_control accordingly.
669 // Valid keywords are: fin, syn, rst, psh, ack, urg, ecn, cwr
670 // Valid delimiters are: | or + or -
671 // Return value: 0 on success, 1 upon failure
673 int get_tcp_flags (char* flags);
675 // Scans string 'params' for MPLS parameters
676 // and sets tx.mpls_* accordingly.
678 // CLI Syntax Examples:
680 // -M help .... shows syntax
682 // -M 800 .... label=800
683 // -M 800:S .... label=800 and BOS flag set
684 // -M 800:S:64 .... label=800, BOS, TTL=64
685 // -M 800:64:S .... same
686 // -M 64:77 .... label=64, TTL=77
687 // -M 64:800 .... INVALID
688 // -M 800:64 .... label=800, TTL=64
689 // -M 800:3:S:64 .... additionall the experimental bits are set (all fields required!)
691 // Note: S = BOS(1), s = NOT-BOS(0)
693 // Valid delimiters: :-.,+
694 // Return value: 0 on success, 1 upon failure
695 int get_mpls_params(char *params);
697 // Parses str for occurence of character or sequence ch.
698 // Returns number of occurences
699 int exists(char* str, char* ch);
702 // Applies another random address to a given buffer.
703 // (The calling function should check 'tx.eth_(dst|src)_rand' whether the address
704 // should be randomized.)
705 void rand_addr(u_int8_t *addr);
708 // Update timestamp and sequence number in the RTP header.
709 // The actual RTP message is stored in tx.udp_payload.
710 int update_RTP(libnet_t *l, libnet_ptag_t t);
713 // Applies another SOURCE IP address,
714 // - either a random one (tx.ip_src_rand==1)
715 // - or from a specified range (tx.ip_src_isrange==1)
716 // to a given IP-PTAG.
718 // Note: tx.ip_src MUST be already initialized with tx.ip_src_start.
719 // This is done by 'get_ip_range_src()' in tools.c.
721 // RETURNS '1' if tx.ip_src restarts
722 int update_IP_SA (libnet_t *l, libnet_ptag_t t);
723 int update_IP6_SA (libnet_t *l, libnet_ptag_t t);
726 // Applies another DESTINATION IP address from a specified range (tx.ip_dst_isrange==1)
727 // to a given IP-PTAG.
729 // Note: tx.ip_dst MUST be already initialized with tx.ip_dst_start.
730 // This is done by 'get_ip_range_dst()' in tools.c.
732 // RETURN VALUE: '1' if tx.ip_dst restarts
733 int update_IP_DA(libnet_t *l, libnet_ptag_t t);
734 int update_IP6_DA (libnet_t *l, libnet_ptag_t t);
737 // Applies another DESTINATION PORT from a specified range to a given UDP- or TCP-PTAG.
739 // Note: tx.dp MUST be already initialized with tx.dp_start
740 // This is done by 'get_port_range()' in tools.c.
742 // RETURN VALUE: '1' if tx.dp restarts
743 int update_DPORT(libnet_t *l, libnet_ptag_t t);
746 // Applies another SOURCE PORT from a specified range to a given UDP- or TCP-PTAG.
748 // Note: tx.sp MUST be already initialized with tx.sp_start
749 // This is done by 'get_port_range()' in tools.c.
751 // RETURN VALUE: '1' if tx.sp restarts
752 int update_SPORT(libnet_t *l, libnet_ptag_t t);
755 // Applies another TCP SQNR from a specified range to a given TCP-PTAG
757 // RETURN VALUE: '1' if tx.txp_seq restarts
759 int update_TCP_SQNR(libnet_t *l, libnet_ptag_t t);
761 int update_ISUM(libnet_t *l, libnet_ptag_t t);
762 int update_USUM(libnet_t *l, libnet_ptag_t t);
763 int update_TSUM(libnet_t *l, libnet_ptag_t t);
767 int print_frame_details(void);
769 int in6_addr_cmp(struct libnet_in6_addr addr1, struct libnet_in6_addr addr2);
770 int incr_in6_addr(struct libnet_in6_addr src, struct libnet_in6_addr *dst);
771 uint64_t get_ip6_range_count(struct libnet_in6_addr start, struct libnet_in6_addr stop);
773 // Calculates the number of frames to be sent.
774 // Should be used as standard output except the
775 // 'quiet' option (-q) has been specified.
776 int complexity(void);
779 // Purpose: Calculate time deltas of two timestamps stored in struct timeval.
780 // Subtract the "struct timeval" values X and Y, storing the result in RESULT.
781 // Return 1 if the difference is negative, otherwise 0.
782 int timestamp_subtract (struct mz_timestamp *x,
783 struct mz_timestamp *y,
784 struct mz_timestamp *result);
786 void timestamp_add (struct mz_timestamp *x,
787 struct mz_timestamp *y,
788 struct mz_timestamp *result);
790 // Returns a human readable timestamp in the string result.
791 // Optionally a prefix can be specified, for example if the
792 // timestamp is part of a filename.
794 // Example:
795 // char myTimeStamp[128];
797 // timestamp_human(myTimeStamp, NULL);
799 // => "20080718_155521"
801 // /* or with prefix */
803 // timestamp_human(myTimeStamp, "MZ_RTP_jitter_");
805 // => MZ_RTP_jitter_20080718_155521
807 int timestamp_human(char* result, const char* prefix);
809 // Returns a human readable timestamp in the string result.
810 // Optionally a prefix can be specified, for example if the
811 // timestamp is part of a filename.
813 // Example:
814 // char myTimeStamp[8];
816 // timestamp_hms (myTimeStamp);
818 // => "15:55:21"
819 int timestamp_hms(char* result);
821 // Initialize the rcv_rtp process: Read user parameters and initialize globals
822 int rcv_rtp_init(void);
824 // Defines the pcap handler and the callback function
825 int rcv_rtp(void);
827 // Print current RFC-Jitter on screen
828 void print_jitterbar (long int j, unsigned int d);
830 // Compares two 4-byte variables byte by byte
831 // returns 0 if identical, 1 if different
832 int compare4B (u_int8_t *ip1, u_int8_t *ip2);
834 // PURPOSE: Find usable network devices
836 // NOTE:
838 // 1. Ignores devices without IP address
839 // 2. Ignores loopback (etc)
841 // RETURN VALUES:
843 // 0 if usable device found (device_list[] and tx.device set)
844 // 1 if no usable device found
846 int lookupdev(void);
849 // For a given device name, find out the following parameters:
851 // - MTU
852 // - Network
853 // - Mask
854 // - Default GW (IP)
856 int get_dev_params (char *name);
858 // Handler function to do something when RTP messages are received
859 void got_rtp_packet(u_char *args,
860 const struct pcap_pkthdr *header, // statistics about the packet (see 'struct pcap_pkthdr')
861 const u_char *packet); // the bytestring sniffed
864 // Check if current system supports the nanosecond timer functions.
865 // Additionally, measure the precision.
866 // This function should be called upon program start.
868 int check_timer(void);
870 // This is the replacement for gettimeofday() which would result in 'jumps' if
871 // the system clock is adjusted (e. g. via a NTP process) and finally the jitter
872 // measurement would include wrong datapoints.
874 // Furthermore the function below utilizes the newer hi-res nanosecond timers.
875 void getcurtime (struct mz_timestamp *t);
877 // Only print out the help text for the 02.1Q option
878 void print_dot1Q_help(void);
880 // Determines ip and mac address of specified interface 'ifname'
881 // Caller must provide an unsigned char ip[4], mac[6]
883 int get_if_addr (char *ifname, unsigned char *ip, unsigned char *mac);
885 // Takes filename and prepends valid configuration/logging directory
886 // NOTE: filename is overwritten and must be big enough to hold full path!
887 int getfullpath_cfg (char *filename);
888 int getfullpath_log (char *filename);
890 // A safer replacement for strncpy which ensures \0-termination
891 char * mz_strncpy(char *dest, const char *src, size_t n);
893 // Helper function to count the number of arguments
894 // in the Mausezahn argument string (comma separated args)
895 // RETURN VALUE: Number of arguments
896 int number_of_args (char *str);
898 int arptable_add(struct device_struct *dev,
899 u_int8_t *sa,
900 u_int8_t *da,
901 u_int8_t *smac,
902 u_int8_t *sip,
903 u_int32_t sec,
904 u_int32_t nsec);
906 // Validate ARP requests
907 int arpwatch(struct device_struct *dev,
908 u_int8_t *sa,
909 u_int8_t *da,
910 u_int8_t *smac,
911 u_int8_t *sip,
912 u_int8_t *tmac,
913 u_int8_t *tip,
914 u_int32_t sec,
915 u_int32_t nsec);
918 #endif