2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 Herbert Haas
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.
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
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
26 #include <pcap/pcap.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>
44 extern int verbose_level
;
46 static inline void verbose_l1(const char *format
, ...)
50 if (verbose_level
< 1)
54 vfprintf(stderr
, format
, vl
);
58 static inline void verbose_l2(const char *format
, ...)
62 if (verbose_level
< 2)
66 vfprintf(stderr
, format
, 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/netsniff-ng/" // 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
;
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)
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
;
169 struct struct_ethernet
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
204 offset
; // flags and fragment offset field
233 timestamp
, // official timestamp, created by codecs
235 // csrc, // only used by mixers
246 // ---------End of PCAP-specific definitions---------------
251 // ************************************
255 // ************************************
278 int quiet
; // don't even print 'important standard short messages'
279 int verbose
; // report character
280 int simulate
; // if 1 then don't really send frames
284 FILE *fp
, *fp2
; // global multipurpose file pointer
287 clock_t mz_start
, mz_stop
;
289 enum rtp_display_mode
{
297 struct mz_timestamp
{
304 timeTX
[TIME_COUNT_MAX
],
305 timeRX
[TIME_COUNT_MAX
];
310 jitter
[TIME_COUNT_MAX
];
314 time0_flag
, // If set then time0 has valid data
318 mz_ssrc
[4]; // holds RTP stream identifier for rcv_rtp()
326 drop
, // packet drop count
327 dis
, // packet disorder count
328 gind
, // a global index to run through deltaRX, deltaTX, and jitter
329 gind_max
, // the amount of entries used in the (ugly oversized) arrays; per default set to TIME_COUNT
330 gtotal
; // counts number of file write cycles (see "got_rtp_packet()")
333 char rtp_filter_str
[64];
337 // Management issues for TX
338 char device
[16]; // every packet could be sent through a different device
339 int packet_mode
; // 0 means use LIBNET_LINK_ADV, 1 means LIBNET_RAW4
340 unsigned int count
; // 0 means infinite, 1 is default
341 unsigned int delay
; // Delay in microseconds, 0 means no delay (default)
342 char arg_string
[MAX_PAYLOAD_SIZE
]; // Argument-string when -t is used
344 // Ethernet and 802.3 parameters
345 int eth_params_already_set
; // if set to 1 then send_eth should only send the frame
346 u_int8_t eth_mac_own
[6]; // Contains own interface MAC if needed by some modules
347 char eth_dst_txt
[32]; // Text version of eth_dst (or keyword such as 'rand')
349 int eth_dst_rand
; // 1 if random
350 char eth_src_txt
[32]; // Text version of eth_src (or keyword such as 'rand')
352 int eth_src_rand
; // 1 if random
355 u_int8_t eth_payload
[MAX_PAYLOAD_SIZE
];
356 u_int32_t eth_payload_s
;
357 unsigned int padding
;
363 cdp_payload
[MAX_PAYLOAD_SIZE
],
364 cdp_tlv_id
[2048]; // The ID is the only required TLV
372 int dot1Q
; // 1 if specified
373 char dot1Q_txt
[32]; // contains 802.1p(CoS) and VLAN-ID ("5:130" or only VLAN "130")
375 u_int16_t dot1Q_vlan
;
376 u_int8_t dot1Q_header
[256]; // Contains the complete 802.1Q/P headers (but NOT the Ethernet header!)
377 u_int8_t dot1Q_header_s
;
378 int dot1Q_at_least_two_headers
; // If '1' then we have at least QinQ (or more VLAN tags)
381 int ascii
; // 1 if specified
382 u_int8_t ascii_payload
[MAX_PAYLOAD_SIZE
];
385 u_int8_t hex_payload
[MAX_PAYLOAD_SIZE
];
386 u_int32_t hex_payload_s
; // >0 if hex payload is specified
389 char mpls_txt
[128]; // contains MPLS parameters (label, exp, S, TTL)
390 char mpls_verbose_string
[1024]; // contains all labels for print_frame_details()
391 int mpls
; // 1 if specified
392 u_int32_t mpls_label
;
398 u_int32_t ip_src
; // has always network byte order(!)
399 struct libnet_in6_addr ip6_src
;
400 char ip_src_txt
[256];
401 int ip_src_rand
; // if set to 1 then SA should be random
402 u_int32_t ip_src_h
; // mirror of ip_src (NOT network byte order => easy to count)
403 u_int32_t ip_src_start
; // start of range (NOT network byte order => easy to count)
404 u_int32_t ip_src_stop
; // stop of range (NOT network byte order => easy to count)
405 struct libnet_in6_addr ip6_src_start
; // start of IPv6 range
406 struct libnet_in6_addr ip6_src_stop
; // stop of IPv6 range
407 int ip_src_isrange
; // if set to 1 then the start/stop values above are valid.
408 u_int32_t ip_dst
; // has always network byte order(!)
409 struct libnet_in6_addr ip6_dst
;
410 char ip_dst_txt
[256];
411 u_int32_t ip_dst_h
; // mirror of ip_dst (NOT network byte order => easy to count)
412 u_int32_t ip_dst_start
; // start of range (NOT network byte order => easy to count)
413 u_int32_t ip_dst_stop
; // stop of range (NOT network byte order => easy to count)
414 struct libnet_in6_addr ip6_dst_start
; // start of IPv6 range
415 struct libnet_in6_addr ip6_dst_stop
; // stop of IPv6 range
416 int ip_dst_isrange
; // if set to 1 then the start/stop values above are valid.
420 ip_frag
, // Flags and Offset !!!
430 ip_payload
[MAX_PAYLOAD_SIZE
];
439 icmp_verbose_txt
[256]; // used for verbose messages in send.c
443 u_int16_t icmp_ident
; // ATTENTION: libnet.h already #defines 'icmp_id', 'icmp_sum', and 'icmp_num'
444 u_int16_t icmp_chksum
; // therefore I needed a renaming here -- be careful in future...
445 u_int16_t icmp_sqnr
; //
450 icmp_payload
[MAX_PAYLOAD_SIZE
];
452 // General L4 parameters:
459 sp_isrange
, // if set to 1 then start/stop values above are valid
460 dp_isrange
; // if set to 1 then start/stop values above are valid
464 udp_len
, // includes header size (8 bytes)
467 udp_payload
[MAX_PAYLOAD_SIZE
];
475 tcp_seq_stop
, // is always set! Usually seq_start = seq_stop (=no range)
476 tcp_seq_delta
, // Also used instead of an 'isrange' variable
485 tcp_len
; // only needed by libnet and must include header size
487 tcp_payload
[MAX_PAYLOAD_SIZE
];
497 } tx
; // NOTE: tx elements are considered as default values for MOPS
503 u_int8_t gbuf
[MAX_PAYLOAD_SIZE
]; // This is only a generic global buffer to handover data more easily
507 // ************************************
509 // Prototypes: General Tools
511 // ************************************
513 void clean_up(int sig
);
514 int getopts(int argc
, char *argv
[]);
515 int getarg(char *str
, char *arg_name
, char *arg_value
);
516 unsigned long int str2int(char *str
); // converts "65535" to 65535
517 unsigned long long int str2lint(char *str
); // same but allows 64-bit integers
518 unsigned long int xstr2int(char *str
); // converts "ffff" to 65535
519 unsigned long long int xstr2lint(char *str
); // same but allows 64-bit integers
520 int mz_strisbinary(char *str
);
521 int mz_strisnum(char *str
);
522 int mz_strishex(char *str
);
523 int str2bin8 (char *str
);
524 long int str2bin16 (char *str
);
525 int char2bits (char c
, char *str
);
526 int mz_strcmp(char* usr
, char* str
, int min
);
527 int mz_tok(char * str
, char * delim
, int anz
, ...);
528 int delay_parse (struct timespec
*t
, char *a
, char *b
);
531 // ************************************
533 // Prototypes: Layer1
535 // ************************************
538 libnet_ptag_t
create_eth_frame (libnet_t
*l
, libnet_ptag_t t3
, libnet_ptag_t t4
);
540 // ************************************
542 // Prototypes: Layer 2
544 // ************************************
547 int send_bpdu (void);
550 // ************************************
552 // Prototypes: Layer 3
554 // ************************************
557 libnet_t
* get_link_context(void);
558 libnet_ptag_t
create_ip_packet (libnet_t
*l
);
559 libnet_ptag_t
create_ip6_packet (libnet_t
*l
);
560 int send_frame (libnet_t
*l
, libnet_ptag_t t3
, libnet_ptag_t t4
);
564 // ************************************
566 // Prototypes: Layer 4
568 // ************************************
569 libnet_ptag_t
create_udp_packet(libnet_t
*l
);
570 libnet_ptag_t
create_icmp_packet(libnet_t
*l
);
571 libnet_ptag_t
create_icmp6_packet(libnet_t
*l
);
572 libnet_ptag_t
create_tcp_packet(libnet_t
*l
);
573 libnet_ptag_t
create_igmp_packet(libnet_t
*l
);
576 // ************************************
578 // Prototypes: Layer 7
580 // ************************************
581 int create_dns_packet (void);
582 int create_rtp_packet(void);
583 int create_syslog_packet(void);
585 // ************************************
587 // Prototypes: Helper functions for
588 // byte manipulation,
589 // address conversion,
592 // ************************************
594 // Converts MAC address specified in str into u_int8_t array
595 // Usage: str2hex_mac ( "00:01:02:aa:ff:ee", src_addr )
596 int str2hex_mac (char* str
, u_int8_t
*addr
);
598 // Converts ascii hex values (string) into integer array, similarly as above but for any size.
599 // Example: "1a 00:00-2f" => {26, 0, 0, 47}
600 // Note: apply any improvements here and prefer this function in future!
601 // Return value: Number of converted elements (=length of array)
602 int str2hex (char* str
, u_int8_t
*hp
, int n
);
604 // Converts ascii numbers (string) into integer array
605 // Every byte can be specified as integers {0..255}
606 // For example "192.16.1.1" will be converted to {C0, 10, 01, 01}
607 int num2hex(char* str
, u_int8_t
*hp
);
609 // Convert array of integers into string of hex. Useful for verification messages.
610 // Example: {0,1,10} => "00-01-0A"
611 // Usage: bs2str ( src_mac, src_mac_txt, 6 )
612 int bs2str (u_int8_t
*bs
, char* str
, int len
);
614 // Extract contiguous sequence of bytes from an array. First element has index 1 !!!
615 // Usage: getbytes (bs, da, 1, 6);
616 int getbytes(u_int8_t
*source
, u_int8_t
*target
, int from
, int to
);
618 // For any IP address given in 'dotted decimal' returns an unsigned 32-bit integer.
619 // Example: "192.168.0.1" => 3232235521
620 // Note: Result is in LITTLE ENDIAN but usually with IP you need BIG ENDIAN, see next.
621 u_int32_t
str2ip32 (char* str
);
623 // For any IP address given in 'dotted decimal' into an unsigned 32-bit integer
624 // This version does the same as str2ip32() but in BIG ENDIAN.
625 // Note: With netlib you need this one, not the previous function.
626 u_int32_t
str2ip32_rev (char* str
);
628 // Converts a 2-byte value (e. g. a EtherType field)
629 // into a nice string using hex notation.
630 // Useful for verification messages.
631 // Example: type2str (tx.eth_type, msg) may result in msg="08:00"
632 // Return value: how many hex digits have been found.
633 int type2str(u_int16_t type
, char *str
);
636 // Parses string 'arg' for an IP range and finds start and stop IP addresses.
637 // Return value: 0 upon success, 1 upon failure.
639 // NOTE: The results are written in the following variables:
641 // (u_int32_t) tx.ip_dst_start ... contains start value
642 // (u_int32_t) tx.ip_dst_stop ... contains stop value
643 // int tx.ip_dst_isrange ... set to 1 if above values valid
645 // The other function does the same for the source address!
647 // Possible range specifications:
649 // 1) 192.168.0.0-192.168.0.12
650 // 2) 10.2.11.0-10.55.13.2
655 // FIRST detect a range by scanning for the "-" OR "/" chars
656 // THEN determine start and stop value and store them as normal unsigned integers
658 int get_ip_range_dst (char *arg
);
659 int get_ip_range_src (char *arg
);
660 int get_ip6_range_src (char *arg
, libnet_t
*l
);
661 int get_ip6_range_dst (char *arg
, libnet_t
*l
);
663 // Sets a random SA for a given IP packet.
664 // Return value: 0 upon success, 1 upon failure
666 int set_rand_SA (libnet_t
*l
, libnet_ptag_t t3
);
668 // Scans tx.eth_dst_txt or tx.eth_src_txt and sets the corresponding
669 // MAC addresses (tx.eth_dst or tx.eth_src) accordingly.
670 // Argument: What string should be checked, ETH_SRC or ETH_DST.
672 // 0 when a MAC address has been set or
674 // Currently eth_src|dst_txt can be:
675 // 'rand', 'own', 'bc'|'bcast', 'stp', 'pvst',
676 // or a real mac address.
678 int check_eth_mac_txt(int src_or_dst
);
680 // Scans argument for a port number or range
681 // and sets the corresponding values in the
684 // Arguments: sp_or_dp is either SRC_PORT or DST_PORT
685 // Return value: 0 on success, 1 upon failure
687 int get_port_range (int sp_or_dp
, char *arg
);
689 // Return a 4-byte unsigned int random number
690 u_int32_t
mz_rand32 (void);
692 // Scans argument for TCP flags and sets
693 // tx.tcp_control accordingly.
695 // Valid keywords are: fin, syn, rst, psh, ack, urg, ecn, cwr
696 // Valid delimiters are: | or + or -
697 // Return value: 0 on success, 1 upon failure
699 int get_tcp_flags (char* flags
);
701 // Scans string 'params' for MPLS parameters
702 // and sets tx.mpls_* accordingly.
704 // CLI Syntax Examples:
706 // -M help .... shows syntax
708 // -M 800 .... label=800
709 // -M 800:S .... label=800 and BOS flag set
710 // -M 800:S:64 .... label=800, BOS, TTL=64
711 // -M 800:64:S .... same
712 // -M 64:77 .... label=64, TTL=77
713 // -M 64:800 .... INVALID
714 // -M 800:64 .... label=800, TTL=64
715 // -M 800:3:S:64 .... additionall the experimental bits are set (all fields required!)
717 // Note: S = BOS(1), s = NOT-BOS(0)
719 // Valid delimiters: :-.,+
720 // Return value: 0 on success, 1 upon failure
721 int get_mpls_params(char *params
);
723 // Parses str for occurence of character or sequence ch.
724 // Returns number of occurences
725 int exists(char* str
, char* ch
);
728 // Applies another random Ethernet source address to a given Ethernet-PTAG.
729 // (The calling function should check 'tx.eth_src_rand' whether the SA
730 // should be randomized.)
731 int update_Eth_SA(libnet_t
*l
, libnet_ptag_t t
);
734 // Update timestamp and sequence number in the RTP header.
735 // The actual RTP message is stored in tx.udp_payload.
736 int update_RTP(libnet_t
*l
, libnet_ptag_t t
);
739 // Applies another SOURCE IP address,
740 // - either a random one (tx.ip_src_rand==1)
741 // - or from a specified range (tx.ip_src_isrange==1)
742 // to a given IP-PTAG.
744 // Note: tx.ip_src MUST be already initialized with tx.ip_src_start.
745 // This is done by 'get_ip_range_src()' in tools.c.
747 // RETURNS '1' if tx.ip_src restarts
748 int update_IP_SA (libnet_t
*l
, libnet_ptag_t t
);
749 int update_IP6_SA (libnet_t
*l
, libnet_ptag_t t
);
752 // Applies another DESTINATION IP address from a specified range (tx.ip_dst_isrange==1)
753 // to a given IP-PTAG.
755 // Note: tx.ip_dst MUST be already initialized with tx.ip_dst_start.
756 // This is done by 'get_ip_range_dst()' in tools.c.
758 // RETURN VALUE: '1' if tx.ip_dst restarts
759 int update_IP_DA(libnet_t
*l
, libnet_ptag_t t
);
760 int update_IP6_DA (libnet_t
*l
, libnet_ptag_t t
);
763 // Applies another DESTINATION PORT from a specified range to a given UDP- or TCP-PTAG.
765 // Note: tx.dp MUST be already initialized with tx.dp_start
766 // This is done by 'get_port_range()' in tools.c.
768 // RETURN VALUE: '1' if tx.dp restarts
769 int update_DPORT(libnet_t
*l
, libnet_ptag_t t
);
772 // Applies another SOURCE PORT from a specified range to a given UDP- or TCP-PTAG.
774 // Note: tx.sp MUST be already initialized with tx.sp_start
775 // This is done by 'get_port_range()' in tools.c.
777 // RETURN VALUE: '1' if tx.sp restarts
778 int update_SPORT(libnet_t
*l
, libnet_ptag_t t
);
781 // Applies another TCP SQNR from a specified range to a given TCP-PTAG
783 // RETURN VALUE: '1' if tx.txp_seq restarts
785 int update_TCP_SQNR(libnet_t
*l
, libnet_ptag_t t
);
787 int update_ISUM(libnet_t
*l
, libnet_ptag_t t
);
788 int update_USUM(libnet_t
*l
, libnet_ptag_t t
);
789 int update_TSUM(libnet_t
*l
, libnet_ptag_t t
);
793 int print_frame_details(void);
795 int in6_addr_cmp(struct libnet_in6_addr addr1
, struct libnet_in6_addr addr2
);
796 int incr_in6_addr(struct libnet_in6_addr src
, struct libnet_in6_addr
*dst
);
797 uint64_t get_ip6_range_count(struct libnet_in6_addr start
, struct libnet_in6_addr stop
);
799 // Calculates the number of frames to be sent.
800 // Should be used as standard output except the
801 // 'quiet' option (-q) has been specified.
802 int complexity(void);
805 // Purpose: Calculate time deltas of two timestamps stored in struct timeval.
806 // Subtract the "struct timeval" values X and Y, storing the result in RESULT.
807 // Return 1 if the difference is negative, otherwise 0.
808 int timestamp_subtract (struct mz_timestamp
*x
,
809 struct mz_timestamp
*y
,
810 struct mz_timestamp
*result
);
812 void timestamp_add (struct mz_timestamp
*x
,
813 struct mz_timestamp
*y
,
814 struct mz_timestamp
*result
);
816 // Returns a human readable timestamp in the string result.
817 // Optionally a prefix can be specified, for example if the
818 // timestamp is part of a filename.
821 // char myTimeStamp[128];
823 // timestamp_human(myTimeStamp, NULL);
825 // => "20080718_155521"
827 // /* or with prefix */
829 // timestamp_human(myTimeStamp, "MZ_RTP_jitter_");
831 // => MZ_RTP_jitter_20080718_155521
833 int timestamp_human(char* result
, const char* prefix
);
835 // Returns a human readable timestamp in the string result.
836 // Optionally a prefix can be specified, for example if the
837 // timestamp is part of a filename.
840 // char myTimeStamp[8];
842 // timestamp_hms (myTimeStamp);
845 int timestamp_hms(char* result
);
847 // Initialize the rcv_rtp process: Read user parameters and initialize globals
848 int rcv_rtp_init(void);
850 // Defines the pcap handler and the callback function
853 // Print current RFC-Jitter on screen
854 void print_jitterbar (long int j
, unsigned int d
);
856 // Compares two 4-byte variables byte by byte
857 // returns 0 if identical, 1 if different
858 int compare4B (u_int8_t
*ip1
, u_int8_t
*ip2
);
860 // PURPOSE: Find usable network devices
864 // 1. Ignores devices without IP address
865 // 2. Ignores loopback (etc)
869 // 0 if usable device found (device_list[] and tx.device set)
870 // 1 if no usable device found
875 // For a given device name, find out the following parameters:
882 int get_dev_params (char *name
);
884 // Handler function to do something when RTP messages are received
885 void got_rtp_packet(u_char
*args
,
886 const struct pcap_pkthdr
*header
, // statistics about the packet (see 'struct pcap_pkthdr')
887 const u_char
*packet
); // the bytestring sniffed
890 // Check if current system supports the nanosecond timer functions.
891 // Additionally, measure the precision.
892 // This function should be called upon program start.
894 int check_timer(void);
896 // This is the replacement for gettimeofday() which would result in 'jumps' if
897 // the system clock is adjusted (e. g. via a NTP process) and finally the jitter
898 // measurement would include wrong datapoints.
900 // Furthermore the function below utilizes the newer hi-res nanosecond timers.
901 void getcurtime (struct mz_timestamp
*t
);
903 // Only print out the help text for the 02.1Q option
904 void print_dot1Q_help(void);
906 // Determines ip and mac address of specified interface 'ifname'
907 // Caller must provide an unsigned char ip[4], mac[6]
909 int get_if_addr (char *ifname
, unsigned char *ip
, unsigned char *mac
);
911 // Takes filename and prepends valid configuration/logging directory
912 // NOTE: filename is overwritten and must be big enough to hold full path!
913 int getfullpath_cfg (char *filename
);
914 int getfullpath_log (char *filename
);
916 // A safer replacement for strncpy which ensures \0-termination
917 char * mz_strncpy(char *dest
, const char *src
, size_t n
);
919 // Helper function to count the number of arguments
920 // in the Mausezahn argument string (comma separated args)
921 // RETURN VALUE: Number of arguments
922 int number_of_args (char *str
);
924 int arptable_add(struct device_struct
*dev
,
932 // Validate ARP requests
933 int arpwatch(struct device_struct
*dev
,