ifpps: Optionally display median values for CPU load and interrupts
[netsniff-ng.git] / staging / mz.h
blobcad091f43205bf538111440fc40ea8006f517dcd
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>
44 extern int verbose_level;
46 static inline void verbose_l1(const char *format, ...)
48 va_list vl;
50 if (verbose_level < 1)
51 return;
53 va_start(vl, format);
54 vfprintf(stderr, format, vl);
55 va_end(vl);
58 static inline void verbose_l2(const char *format, ...)
60 va_list vl;
62 if (verbose_level < 2)
63 return;
65 va_start(vl, format);
66 vfprintf(stderr, format, vl);
67 va_end(vl);
70 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 #define MAUSEZAHN_VERSION "Mausezahn 0.40 - (C) 2007-2010 by Herbert Haas - http://www.perihel.at/sec/mz/"
74 #define MAUSEZAHN_VERSION_SHORT "0.40"
77 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
80 // "Dies ist ein schrecklicher Ort."
82 #define MZ_DEFAULT_CONFIG_PATH "/etc/mausezahn/" // see also mz_default_config_path below
83 #define MZ_DEFAULT_LOG_PATH "/var/log/mausezahn/" // see also mz_default_log_path below
85 #define SLEEP usleep // The sleep function to use. Consider 'nanosleep' in future.
86 #define DEFAULT_DELAY 0
87 #define PCAP_READ_TIMEOUT_MSEC 1 // The read timeout for pcap_open_live()
88 #define MZ_MAX_DEVICES 10 // Max number of network devices supported
89 #define MAX_PAYLOAD_SIZE 3*8192
90 #define MAX_DNS_NAME 256
91 #define MAX_8021Q_TAGS 16
92 #define TIME_COUNT_MAX 10000 // the size of the timestamp arrays timeRX and timeTX upon creation
93 #define TIME_COUNT 100 // the default used-size of the timestamp arrays timeRX and timeTX
94 #define MAX_DATA_BLOCKS 1000 // how many data blocks of size TIME_COUNT-1 should be written per file
95 #define MAXBYTES_TO_READ 1500 // how many bytes the pcap routine should read from net
96 #define RCV_RTP_MAX_BAR_WIDTH 500 // max line-width printed in BAR mode (see rcv_rtp.c)
98 #define ETH_SRC 1 // These are only some symbols used by some functions. (Don't touch)
99 #define ETH_DST 2 // These are only some symbols used by some functions.
100 #define SRC_PORT 1 // These are only some symbols used by some functions.
101 #define DST_PORT 2 // These are only some symbols used by some functions.
103 #define TEST fprintf(stderr, "HERE at line %i in file %s\n", __LINE__,__FILE__ ); fflush(stderr);
106 // ----- PCAP-specific definitions: ---------------------
107 #define IPADDRSIZE 46
110 int MZ_SIZE_LONG_INT;
112 char mz_default_config_path[256];
113 char mz_default_log_path[256];
116 struct arp_table_struct {
117 int index; // an entry index (1, 2, ...) for easier user access
118 u_int8_t sa[6]; // sent by this MAC SA
119 u_int8_t smac[6]; // announced MAC
120 u_int8_t smac_prev[6]; // previously announced MAC
121 u_int8_t sip[4]; // announced IP
122 unsigned long int uni_rq; // count unidirectional ARP requests for this IP
123 unsigned long int bc_resp; // count broadcast ARP responses for this IP
124 unsigned long int uni_resp; // count normal (unidir) ARP responses for this IP
125 unsigned long int changed; // count how often the MAC address has changed!
126 int locked; // 1=this entry cannot be overidden anymore
127 int dynamic; // 1=learned dynamically, 0=configured by user
128 int flags; // anomaly information (length anomaly: bit 0, sa!=smac: bit 1 , ...)
129 int gw; // 1=Default GW
130 char when[10]; // human readable timestamp (e. g. "11:42:53")
131 u_int32_t sec, nsec; // timestamp of last ARP response
132 u_int32_t sec_prev, nsec_prev; // timestamp of previous ARP response
133 //-----------------//
134 struct arp_table_struct *next;
137 // Device list
138 struct device_struct
140 char dev[16]; // Device name
141 int index; // Device index (assigned by OS)
142 int phy; // 1 if physical, 0 if not (e. g. loopback)
143 int mtu;
144 int cli; // if set to 1 then the CLI connection must terminate here
145 int mgmt_only; // if set to 1 then no data traffic is allowed through that interface
146 // ---- MAC addresses ----
147 u_int8_t mac[6]; // Real MAC address
148 u_int8_t mac_mops[6]; // MAC address to be used
149 // ---- IP related -----
150 char ip_str[IPADDRSIZE+1]; // Real IP address as string in dotted decimal notation
151 u_int8_t ip[4]; // Real IP address
152 u_int8_t net[4]; // Real network
153 u_int8_t mask[4]; // Real mask
154 u_int8_t ip_mops[4]; // IP address to be used
155 // ---- Default Gateway per interface:
156 u_int8_t mac_gw[6]; // MAC address of default gateway
157 u_int8_t ip_gw[4]; // IP address of default gateway
158 // ---- various device-specific handles ----
159 pthread_t arprx_thread;
160 struct pcap *p_arp; // pcap handle
161 struct arp_table_struct *arp_table; // dedicated ARP table
162 int ps; // packet socket
163 } device_list[MZ_MAX_DEVICES];
165 int device_list_entries;
168 #pragma pack(1)
169 struct struct_ethernet
171 u_int8_t eth_da[6];
172 u_int8_t eth_sa[6];
173 u_int16_t eth_type;
176 struct struct_arp
178 u_int16_t arp_hrd; // hardware address format
179 u_int16_t arp_pro; // protocol address format
180 u_int8_t arp_hln; // hardware address length
181 u_int8_t arp_pln; // protocol address length
182 u_int16_t arp_op; // ARP operation type
183 u_int8_t arp_smac[6]; // sender's hardware address
184 u_int8_t arp_sip[4]; // sender's protocol address
185 u_int8_t arp_tmac[6]; // target hardware address
186 u_int8_t arp_tip[4]; // target protocol address
191 //#pragma pack(1)
192 struct struct_ip
194 u_int8_t
195 hlen :4,
196 ver :4;
197 u_int8_t
198 tos;
199 u_int16_t
200 len;
202 u_int16_t
203 id,
204 offset; // flags and fragment offset field
206 u_int8_t
207 ttl,
208 proto;
209 u_int16_t
210 sum;
212 u_int8_t src[4];
213 u_int8_t dst[4];
216 //#pragma pack(1)
217 struct struct_udp {
218 u_int16_t
221 len,
222 sum;
225 //#pragma pack(1)
226 struct struct_rtp {
227 u_int8_t
228 byte1,
229 ptype;
230 u_int16_t
231 sqnr;
232 u_int32_t
233 timestamp, // official timestamp, created by codecs
234 ssrc;
235 // csrc, // only used by mixers
236 u_int16_t
237 ext_id,
238 ext_len;
239 u_int32_t
240 time_sec,
241 time_nsec,
242 time_sec2,
243 time_nsec2;
246 // ---------End of PCAP-specific definitions---------------
251 // ************************************
253 // Global variables
255 // ************************************
257 enum operating_modes
259 BYTE_STREAM,
260 ARP,
261 BPDU,
262 IP,
263 ICMP,
264 ICMP6,
265 UDP,
266 TCP,
267 DNS,
268 CDP,
269 RTP,
270 RX_RTP,
271 SYSLOG,
272 LLDP
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 enum rtp_display_mode {
289 BAR, NCURSES, TEXT
290 } rtp_dm;
293 int mz_rand;
294 int bwidth;
296 struct mz_timestamp {
297 u_int32_t sec;
298 u_int32_t nsec;
301 struct mz_timestamp
302 tv,
303 timeTX[TIME_COUNT_MAX],
304 timeRX[TIME_COUNT_MAX];
306 int32_t
307 time0,
308 jitter_rfc,
309 jitter[TIME_COUNT_MAX];
311 int
312 rtp_log,
313 time0_flag, // If set then time0 has valid data
314 sqnr0_flag;
316 u_int8_t
317 mz_ssrc[4]; // holds RTP stream identifier for rcv_rtp()
319 u_int16_t
320 sqnr_cur,
321 sqnr_last,
322 sqnr_next;
324 u_int32_t
325 drop, // packet drop count
326 dis, // packet disorder count
327 gind, // a global index to run through deltaRX, deltaTX, and jitter
328 gind_max, // the amount of entries used in the (ugly oversized) arrays; per default set to TIME_COUNT
329 gtotal; // counts number of file write cycles (see "got_rtp_packet()")
332 char rtp_filter_str[64];
334 struct tx_struct
336 // Management issues for TX
337 char device[16]; // every packet could be sent through a different device
338 int packet_mode; // 0 means use LIBNET_LINK_ADV, 1 means LIBNET_RAW4
339 unsigned int count; // 0 means infinite, 1 is default
340 unsigned int delay; // Delay in microseconds, 0 means no delay (default)
341 char arg_string[MAX_PAYLOAD_SIZE]; // Argument-string when -t is used
343 // Ethernet and 802.3 parameters
344 int eth_params_already_set; // if set to 1 then send_eth should only send the frame
345 u_int8_t eth_mac_own[6]; // Contains own interface MAC if needed by some modules
346 char eth_dst_txt[32]; // Text version of eth_dst (or keyword such as 'rand')
347 u_int8_t eth_dst[6];
348 int eth_dst_rand; // 1 if random
349 char eth_src_txt[32]; // Text version of eth_src (or keyword such as 'rand')
350 u_int8_t eth_src[6];
351 int eth_src_rand; // 1 if random
352 u_int16_t eth_type;
353 u_int16_t eth_len;
354 u_int8_t eth_payload[MAX_PAYLOAD_SIZE];
355 u_int32_t eth_payload_s;
356 unsigned int padding;
358 // CDP parameters
359 u_int8_t
360 cdp_version,
361 cdp_ttl,
362 cdp_payload[MAX_PAYLOAD_SIZE],
363 cdp_tlv_id[2048]; // The ID is the only required TLV
364 u_int16_t
365 cdp_sum;
366 u_int32_t
367 cdp_tlv_id_len,
368 cdp_payload_s;
370 // 802.1Q VLAN Tag
371 int dot1Q; // 1 if specified
372 char dot1Q_txt[32]; // contains 802.1p(CoS) and VLAN-ID ("5:130" or only VLAN "130")
373 u_int8_t dot1Q_CoS;
374 u_int16_t dot1Q_vlan;
375 u_int8_t dot1Q_header[256]; // Contains the complete 802.1Q/P headers (but NOT the Ethernet header!)
376 u_int8_t dot1Q_header_s;
377 int dot1Q_at_least_two_headers; // If '1' then we have at least QinQ (or more VLAN tags)
379 // ASCII PAYLOAD
380 int ascii; // 1 if specified
381 u_int8_t ascii_payload[MAX_PAYLOAD_SIZE];
383 // HEX PAYLOAD
384 u_int8_t hex_payload[MAX_PAYLOAD_SIZE];
385 u_int32_t hex_payload_s; // >0 if hex payload is specified
387 // MPLS Parameters
388 char mpls_txt[128]; // contains MPLS parameters (label, exp, S, TTL)
389 char mpls_verbose_string[1024]; // contains all labels for print_frame_details()
390 int mpls; // 1 if specified
391 u_int32_t mpls_label;
392 u_int8_t mpls_exp;
393 u_int8_t mpls_bos;
394 u_int8_t mpls_ttl;
396 // IP parameters
397 u_int32_t ip_src; // has always network byte order(!)
398 struct libnet_in6_addr ip6_src;
399 char ip_src_txt[256];
400 int ip_src_rand; // if set to 1 then SA should be random
401 u_int32_t ip_src_h; // mirror of ip_src (NOT network byte order => easy to count)
402 u_int32_t ip_src_start; // start of range (NOT network byte order => easy to count)
403 u_int32_t ip_src_stop; // stop of range (NOT network byte order => easy to count)
404 int ip_src_isrange; // if set to 1 then the start/stop values above are valid.
405 u_int32_t ip_dst; // has always network byte order(!)
406 struct libnet_in6_addr ip6_dst;
407 char ip_dst_txt[256];
408 u_int32_t ip_dst_h; // mirror of ip_dst (NOT network byte order => easy to count)
409 u_int32_t ip_dst_start; // start of range (NOT network byte order => easy to count)
410 u_int32_t ip_dst_stop; // stop of range (NOT network byte order => easy to count)
411 int ip_dst_isrange; // if set to 1 then the start/stop values above are valid.
412 u_int16_t
413 ip_len,
414 ip_id,
415 ip_frag, // Flags and Offset !!!
416 ip_sum;
417 u_int8_t
418 ip_tos,
419 ip_ttl,
420 ip6_rtype,
421 ip6_segs,
422 ip_proto;
423 u_int8_t
424 ip_option[1024],
425 ip_payload[MAX_PAYLOAD_SIZE];
426 u_int32_t
427 ip_flow,
428 ip6_id,
429 ip_option_s,
430 ip_payload_s;
432 // ICMP
433 char
434 icmp_verbose_txt[256]; // used for verbose messages in send.c
435 u_int8_t
436 icmp_type,
437 icmp_code;
438 u_int16_t icmp_ident; // ATTENTION: libnet.h already #defines 'icmp_id', 'icmp_sum', and 'icmp_num'
439 u_int16_t icmp_chksum; // therefore I needed a renaming here -- be careful in future...
440 u_int16_t icmp_sqnr; //
441 u_int32_t
442 icmp_gateway,
443 icmp_payload_s;
444 u_int8_t
445 icmp_payload[MAX_PAYLOAD_SIZE];
447 // General L4 parameters:
448 char *layer4;
449 u_int16_t
450 sp, dp,
451 sp_start, sp_stop,
452 dp_start, dp_stop;
453 int
454 sp_isrange, // if set to 1 then start/stop values above are valid
455 dp_isrange; // if set to 1 then start/stop values above are valid
457 // UDP parameters
458 u_int16_t
459 udp_len, // includes header size (8 bytes)
460 udp_sum;
461 u_int8_t
462 udp_payload[MAX_PAYLOAD_SIZE];
463 u_int32_t
464 udp_payload_s;
466 // TCP parameters
467 u_int32_t
468 tcp_seq,
469 tcp_seq_start,
470 tcp_seq_stop, // is always set! Usually seq_start = seq_stop (=no range)
471 tcp_seq_delta, // Also used instead of an 'isrange' variable
472 tcp_ack;
473 u_int8_t
474 tcp_offset,
475 tcp_control;
476 u_int16_t
477 tcp_win,
478 tcp_sum,
479 tcp_urg,
480 tcp_len; // only needed by libnet and must include header size
481 u_int8_t
482 tcp_payload[MAX_PAYLOAD_SIZE];
483 u_int32_t
484 tcp_sum_part,
485 tcp_payload_s;
487 // RTP parameters
488 u_int32_t
489 rtp_sqnr,
490 rtp_stmp;
492 } tx; // NOTE: tx elements are considered as default values for MOPS
498 u_int8_t gbuf[MAX_PAYLOAD_SIZE]; // This is only a generic global buffer to handover data more easily
499 u_int32_t gbuf_s; //
502 // ************************************
504 // Prototypes: General Tools
506 // ************************************
508 void clean_up(int sig);
509 int getopts(int argc, char *argv[]);
510 int getarg(char *str, char *arg_name, char *arg_value);
511 unsigned long int str2int(char *str); // converts "65535" to 65535
512 unsigned long long int str2lint(char *str); // same but allows 64-bit integers
513 unsigned long int xstr2int(char *str); // converts "ffff" to 65535
514 unsigned long long int xstr2lint(char *str); // same but allows 64-bit integers
515 int mz_strisbinary(char *str);
516 int mz_strisnum(char *str);
517 int mz_strishex(char *str);
518 int str2bin8 (char *str);
519 long int str2bin16 (char *str);
520 int char2bits (char c, char *str);
521 int mz_strcmp(char* usr, char* str, int min);
522 int mz_tok(char * str, char * delim, int anz, ...);
523 int delay_parse (struct timespec *t, char *a, char *b);
524 int reset();
526 // ************************************
528 // Prototypes: Layer1
530 // ************************************
532 int send_eth(void);
533 libnet_ptag_t create_eth_frame (libnet_t *l, libnet_ptag_t t3, libnet_ptag_t t4);
535 // ************************************
537 // Prototypes: Layer 2
539 // ************************************
541 int send_arp (void);
542 int send_bpdu (void);
543 int send_cdp (void);
545 // ************************************
547 // Prototypes: Layer 3
549 // ************************************
552 libnet_t* get_link_context(void);
553 libnet_ptag_t create_ip_packet (libnet_t *l);
554 libnet_ptag_t create_ip6_packet (libnet_t *l);
555 int send_frame (libnet_t *l, libnet_ptag_t t3, libnet_ptag_t t4);
559 // ************************************
561 // Prototypes: Layer 4
563 // ************************************
564 libnet_ptag_t create_udp_packet (libnet_t *l);
565 libnet_ptag_t create_icmp_packet (libnet_t *l);
566 libnet_ptag_t create_icmp6_packet (libnet_t *l);
567 libnet_ptag_t create_tcp_packet (libnet_t *l);
570 // ************************************
572 // Prototypes: Layer 7
574 // ************************************
575 int create_dns_packet (void);
576 int create_rtp_packet(void);
577 int create_syslog_packet(void);
579 // ************************************
581 // Prototypes: Helper functions for
582 // byte manipulation,
583 // address conversion,
584 // etc
586 // ************************************
588 // Converts MAC address specified in str into u_int8_t array
589 // Usage: str2hex_mac ( "00:01:02:aa:ff:ee", src_addr )
590 int str2hex_mac (char* str, u_int8_t *addr);
592 // Converts ascii hex values (string) into integer array, similarly as above but for any size.
593 // Example: "1a 00:00-2f" => {26, 0, 0, 47}
594 // Note: apply any improvements here and prefer this function in future!
595 // Return value: Number of converted elements (=length of array)
596 int str2hex (char* str, u_int8_t *hp, int n);
598 // Converts ascii numbers (string) into integer array
599 // Every byte can be specified as integers {0..255}
600 // For example "192.16.1.1" will be converted to {C0, 10, 01, 01}
601 int num2hex(char* str, u_int8_t *hp);
603 // Convert array of integers into string of hex. Useful for verification messages.
604 // Example: {0,1,10} => "00-01-0A"
605 // Usage: bs2str ( src_mac, src_mac_txt, 6 )
606 int bs2str (u_int8_t *bs, char* str, int len);
608 // Extract contiguous sequence of bytes from an array. First element has index 1 !!!
609 // Usage: getbytes (bs, da, 1, 6);
610 int getbytes(u_int8_t *source, u_int8_t *target, int from, int to);
612 // For any IP address given in 'dotted decimal' returns an unsigned 32-bit integer.
613 // Example: "192.168.0.1" => 3232235521
614 // Note: Result is in LITTLE ENDIAN but usually with IP you need BIG ENDIAN, see next.
615 u_int32_t str2ip32 (char* str);
617 // For any IP address given in 'dotted decimal' into an unsigned 32-bit integer
618 // This version does the same as str2ip32() but in BIG ENDIAN.
619 // Note: With netlib you need this one, not the previous function.
620 u_int32_t str2ip32_rev (char* str);
622 // Converts a 2-byte value (e. g. a EtherType field)
623 // into a nice string using hex notation.
624 // Useful for verification messages.
625 // Example: type2str (tx.eth_type, msg) may result in msg="08:00"
626 // Return value: how many hex digits have been found.
627 int type2str(u_int16_t type, char *str);
630 // Parses string 'arg' for an IP range and finds start and stop IP addresses.
631 // Return value: 0 upon success, 1 upon failure.
633 // NOTE: The results are written in the following variables:
635 // (u_int32_t) tx.ip_dst_start ... contains start value
636 // (u_int32_t) tx.ip_dst_stop ... contains stop value
637 // int tx.ip_dst_isrange ... set to 1 if above values valid
639 // The other function does the same for the source address!
641 // Possible range specifications:
643 // 1) 192.168.0.0-192.168.0.12
644 // 2) 10.2.11.0-10.55.13.2
645 // 3) 172.18.96.0/19
647 // That is:
649 // FIRST detect a range by scanning for the "-" OR "/" chars
650 // THEN determine start and stop value and store them as normal unsigned integers
652 int get_ip_range_dst (char *arg);
653 int get_ip_range_src (char *arg);
655 // Sets a random SA for a given IP packet.
656 // Return value: 0 upon success, 1 upon failure
658 int set_rand_SA (libnet_t *l, libnet_ptag_t t3);
660 // Scans tx.eth_dst_txt or tx.eth_src_txt and sets the corresponding
661 // MAC addresses (tx.eth_dst or tx.eth_src) accordingly.
662 // Argument: What string should be checked, ETH_SRC or ETH_DST.
663 // Return value:
664 // 0 when a MAC address has been set or
665 // 1 upon failure.
666 // Currently eth_src|dst_txt can be:
667 // 'rand', 'own', 'bc'|'bcast', 'stp', 'pvst',
668 // or a real mac address.
670 int check_eth_mac_txt(int src_or_dst);
672 // Scans argument for a port number or range
673 // and sets the corresponding values in the
674 // tx struct.
676 // Arguments: sp_or_dp is either SRC_PORT or DST_PORT
677 // Return value: 0 on success, 1 upon failure
679 int get_port_range (int sp_or_dp, char *arg);
681 // Return a 4-byte unsigned int random number
682 u_int32_t mz_rand32 (void);
684 // Scans argument for TCP flags and sets
685 // tx.tcp_control accordingly.
687 // Valid keywords are: fin, syn, rst, psh, ack, urg, ecn, cwr
688 // Valid delimiters are: | or + or -
689 // Return value: 0 on success, 1 upon failure
691 int get_tcp_flags (char* flags);
693 // Scans string 'params' for MPLS parameters
694 // and sets tx.mpls_* accordingly.
696 // CLI Syntax Examples:
698 // -M help .... shows syntax
700 // -M 800 .... label=800
701 // -M 800:S .... label=800 and BOS flag set
702 // -M 800:S:64 .... label=800, BOS, TTL=64
703 // -M 800:64:S .... same
704 // -M 64:77 .... label=64, TTL=77
705 // -M 64:800 .... INVALID
706 // -M 800:64 .... label=800, TTL=64
707 // -M 800:3:S:64 .... additionall the experimental bits are set (all fields required!)
709 // Note: S = BOS(1), s = NOT-BOS(0)
711 // Valid delimiters: :-.,+
712 // Return value: 0 on success, 1 upon failure
713 int get_mpls_params(char *params);
715 // Parses str for occurence of character or sequence ch.
716 // Returns number of occurences
717 int exists(char* str, char* ch);
720 // Applies another random Ethernet source address to a given Ethernet-PTAG.
721 // (The calling function should check 'tx.eth_src_rand' whether the SA
722 // should be randomized.)
723 int update_Eth_SA(libnet_t *l, libnet_ptag_t t);
726 // Update timestamp and sequence number in the RTP header.
727 // The actual RTP message is stored in tx.udp_payload.
728 int update_RTP(libnet_t *l, libnet_ptag_t t);
731 // Applies another SOURCE IP address,
732 // - either a random one (tx.ip_src_rand==1)
733 // - or from a specified range (tx.ip_src_isrange==1)
734 // to a given IP-PTAG.
736 // Note: tx.ip_src MUST be already initialized with tx.ip_src_start.
737 // This is done by 'get_ip_range_src()' in tools.c.
739 // RETURNS '1' if tx.ip_src restarts
740 int update_IP_SA (libnet_t *l, libnet_ptag_t t);
743 // Applies another DESTINATION IP address from a specified range (tx.ip_dst_isrange==1)
744 // to a given IP-PTAG.
746 // Note: tx.ip_dst MUST be already initialized with tx.ip_dst_start.
747 // This is done by 'get_ip_range_dst()' in tools.c.
749 // RETURN VALUE: '1' if tx.ip_dst restarts
750 int update_IP_DA(libnet_t *l, libnet_ptag_t t);
753 // Applies another DESTINATION PORT from a specified range to a given UDP- or TCP-PTAG.
755 // Note: tx.dp MUST be already initialized with tx.dp_start
756 // This is done by 'get_port_range()' in tools.c.
758 // RETURN VALUE: '1' if tx.dp restarts
759 int update_DPORT(libnet_t *l, libnet_ptag_t t);
762 // Applies another SOURCE PORT from a specified range to a given UDP- or TCP-PTAG.
764 // Note: tx.sp MUST be already initialized with tx.sp_start
765 // This is done by 'get_port_range()' in tools.c.
767 // RETURN VALUE: '1' if tx.sp restarts
768 int update_SPORT(libnet_t *l, libnet_ptag_t t);
771 // Applies another TCP SQNR from a specified range to a given TCP-PTAG
773 // RETURN VALUE: '1' if tx.txp_seq restarts
775 int update_TCP_SQNR(libnet_t *l, libnet_ptag_t t);
777 int update_ISUM(libnet_t *l, libnet_ptag_t t);
778 int update_USUM(libnet_t *l, libnet_ptag_t t);
779 int update_TSUM(libnet_t *l, libnet_ptag_t t);
783 int print_frame_details(void);
786 // Calculates the number of frames to be sent.
787 // Should be used as standard output except the
788 // 'quiet' option (-q) has been specified.
789 int complexity(void);
792 // Purpose: Calculate time deltas of two timestamps stored in struct timeval.
793 // Subtract the "struct timeval" values X and Y, storing the result in RESULT.
794 // Return 1 if the difference is negative, otherwise 0.
795 int timestamp_subtract (struct mz_timestamp *x,
796 struct mz_timestamp *y,
797 struct mz_timestamp *result);
799 void timestamp_add (struct mz_timestamp *x,
800 struct mz_timestamp *y,
801 struct mz_timestamp *result);
803 // Returns a human readable timestamp in the string result.
804 // Optionally a prefix can be specified, for example if the
805 // timestamp is part of a filename.
807 // Example:
808 // char myTimeStamp[128];
810 // timestamp_human(myTimeStamp, NULL);
812 // => "20080718_155521"
814 // /* or with prefix */
816 // timestamp_human(myTimeStamp, "MZ_RTP_jitter_");
818 // => MZ_RTP_jitter_20080718_155521
820 int timestamp_human(char* result, const char* prefix);
822 // Returns a human readable timestamp in the string result.
823 // Optionally a prefix can be specified, for example if the
824 // timestamp is part of a filename.
826 // Example:
827 // char myTimeStamp[8];
829 // timestamp_hms (myTimeStamp);
831 // => "15:55:21"
832 int timestamp_hms(char* result);
834 // Initialize the rcv_rtp process: Read user parameters and initialize globals
835 int rcv_rtp_init(void);
837 // Defines the pcap handler and the callback function
838 int rcv_rtp(void);
840 // Print current RFC-Jitter on screen
841 void print_jitterbar (long int j, unsigned int d);
843 // Compares two 4-byte variables byte by byte
844 // returns 0 if identical, 1 if different
845 int compare4B (u_int8_t *ip1, u_int8_t *ip2);
847 // PURPOSE: Find usable network devices
849 // NOTE:
851 // 1. Ignores devices without IP address
852 // 2. Ignores loopback (etc)
854 // RETURN VALUES:
856 // 0 if usable device found (device_list[] and tx.device set)
857 // 1 if no usable device found
859 int lookupdev(void);
862 // For a given device name, find out the following parameters:
864 // - MTU
865 // - Network
866 // - Mask
867 // - Default GW (IP)
869 int get_dev_params (char *name);
871 // Handler function to do something when RTP messages are received
872 void got_rtp_packet(u_char *args,
873 const struct pcap_pkthdr *header, // statistics about the packet (see 'struct pcap_pkthdr')
874 const u_char *packet); // the bytestring sniffed
877 // Check if current system supports the nanosecond timer functions.
878 // Additionally, measure the precision.
879 // This function should be called upon program start.
881 int check_timer(void);
883 // This is the replacement for gettimeofday() which would result in 'jumps' if
884 // the system clock is adjusted (e. g. via a NTP process) and finally the jitter
885 // measurement would include wrong datapoints.
887 // Furthermore the function below utilizes the newer hi-res nanosecond timers.
888 void getcurtime (struct mz_timestamp *t);
890 // Only print out the help text for the 02.1Q option
891 void print_dot1Q_help(void);
893 // Determines ip and mac address of specified interface 'ifname'
894 // Caller must provide an unsigned char ip[4], mac[6]
896 int get_if_addr (char *ifname, unsigned char *ip, unsigned char *mac);
898 // Takes filename and prepends valid configuration/logging directory
899 // NOTE: filename is overwritten and must be big enough to hold full path!
900 int getfullpath_cfg (char *filename);
901 int getfullpath_log (char *filename);
903 // A safer replacement for strncpy which ensures \0-termination
904 char * mz_strncpy(char *dest, const char *src, size_t n);
906 // Helper function to count the number of arguments
907 // in the Mausezahn argument string (comma separated args)
908 // RETURN VALUE: Number of arguments
909 int number_of_args (char *str);
911 int arptable_add(struct device_struct *dev,
912 u_int8_t *sa,
913 u_int8_t *da,
914 u_int8_t *smac,
915 u_int8_t *sip,
916 u_int32_t sec,
917 u_int32_t nsec);
919 // Validate ARP requests
920 int arpwatch(struct device_struct *dev,
921 u_int8_t *sa,
922 u_int8_t *da,
923 u_int8_t *smac,
924 u_int8_t *sip,
925 u_int8_t *tmac,
926 u_int8_t *tip,
927 u_int32_t sec,
928 u_int32_t nsec);
931 #endif