docs: authors: add Doug as minor contr. (thanks)
[netsniff-ng.git] / src / mz.h
blobe64296ec5af282b122c44fb758e8a3b5f59dc46c
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 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
47 #define MAUSEZAHN_VERSION "Mausezahn 0.40 - (C) 2007-2010 by Herbert Haas - http://www.perihel.at/sec/mz/"
48 #define MAUSEZAHN_VERSION_SHORT "0.40"
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
54 // "Dies ist ein schrecklicher Ort."
56 #define MZ_DEFAULT_CONFIG_PATH "/etc/mausezahn/" // see also mz_default_config_path below
57 #define MZ_DEFAULT_LOG_PATH "/var/log/mausezahn/" // see also mz_default_log_path below
59 #define SLEEP usleep // The sleep function to use. Consider 'nanosleep' in future.
60 #define DEFAULT_DELAY 0
61 #define PCAP_READ_TIMEOUT_MSEC 1 // The read timeout for pcap_open_live()
62 #define MZ_MAX_DEVICES 10 // Max number of network devices supported
63 #define MAX_PAYLOAD_SIZE 3*8192
64 #define MAX_DNS_NAME 256
65 #define MAX_8021Q_TAGS 16
66 #define TIME_COUNT_MAX 10000 // the size of the timestamp arrays timeRX and timeTX upon creation
67 #define TIME_COUNT 100 // the default used-size of the timestamp arrays timeRX and timeTX
68 #define MAX_DATA_BLOCKS 1000 // how many data blocks of size TIME_COUNT-1 should be written per file
69 #define MAXBYTES_TO_READ 1500 // how many bytes the pcap routine should read from net
70 #define RCV_RTP_MAX_BAR_WIDTH 500 // max line-width printed in BAR mode (see rcv_rtp.c)
72 #define ETH_SRC 1 // These are only some symbols used by some functions. (Don't touch)
73 #define ETH_DST 2 // These are only some symbols used by some functions.
74 #define SRC_PORT 1 // These are only some symbols used by some functions.
75 #define DST_PORT 2 // These are only some symbols used by some functions.
77 #define TEST fprintf(stderr, "HERE at line %i in file %s\n", __LINE__,__FILE__ ); fflush(stderr);
80 // ----- PCAP-specific definitions: ---------------------
81 #define IPADDRSIZE 46
84 int MZ_SIZE_LONG_INT;
86 char mz_default_config_path[256];
87 char mz_default_log_path[256];
90 struct arp_table_struct {
91 int index; // an entry index (1, 2, ...) for easier user access
92 u_int8_t sa[6]; // sent by this MAC SA
93 u_int8_t smac[6]; // announced MAC
94 u_int8_t smac_prev[6]; // previously announced MAC
95 u_int8_t sip[4]; // announced IP
96 unsigned long int uni_rq; // count unidirectional ARP requests for this IP
97 unsigned long int bc_resp; // count broadcast ARP responses for this IP
98 unsigned long int uni_resp; // count normal (unidir) ARP responses for this IP
99 unsigned long int changed; // count how often the MAC address has changed!
100 int locked; // 1=this entry cannot be overidden anymore
101 int dynamic; // 1=learned dynamically, 0=configured by user
102 int flags; // anomaly information (length anomaly: bit 0, sa!=smac: bit 1 , ...)
103 int gw; // 1=Default GW
104 char when[10]; // human readable timestamp (e. g. "11:42:53")
105 u_int32_t sec, nsec; // timestamp of last ARP response
106 u_int32_t sec_prev, nsec_prev; // timestamp of previous ARP response
107 //-----------------//
108 struct arp_table_struct *next;
111 // Device list
112 struct device_struct
114 char dev[16]; // Device name
115 int index; // Device index (assigned by OS)
116 int phy; // 1 if physical, 0 if not (e. g. loopback)
117 int mtu;
118 int cli; // if set to 1 then the CLI connection must terminate here
119 int mgmt_only; // if set to 1 then no data traffic is allowed through that interface
120 // ---- MAC addresses ----
121 u_int8_t mac[6]; // Real MAC address
122 u_int8_t mac_mops[6]; // MAC address to be used
123 // ---- IP related -----
124 char ip_str[IPADDRSIZE+1]; // Real IP address as string in dotted decimal notation
125 u_int8_t ip[4]; // Real IP address
126 u_int8_t net[4]; // Real network
127 u_int8_t mask[4]; // Real mask
128 u_int8_t ip_mops[4]; // IP address to be used
129 // ---- Default Gateway per interface:
130 u_int8_t mac_gw[6]; // MAC address of default gateway
131 u_int8_t ip_gw[4]; // IP address of default gateway
132 // ---- various device-specific handles ----
133 pthread_t arprx_thread;
134 struct pcap *p_arp; // pcap handle
135 struct arp_table_struct *arp_table; // dedicated ARP table
136 int ps; // packet socket
137 } device_list[MZ_MAX_DEVICES];
139 int device_list_entries;
142 #pragma pack(1)
143 struct struct_ethernet
145 u_int8_t eth_da[6];
146 u_int8_t eth_sa[6];
147 u_int16_t eth_type;
150 struct struct_arp
152 u_int16_t arp_hrd; // hardware address format
153 u_int16_t arp_pro; // protocol address format
154 u_int8_t arp_hln; // hardware address length
155 u_int8_t arp_pln; // protocol address length
156 u_int16_t arp_op; // ARP operation type
157 u_int8_t arp_smac[6]; // sender's hardware address
158 u_int8_t arp_sip[4]; // sender's protocol address
159 u_int8_t arp_tmac[6]; // target hardware address
160 u_int8_t arp_tip[4]; // target protocol address
165 //#pragma pack(1)
166 struct struct_ip
168 u_int8_t
169 hlen :4,
170 ver :4;
171 u_int8_t
172 tos;
173 u_int16_t
174 len;
176 u_int16_t
177 id,
178 offset; // flags and fragment offset field
180 u_int8_t
181 ttl,
182 proto;
183 u_int16_t
184 sum;
186 u_int8_t src[4];
187 u_int8_t dst[4];
190 //#pragma pack(1)
191 struct struct_udp {
192 u_int16_t
195 len,
196 sum;
199 //#pragma pack(1)
200 struct struct_rtp {
201 u_int8_t
202 byte1,
203 ptype;
204 u_int16_t
205 sqnr;
206 u_int32_t
207 timestamp, // official timestamp, created by codecs
208 ssrc;
209 // csrc, // only used by mixers
210 u_int16_t
211 ext_id,
212 ext_len;
213 u_int32_t
214 time_sec,
215 time_nsec,
216 time_sec2,
217 time_nsec2;
220 // ---------End of PCAP-specific definitions---------------
225 // ************************************
227 // Global variables
229 // ************************************
231 enum operating_modes
233 BYTE_STREAM,
234 ARP,
235 BPDU,
236 IP,
237 ICMP,
238 ICMP6,
239 UDP,
240 TCP,
241 DNS,
242 CDP,
243 RTP,
244 RX_RTP,
245 SYSLOG,
246 LLDP
247 } mode;
250 int ipv6_mode;
251 int quiet; // don't even print 'important standard short messages'
252 int verbose; // report character
253 int simulate; // if 1 then don't really send frames
255 char path[256];
256 char filename[256];
257 FILE *fp, *fp2; // global multipurpose file pointer
259 long double total_d;
260 clock_t mz_start, mz_stop;
262 enum rtp_display_mode {
263 BAR, NCURSES, TEXT
264 } rtp_dm;
267 int mz_rand;
268 int bwidth;
270 struct mz_timestamp {
271 u_int32_t sec;
272 u_int32_t nsec;
275 struct mz_timestamp
276 tv,
277 timeTX[TIME_COUNT_MAX],
278 timeRX[TIME_COUNT_MAX];
280 int32_t
281 time0,
282 jitter_rfc,
283 jitter[TIME_COUNT_MAX];
285 int
286 rtp_log,
287 time0_flag, // If set then time0 has valid data
288 sqnr0_flag;
290 u_int8_t
291 mz_ssrc[4]; // holds RTP stream identifier for rcv_rtp()
293 u_int16_t
294 sqnr_cur,
295 sqnr_last,
296 sqnr_next;
298 u_int32_t
299 drop, // packet drop count
300 dis, // packet disorder count
301 gind, // a global index to run through deltaRX, deltaTX, and jitter
302 gind_max, // the amount of entries used in the (ugly oversized) arrays; per default set to TIME_COUNT
303 gtotal; // counts number of file write cycles (see "got_rtp_packet()")
306 char rtp_filter_str[64];
308 struct tx_struct
310 // Management issues for TX
311 char device[16]; // every packet could be sent through a different device
312 int packet_mode; // 0 means use LIBNET_LINK_ADV, 1 means LIBNET_RAW4
313 unsigned int count; // 0 means infinite, 1 is default
314 unsigned int delay; // Delay in microseconds, 0 means no delay (default)
315 char arg_string[MAX_PAYLOAD_SIZE]; // Argument-string when -t is used
317 // Ethernet and 802.3 parameters
318 int eth_params_already_set; // if set to 1 then send_eth should only send the frame
319 u_int8_t eth_mac_own[6]; // Contains own interface MAC if needed by some modules
320 char eth_dst_txt[32]; // Text version of eth_dst (or keyword such as 'rand')
321 u_int8_t eth_dst[6];
322 int eth_dst_rand; // 1 if random
323 char eth_src_txt[32]; // Text version of eth_src (or keyword such as 'rand')
324 u_int8_t eth_src[6];
325 int eth_src_rand; // 1 if random
326 u_int16_t eth_type;
327 u_int16_t eth_len;
328 u_int8_t eth_payload[MAX_PAYLOAD_SIZE];
329 u_int32_t eth_payload_s;
330 unsigned int padding;
332 // CDP parameters
333 u_int8_t
334 cdp_version,
335 cdp_ttl,
336 cdp_payload[MAX_PAYLOAD_SIZE],
337 cdp_tlv_id[2048]; // The ID is the only required TLV
338 u_int16_t
339 cdp_sum;
340 u_int32_t
341 cdp_tlv_id_len,
342 cdp_payload_s;
344 // 802.1Q VLAN Tag
345 int dot1Q; // 1 if specified
346 char dot1Q_txt[32]; // contains 802.1p(CoS) and VLAN-ID ("5:130" or only VLAN "130")
347 u_int8_t dot1Q_CoS;
348 u_int16_t dot1Q_vlan;
349 u_int8_t dot1Q_header[256]; // Contains the complete 802.1Q/P headers (but NOT the Ethernet header!)
350 u_int8_t dot1Q_header_s;
351 int dot1Q_at_least_two_headers; // If '1' then we have at least QinQ (or more VLAN tags)
353 // ASCII PAYLOAD
354 int ascii; // 1 if specified
355 u_int8_t ascii_payload[MAX_PAYLOAD_SIZE];
357 // HEX PAYLOAD
358 u_int8_t hex_payload[MAX_PAYLOAD_SIZE];
359 u_int32_t hex_payload_s; // >0 if hex payload is specified
361 // MPLS Parameters
362 char mpls_txt[128]; // contains MPLS parameters (label, exp, S, TTL)
363 char mpls_verbose_string[1024]; // contains all labels for print_frame_details()
364 int mpls; // 1 if specified
365 u_int32_t mpls_label;
366 u_int8_t mpls_exp;
367 u_int8_t mpls_bos;
368 u_int8_t mpls_ttl;
370 // IP parameters
371 u_int32_t ip_src; // has always network byte order(!)
372 struct libnet_in6_addr ip6_src;
373 char ip_src_txt[256];
374 int ip_src_rand; // if set to 1 then SA should be random
375 u_int32_t ip_src_h; // mirror of ip_src (NOT network byte order => easy to count)
376 u_int32_t ip_src_start; // start of range (NOT network byte order => easy to count)
377 u_int32_t ip_src_stop; // stop of range (NOT network byte order => easy to count)
378 int ip_src_isrange; // if set to 1 then the start/stop values above are valid.
379 u_int32_t ip_dst; // has always network byte order(!)
380 struct libnet_in6_addr ip6_dst;
381 char ip_dst_txt[256];
382 u_int32_t ip_dst_h; // mirror of ip_dst (NOT network byte order => easy to count)
383 u_int32_t ip_dst_start; // start of range (NOT network byte order => easy to count)
384 u_int32_t ip_dst_stop; // stop of range (NOT network byte order => easy to count)
385 int ip_dst_isrange; // if set to 1 then the start/stop values above are valid.
386 u_int16_t
387 ip_len,
388 ip_id,
389 ip_frag, // Flags and Offset !!!
390 ip_sum;
391 u_int8_t
392 ip_tos,
393 ip_ttl,
394 ip6_rtype,
395 ip6_segs,
396 ip_proto;
397 u_int8_t
398 ip_option[1024],
399 ip_payload[MAX_PAYLOAD_SIZE];
400 u_int32_t
401 ip_flow,
402 ip6_id,
403 ip_option_s,
404 ip_payload_s;
406 // ICMP
407 char
408 icmp_verbose_txt[256]; // used for verbose messages in send.c
409 u_int8_t
410 icmp_type,
411 icmp_code;
412 u_int16_t icmp_ident; // ATTENTION: libnet.h already #defines 'icmp_id', 'icmp_sum', and 'icmp_num'
413 u_int16_t icmp_chksum; // therefore I needed a renaming here -- be careful in future...
414 u_int16_t icmp_sqnr; //
415 u_int32_t
416 icmp_gateway,
417 icmp_payload_s;
418 u_int8_t
419 icmp_payload[MAX_PAYLOAD_SIZE];
421 // General L4 parameters:
422 char *layer4;
423 u_int16_t
424 sp, dp,
425 sp_start, sp_stop,
426 dp_start, dp_stop;
427 int
428 sp_isrange, // if set to 1 then start/stop values above are valid
429 dp_isrange; // if set to 1 then start/stop values above are valid
431 // UDP parameters
432 u_int16_t
433 udp_len, // includes header size (8 bytes)
434 udp_sum;
435 u_int8_t
436 udp_payload[MAX_PAYLOAD_SIZE];
437 u_int32_t
438 udp_payload_s;
440 // TCP parameters
441 u_int32_t
442 tcp_seq,
443 tcp_seq_start,
444 tcp_seq_stop, // is always set! Usually seq_start = seq_stop (=no range)
445 tcp_seq_delta, // Also used instead of an 'isrange' variable
446 tcp_ack;
447 u_int8_t
448 tcp_offset,
449 tcp_control;
450 u_int16_t
451 tcp_win,
452 tcp_sum,
453 tcp_urg,
454 tcp_len; // only needed by libnet and must include header size
455 u_int8_t
456 tcp_payload[MAX_PAYLOAD_SIZE];
457 u_int32_t
458 tcp_sum_part,
459 tcp_payload_s;
461 // RTP parameters
462 u_int32_t
463 rtp_sqnr,
464 rtp_stmp;
466 } tx; // NOTE: tx elements are considered as default values for MOPS
472 u_int8_t gbuf[MAX_PAYLOAD_SIZE]; // This is only a generic global buffer to handover data more easily
473 u_int32_t gbuf_s; //
476 // ************************************
478 // Prototypes: General Tools
480 // ************************************
482 void clean_up(int sig);
483 int getopts(int argc, char *argv[]);
484 int getarg(char *str, char *arg_name, char *arg_value);
485 unsigned long int str2int(char *str); // converts "65535" to 65535
486 unsigned long long int str2lint(char *str); // same but allows 64-bit integers
487 unsigned long int xstr2int(char *str); // converts "ffff" to 65535
488 unsigned long long int xstr2lint(char *str); // same but allows 64-bit integers
489 int mz_strisbinary(char *str);
490 int mz_strisnum(char *str);
491 int mz_strishex(char *str);
492 int str2bin8 (char *str);
493 long int str2bin16 (char *str);
494 int char2bits (char c, char *str);
495 int mz_strcmp(char* usr, char* str, int min);
496 int mz_tok(char * str, char * delim, int anz, ...);
497 int delay_parse (struct timespec *t, char *a, char *b);
498 int reset();
500 // ************************************
502 // Prototypes: Layer1
504 // ************************************
506 int send_eth(void);
507 libnet_ptag_t create_eth_frame (libnet_t *l, libnet_ptag_t t3, libnet_ptag_t t4);
509 // ************************************
511 // Prototypes: Layer 2
513 // ************************************
515 int send_arp (void);
516 int send_bpdu (void);
517 int send_cdp (void);
519 // ************************************
521 // Prototypes: Layer 3
523 // ************************************
526 libnet_t* get_link_context(void);
527 libnet_ptag_t create_ip_packet (libnet_t *l);
528 libnet_ptag_t create_ip6_packet (libnet_t *l);
529 int send_frame (libnet_t *l, libnet_ptag_t t3, libnet_ptag_t t4);
533 // ************************************
535 // Prototypes: Layer 4
537 // ************************************
538 libnet_ptag_t create_udp_packet (libnet_t *l);
539 libnet_ptag_t create_icmp_packet (libnet_t *l);
540 libnet_ptag_t create_icmp6_packet (libnet_t *l);
541 libnet_ptag_t create_tcp_packet (libnet_t *l);
544 // ************************************
546 // Prototypes: Layer 7
548 // ************************************
549 int create_dns_packet (void);
550 int create_rtp_packet(void);
551 int create_syslog_packet(void);
553 // ************************************
555 // Prototypes: Helper functions for
556 // byte manipulation,
557 // address conversion,
558 // etc
560 // ************************************
562 // Converts MAC address specified in str into u_int8_t array
563 // Usage: str2hex_mac ( "00:01:02:aa:ff:ee", src_addr )
564 int str2hex_mac (char* str, u_int8_t *addr);
566 // Converts ascii hex values (string) into integer array, similarly as above but for any size.
567 // Example: "1a 00:00-2f" => {26, 0, 0, 47}
568 // Note: apply any improvements here and prefer this function in future!
569 // Return value: Number of converted elements (=length of array)
570 int str2hex (char* str, u_int8_t *hp, int n);
572 // Converts ascii numbers (string) into integer array
573 // Every byte can be specified as integers {0..255}
574 // For example "192.16.1.1" will be converted to {C0, 10, 01, 01}
575 int num2hex(char* str, u_int8_t *hp);
577 // Convert array of integers into string of hex. Useful for verification messages.
578 // Example: {0,1,10} => "00-01-0A"
579 // Usage: bs2str ( src_mac, src_mac_txt, 6 )
580 int bs2str (u_int8_t *bs, char* str, int len);
582 // Extract contiguous sequence of bytes from an array. First element has index 1 !!!
583 // Usage: getbytes (bs, da, 1, 6);
584 int getbytes(u_int8_t *source, u_int8_t *target, int from, int to);
586 // For any IP address given in 'dotted decimal' returns an unsigned 32-bit integer.
587 // Example: "192.168.0.1" => 3232235521
588 // Note: Result is in LITTLE ENDIAN but usually with IP you need BIG ENDIAN, see next.
589 u_int32_t str2ip32 (char* str);
591 // For any IP address given in 'dotted decimal' into an unsigned 32-bit integer
592 // This version does the same as str2ip32() but in BIG ENDIAN.
593 // Note: With netlib you need this one, not the previous function.
594 u_int32_t str2ip32_rev (char* str);
596 // Converts a 2-byte value (e. g. a EtherType field)
597 // into a nice string using hex notation.
598 // Useful for verification messages.
599 // Example: type2str (tx.eth_type, msg) may result in msg="08:00"
600 // Return value: how many hex digits have been found.
601 int type2str(u_int16_t type, char *str);
604 // Parses string 'arg' for an IP range and finds start and stop IP addresses.
605 // Return value: 0 upon success, 1 upon failure.
607 // NOTE: The results are written in the following variables:
609 // (u_int32_t) tx.ip_dst_start ... contains start value
610 // (u_int32_t) tx.ip_dst_stop ... contains stop value
611 // int tx.ip_dst_isrange ... set to 1 if above values valid
613 // The other function does the same for the source address!
615 // Possible range specifications:
617 // 1) 192.168.0.0-192.168.0.12
618 // 2) 10.2.11.0-10.55.13.2
619 // 3) 172.18.96.0/19
621 // That is:
623 // FIRST detect a range by scanning for the "-" OR "/" chars
624 // THEN determine start and stop value and store them as normal unsigned integers
626 int get_ip_range_dst (char *arg);
627 int get_ip_range_src (char *arg);
629 // Sets a random SA for a given IP packet.
630 // Return value: 0 upon success, 1 upon failure
632 int set_rand_SA (libnet_t *l, libnet_ptag_t t3);
634 // Scans tx.eth_dst_txt or tx.eth_src_txt and sets the corresponding
635 // MAC addresses (tx.eth_dst or tx.eth_src) accordingly.
636 // Argument: What string should be checked, ETH_SRC or ETH_DST.
637 // Return value:
638 // 0 when a MAC address has been set or
639 // 1 upon failure.
640 // Currently eth_src|dst_txt can be:
641 // 'rand', 'own', 'bc'|'bcast', 'stp', 'pvst',
642 // or a real mac address.
644 int check_eth_mac_txt(int src_or_dst);
646 // Scans argument for a port number or range
647 // and sets the corresponding values in the
648 // tx struct.
650 // Arguments: sp_or_dp is either SRC_PORT or DST_PORT
651 // Return value: 0 on success, 1 upon failure
653 int get_port_range (int sp_or_dp, char *arg);
655 // Return a 4-byte unsigned int random number
656 u_int32_t mz_rand32 (void);
658 // Scans argument for TCP flags and sets
659 // tx.tcp_control accordingly.
661 // Valid keywords are: fin, syn, rst, psh, ack, urg, ecn, cwr
662 // Valid delimiters are: | or + or -
663 // Return value: 0 on success, 1 upon failure
665 int get_tcp_flags (char* flags);
667 // Scans string 'params' for MPLS parameters
668 // and sets tx.mpls_* accordingly.
670 // CLI Syntax Examples:
672 // -M help .... shows syntax
674 // -M 800 .... label=800
675 // -M 800:S .... label=800 and BOS flag set
676 // -M 800:S:64 .... label=800, BOS, TTL=64
677 // -M 800:64:S .... same
678 // -M 64:77 .... label=64, TTL=77
679 // -M 64:800 .... INVALID
680 // -M 800:64 .... label=800, TTL=64
681 // -M 800:3:S:64 .... additionall the experimental bits are set (all fields required!)
683 // Note: S = BOS(1), s = NOT-BOS(0)
685 // Valid delimiters: :-.,+
686 // Return value: 0 on success, 1 upon failure
687 int get_mpls_params(char *params);
689 // Parses str for occurence of character or sequence ch.
690 // Returns number of occurences
691 int exists(char* str, char* ch);
694 // Applies another random Ethernet source address to a given Ethernet-PTAG.
695 // (The calling function should check 'tx.eth_src_rand' whether the SA
696 // should be randomized.)
697 int update_Eth_SA(libnet_t *l, libnet_ptag_t t);
700 // Update timestamp and sequence number in the RTP header.
701 // The actual RTP message is stored in tx.udp_payload.
702 int update_RTP(libnet_t *l, libnet_ptag_t t);
705 // Applies another SOURCE IP address,
706 // - either a random one (tx.ip_src_rand==1)
707 // - or from a specified range (tx.ip_src_isrange==1)
708 // to a given IP-PTAG.
710 // Note: tx.ip_src MUST be already initialized with tx.ip_src_start.
711 // This is done by 'get_ip_range_src()' in tools.c.
713 // RETURNS '1' if tx.ip_src restarts
714 int update_IP_SA (libnet_t *l, libnet_ptag_t t);
717 // Applies another DESTINATION IP address from a specified range (tx.ip_dst_isrange==1)
718 // to a given IP-PTAG.
720 // Note: tx.ip_dst MUST be already initialized with tx.ip_dst_start.
721 // This is done by 'get_ip_range_dst()' in tools.c.
723 // RETURN VALUE: '1' if tx.ip_dst restarts
724 int update_IP_DA(libnet_t *l, libnet_ptag_t t);
727 // Applies another DESTINATION PORT from a specified range to a given UDP- or TCP-PTAG.
729 // Note: tx.dp MUST be already initialized with tx.dp_start
730 // This is done by 'get_port_range()' in tools.c.
732 // RETURN VALUE: '1' if tx.dp restarts
733 int update_DPORT(libnet_t *l, libnet_ptag_t t);
736 // Applies another SOURCE PORT from a specified range to a given UDP- or TCP-PTAG.
738 // Note: tx.sp MUST be already initialized with tx.sp_start
739 // This is done by 'get_port_range()' in tools.c.
741 // RETURN VALUE: '1' if tx.sp restarts
742 int update_SPORT(libnet_t *l, libnet_ptag_t t);
745 // Applies another TCP SQNR from a specified range to a given TCP-PTAG
747 // RETURN VALUE: '1' if tx.txp_seq restarts
749 int update_TCP_SQNR(libnet_t *l, libnet_ptag_t t);
751 int update_ISUM(libnet_t *l, libnet_ptag_t t);
752 int update_USUM(libnet_t *l, libnet_ptag_t t);
753 int update_TSUM(libnet_t *l, libnet_ptag_t t);
757 int print_frame_details(void);
760 // Calculates the number of frames to be sent.
761 // Should be used as standard output except the
762 // 'quiet' option (-q) has been specified.
763 int complexity(void);
766 // Purpose: Calculate time deltas of two timestamps stored in struct timeval.
767 // Subtract the "struct timeval" values X and Y, storing the result in RESULT.
768 // Return 1 if the difference is negative, otherwise 0.
769 int timestamp_subtract (struct mz_timestamp *x,
770 struct mz_timestamp *y,
771 struct mz_timestamp *result);
773 void timestamp_add (struct mz_timestamp *x,
774 struct mz_timestamp *y,
775 struct mz_timestamp *result);
777 // Returns a human readable timestamp in the string result.
778 // Optionally a prefix can be specified, for example if the
779 // timestamp is part of a filename.
781 // Example:
782 // char myTimeStamp[128];
784 // timestamp_human(myTimeStamp, NULL);
786 // => "20080718_155521"
788 // /* or with prefix */
790 // timestamp_human(myTimeStamp, "MZ_RTP_jitter_");
792 // => MZ_RTP_jitter_20080718_155521
794 int timestamp_human(char* result, const char* prefix);
796 // Returns a human readable timestamp in the string result.
797 // Optionally a prefix can be specified, for example if the
798 // timestamp is part of a filename.
800 // Example:
801 // char myTimeStamp[8];
803 // timestamp_hms (myTimeStamp);
805 // => "15:55:21"
806 int timestamp_hms(char* result);
808 // Initialize the rcv_rtp process: Read user parameters and initialize globals
809 int rcv_rtp_init(void);
811 // Defines the pcap handler and the callback function
812 int rcv_rtp(void);
814 // Print current RFC-Jitter on screen
815 void print_jitterbar (long int j, unsigned int d);
817 // Compares two 4-byte variables byte by byte
818 // returns 0 if identical, 1 if different
819 int compare4B (u_int8_t *ip1, u_int8_t *ip2);
821 // PURPOSE: Find usable network devices
823 // NOTE:
825 // 1. Ignores devices without IP address
826 // 2. Ignores loopback (etc)
828 // RETURN VALUES:
830 // 0 if usable device found (device_list[] and tx.device set)
831 // 1 if no usable device found
833 int lookupdev(void);
836 // For a given device name, find out the following parameters:
838 // - MTU
839 // - Network
840 // - Mask
841 // - Default GW (IP)
843 int get_dev_params (char *name);
845 // Handler function to do something when RTP messages are received
846 void got_rtp_packet(u_char *args,
847 const struct pcap_pkthdr *header, // statistics about the packet (see 'struct pcap_pkthdr')
848 const u_char *packet); // the bytestring sniffed
851 // Check if current system supports the nanosecond timer functions.
852 // Additionally, measure the precision.
853 // This function should be called upon program start.
855 int check_timer(void);
857 // This is the replacement for gettimeofday() which would result in 'jumps' if
858 // the system clock is adjusted (e. g. via a NTP process) and finally the jitter
859 // measurement would include wrong datapoints.
861 // Furthermore the function below utilizes the newer hi-res nanosecond timers.
862 void getcurtime (struct mz_timestamp *t);
864 // Only print out the help text for the 02.1Q option
865 void print_dot1Q_help(void);
867 // Determines ip and mac address of specified interface 'ifname'
868 // Caller must provide an unsigned char ip[4], mac[6]
870 int get_if_addr (char *ifname, unsigned char *ip, unsigned char *mac);
872 // Takes filename and prepends valid configuration/logging directory
873 // NOTE: filename is overwritten and must be big enough to hold full path!
874 int getfullpath_cfg (char *filename);
875 int getfullpath_log (char *filename);
877 // A safer replacement for strncpy which ensures \0-termination
878 char * mz_strncpy(char *dest, const char *src, size_t n);
880 // Helper function to count the number of arguments
881 // in the Mausezahn argument string (comma separated args)
882 // RETURN VALUE: Number of arguments
883 int number_of_args (char *str);
885 int arptable_add(struct device_struct *dev,
886 u_int8_t *sa,
887 u_int8_t *da,
888 u_int8_t *smac,
889 u_int8_t *sip,
890 u_int32_t sec,
891 u_int32_t nsec);
893 // Validate ARP requests
894 int arpwatch(struct device_struct *dev,
895 u_int8_t *sa,
896 u_int8_t *da,
897 u_int8_t *smac,
898 u_int8_t *sip,
899 u_int8_t *tmac,
900 u_int8_t *tip,
901 u_int32_t sec,
902 u_int32_t nsec);
905 #endif