ifpps: use uint32_t instead of u32
[netsniff-ng.git] / staging / mz.h
blobaa2c36fc56737bf7bb28953500d338e189191e97
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 int MZ_SIZE_LONG_INT;
113 char mz_default_config_path[256];
114 char mz_default_log_path[256];
117 struct arp_table_struct {
118 int index; // an entry index (1, 2, ...) for easier user access
119 u_int8_t sa[6]; // sent by this MAC SA
120 u_int8_t smac[6]; // announced MAC
121 u_int8_t smac_prev[6]; // previously announced MAC
122 u_int8_t sip[4]; // announced IP
123 unsigned long int uni_rq; // count unidirectional ARP requests for this IP
124 unsigned long int bc_resp; // count broadcast ARP responses for this IP
125 unsigned long int uni_resp; // count normal (unidir) ARP responses for this IP
126 unsigned long int changed; // count how often the MAC address has changed!
127 int locked; // 1=this entry cannot be overidden anymore
128 int dynamic; // 1=learned dynamically, 0=configured by user
129 int flags; // anomaly information (length anomaly: bit 0, sa!=smac: bit 1 , ...)
130 int gw; // 1=Default GW
131 char when[10]; // human readable timestamp (e. g. "11:42:53")
132 u_int32_t sec, nsec; // timestamp of last ARP response
133 u_int32_t sec_prev, nsec_prev; // timestamp of previous ARP response
134 //-----------------//
135 struct arp_table_struct *next;
138 // Device list
139 struct device_struct
141 char dev[16]; // Device name
142 int index; // Device index (assigned by OS)
143 int phy; // 1 if physical, 0 if not (e. g. loopback)
144 int mtu;
145 int cli; // if set to 1 then the CLI connection must terminate here
146 int mgmt_only; // if set to 1 then no data traffic is allowed through that interface
147 // ---- MAC addresses ----
148 u_int8_t mac[6]; // Real MAC address
149 u_int8_t mac_mops[6]; // MAC address to be used
150 // ---- IP related -----
151 char ip_str[IPADDRSIZE+1]; // Real IP address as string in dotted decimal notation
152 u_int8_t ip[4]; // Real IP address
153 u_int8_t net[4]; // Real network
154 u_int8_t mask[4]; // Real mask
155 u_int8_t ip_mops[4]; // IP address to be used
156 // ---- Default Gateway per interface:
157 u_int8_t mac_gw[6]; // MAC address of default gateway
158 u_int8_t ip_gw[4]; // IP address of default gateway
159 // ---- various device-specific handles ----
160 pthread_t arprx_thread;
161 struct pcap *p_arp; // pcap handle
162 struct arp_table_struct *arp_table; // dedicated ARP table
163 int ps; // packet socket
164 } device_list[MZ_MAX_DEVICES];
166 int device_list_entries;
169 #pragma pack(1)
170 struct struct_ethernet
172 u_int8_t eth_da[6];
173 u_int8_t eth_sa[6];
174 u_int16_t eth_type;
177 struct struct_arp
179 u_int16_t arp_hrd; // hardware address format
180 u_int16_t arp_pro; // protocol address format
181 u_int8_t arp_hln; // hardware address length
182 u_int8_t arp_pln; // protocol address length
183 u_int16_t arp_op; // ARP operation type
184 u_int8_t arp_smac[6]; // sender's hardware address
185 u_int8_t arp_sip[4]; // sender's protocol address
186 u_int8_t arp_tmac[6]; // target hardware address
187 u_int8_t arp_tip[4]; // target protocol address
192 //#pragma pack(1)
193 struct struct_ip
195 u_int8_t
196 hlen :4,
197 ver :4;
198 u_int8_t
199 tos;
200 u_int16_t
201 len;
203 u_int16_t
204 id,
205 offset; // flags and fragment offset field
207 u_int8_t
208 ttl,
209 proto;
210 u_int16_t
211 sum;
213 u_int8_t src[4];
214 u_int8_t dst[4];
217 //#pragma pack(1)
218 struct struct_udp {
219 u_int16_t
222 len,
223 sum;
226 //#pragma pack(1)
227 struct struct_rtp {
228 u_int8_t
229 byte1,
230 ptype;
231 u_int16_t
232 sqnr;
233 u_int32_t
234 timestamp, // official timestamp, created by codecs
235 ssrc;
236 // csrc, // only used by mixers
237 u_int16_t
238 ext_id,
239 ext_len;
240 u_int32_t
241 time_sec,
242 time_nsec,
243 time_sec2,
244 time_nsec2;
247 // ---------End of PCAP-specific definitions---------------
252 // ************************************
254 // Global variables
256 // ************************************
258 enum operating_modes
260 BYTE_STREAM,
261 ARP,
262 BPDU,
264 ICMP,
265 ICMP6,
266 UDP,
267 TCP,
268 DNS,
269 CDP,
270 RTP,
271 RX_RTP,
272 SYSLOG,
273 LLDP,
274 IGMP
275 } mode;
278 int ipv6_mode;
279 int quiet; // don't even print 'important standard short messages'
280 int verbose; // report character
281 int simulate; // if 1 then don't really send frames
283 char path[256];
284 char filename[256];
285 FILE *fp, *fp2; // global multipurpose file pointer
287 long double total_d;
288 clock_t mz_start, mz_stop;
290 enum rtp_display_mode {
291 BAR, NCURSES, TEXT
292 } rtp_dm;
295 int mz_rand;
296 int bwidth;
298 struct mz_timestamp {
299 u_int32_t sec;
300 u_int32_t nsec;
303 struct mz_timestamp
304 tv,
305 timeTX[TIME_COUNT_MAX],
306 timeRX[TIME_COUNT_MAX];
308 int32_t
309 time0,
310 jitter_rfc,
311 jitter[TIME_COUNT_MAX];
313 int
314 rtp_log,
315 time0_flag, // If set then time0 has valid data
316 sqnr0_flag;
318 u_int8_t
319 mz_ssrc[4]; // holds RTP stream identifier for rcv_rtp()
321 u_int16_t
322 sqnr_cur,
323 sqnr_last,
324 sqnr_next;
326 u_int32_t
327 drop, // packet drop count
328 dis, // packet disorder count
329 gind, // a global index to run through deltaRX, deltaTX, and jitter
330 gind_max, // the amount of entries used in the (ugly oversized) arrays; per default set to TIME_COUNT
331 gtotal; // counts number of file write cycles (see "got_rtp_packet()")
334 char rtp_filter_str[64];
336 struct tx_struct
338 // Management issues for TX
339 char device[16]; // every packet could be sent through a different device
340 int packet_mode; // 0 means use LIBNET_LINK_ADV, 1 means LIBNET_RAW4
341 unsigned int count; // 0 means infinite, 1 is default
342 unsigned int delay; // Delay in microseconds, 0 means no delay (default)
343 char arg_string[MAX_PAYLOAD_SIZE]; // Argument-string when -t is used
345 // Ethernet and 802.3 parameters
346 int eth_params_already_set; // if set to 1 then send_eth should only send the frame
347 u_int8_t eth_mac_own[6]; // Contains own interface MAC if needed by some modules
348 char eth_dst_txt[32]; // Text version of eth_dst (or keyword such as 'rand')
349 u_int8_t eth_dst[6];
350 int eth_dst_rand; // 1 if random
351 char eth_src_txt[32]; // Text version of eth_src (or keyword such as 'rand')
352 u_int8_t eth_src[6];
353 int eth_src_rand; // 1 if random
354 u_int16_t eth_type;
355 u_int16_t eth_len;
356 u_int8_t eth_payload[MAX_PAYLOAD_SIZE];
357 u_int32_t eth_payload_s;
358 unsigned int padding;
360 // CDP parameters
361 u_int8_t
362 cdp_version,
363 cdp_ttl,
364 cdp_payload[MAX_PAYLOAD_SIZE],
365 cdp_tlv_id[2048]; // The ID is the only required TLV
366 u_int16_t
367 cdp_sum;
368 u_int32_t
369 cdp_tlv_id_len,
370 cdp_payload_s;
372 // 802.1Q VLAN Tag
373 int dot1Q; // 1 if specified
374 char dot1Q_txt[32]; // contains 802.1p(CoS) and VLAN-ID ("5:130" or only VLAN "130")
375 u_int8_t dot1Q_CoS;
376 u_int16_t dot1Q_vlan;
377 u_int8_t dot1Q_header[256]; // Contains the complete 802.1Q/P headers (but NOT the Ethernet header!)
378 u_int8_t dot1Q_header_s;
379 int dot1Q_at_least_two_headers; // If '1' then we have at least QinQ (or more VLAN tags)
381 // ASCII PAYLOAD
382 int ascii; // 1 if specified
383 u_int8_t ascii_payload[MAX_PAYLOAD_SIZE];
385 // HEX PAYLOAD
386 u_int8_t hex_payload[MAX_PAYLOAD_SIZE];
387 u_int32_t hex_payload_s; // >0 if hex payload is specified
389 // MPLS Parameters
390 char mpls_txt[128]; // contains MPLS parameters (label, exp, S, TTL)
391 char mpls_verbose_string[1024]; // contains all labels for print_frame_details()
392 int mpls; // 1 if specified
393 u_int32_t mpls_label;
394 u_int8_t mpls_exp;
395 u_int8_t mpls_bos;
396 u_int8_t mpls_ttl;
398 // IP parameters
399 u_int32_t ip_src; // has always network byte order(!)
400 struct libnet_in6_addr ip6_src;
401 char ip_src_txt[256];
402 int ip_src_rand; // if set to 1 then SA should be random
403 u_int32_t ip_src_h; // mirror of ip_src (NOT network byte order => easy to count)
404 u_int32_t ip_src_start; // start of range (NOT network byte order => easy to count)
405 u_int32_t ip_src_stop; // stop of range (NOT network byte order => easy to count)
406 struct libnet_in6_addr ip6_src_start; // start of IPv6 range
407 struct libnet_in6_addr ip6_src_stop; // stop of IPv6 range
408 int ip_src_isrange; // if set to 1 then the start/stop values above are valid.
409 u_int32_t ip_dst; // has always network byte order(!)
410 struct libnet_in6_addr ip6_dst;
411 char ip_dst_txt[256];
412 u_int32_t ip_dst_h; // mirror of ip_dst (NOT network byte order => easy to count)
413 u_int32_t ip_dst_start; // start of range (NOT network byte order => easy to count)
414 u_int32_t ip_dst_stop; // stop of range (NOT network byte order => easy to count)
415 struct libnet_in6_addr ip6_dst_start; // start of IPv6 range
416 struct libnet_in6_addr ip6_dst_stop; // stop of IPv6 range
417 int ip_dst_isrange; // if set to 1 then the start/stop values above are valid.
418 u_int16_t
419 ip_len,
420 ip_id,
421 ip_frag, // Flags and Offset !!!
422 ip_sum;
423 u_int8_t
424 ip_tos,
425 ip_ttl,
426 ip6_rtype,
427 ip6_segs,
428 ip_proto;
429 u_int8_t
430 ip_option[1024],
431 ip_payload[MAX_PAYLOAD_SIZE];
432 u_int32_t
433 ip_flow,
434 ip6_id,
435 ip_option_s,
436 ip_payload_s;
438 // ICMP
439 char
440 icmp_verbose_txt[256]; // used for verbose messages in send.c
441 u_int8_t
442 icmp_type,
443 icmp_code;
444 u_int16_t icmp_ident; // ATTENTION: libnet.h already #defines 'icmp_id', 'icmp_sum', and 'icmp_num'
445 u_int16_t icmp_chksum; // therefore I needed a renaming here -- be careful in future...
446 u_int16_t icmp_sqnr; //
447 u_int32_t
448 icmp_gateway,
449 icmp_payload_s;
450 u_int8_t
451 icmp_payload[MAX_PAYLOAD_SIZE];
453 // General L4 parameters:
454 char *layer4;
455 u_int16_t
456 sp, dp,
457 sp_start, sp_stop,
458 dp_start, dp_stop;
459 int
460 sp_isrange, // if set to 1 then start/stop values above are valid
461 dp_isrange; // if set to 1 then start/stop values above are valid
463 // UDP parameters
464 u_int16_t
465 udp_len, // includes header size (8 bytes)
466 udp_sum;
467 u_int8_t
468 udp_payload[MAX_PAYLOAD_SIZE];
469 u_int32_t
470 udp_payload_s;
472 // TCP parameters
473 u_int32_t
474 tcp_seq,
475 tcp_seq_start,
476 tcp_seq_stop, // is always set! Usually seq_start = seq_stop (=no range)
477 tcp_seq_delta, // Also used instead of an 'isrange' variable
478 tcp_ack;
479 u_int8_t
480 tcp_offset,
481 tcp_control;
482 u_int16_t
483 tcp_win,
484 tcp_sum,
485 tcp_urg,
486 tcp_len; // only needed by libnet and must include header size
487 u_int8_t
488 tcp_payload[MAX_PAYLOAD_SIZE];
489 u_int32_t
490 tcp_sum_part,
491 tcp_payload_s;
493 // RTP parameters
494 u_int32_t
495 rtp_sqnr,
496 rtp_stmp;
498 } tx; // NOTE: tx elements are considered as default values for MOPS
504 u_int8_t gbuf[MAX_PAYLOAD_SIZE]; // This is only a generic global buffer to handover data more easily
505 u_int32_t gbuf_s; //
508 // ************************************
510 // Prototypes: General Tools
512 // ************************************
514 void clean_up(int sig);
515 int getopts(int argc, char *argv[]);
516 int getarg(char *str, char *arg_name, char *arg_value);
517 unsigned long int str2int(char *str); // converts "65535" to 65535
518 unsigned long long int str2lint(char *str); // same but allows 64-bit integers
519 unsigned long int xstr2int(char *str); // converts "ffff" to 65535
520 unsigned long long int xstr2lint(char *str); // same but allows 64-bit integers
521 int mz_strisbinary(char *str);
522 int mz_strisnum(char *str);
523 int mz_strishex(char *str);
524 int str2bin8 (char *str);
525 long int str2bin16 (char *str);
526 int char2bits (char c, char *str);
527 int mz_strcmp(char* usr, char* str, int min);
528 int mz_tok(char * str, char * delim, int anz, ...);
529 int delay_parse (struct timespec *t, char *a, char *b);
530 int reset(void);
532 // ************************************
534 // Prototypes: Layer1
536 // ************************************
538 int send_eth(void);
539 libnet_ptag_t create_eth_frame (libnet_t *l, libnet_ptag_t t3, libnet_ptag_t t4);
541 // ************************************
543 // Prototypes: Layer 2
545 // ************************************
547 int send_arp (void);
548 int send_bpdu (void);
549 int send_cdp (void);
551 // ************************************
553 // Prototypes: Layer 3
555 // ************************************
558 libnet_t* get_link_context(void);
559 libnet_ptag_t create_ip_packet (libnet_t *l);
560 libnet_ptag_t create_ip6_packet (libnet_t *l);
561 int send_frame (libnet_t *l, libnet_ptag_t t3, libnet_ptag_t t4);
565 // ************************************
567 // Prototypes: Layer 4
569 // ************************************
570 libnet_ptag_t create_udp_packet(libnet_t *l);
571 libnet_ptag_t create_icmp_packet(libnet_t *l);
572 libnet_ptag_t create_icmp6_packet(libnet_t *l);
573 libnet_ptag_t create_tcp_packet(libnet_t *l);
574 libnet_ptag_t create_igmp_packet(libnet_t *l);
577 // ************************************
579 // Prototypes: Layer 7
581 // ************************************
582 int create_dns_packet (void);
583 int create_rtp_packet(void);
584 int create_syslog_packet(void);
586 // ************************************
588 // Prototypes: Helper functions for
589 // byte manipulation,
590 // address conversion,
591 // etc
593 // ************************************
595 // Converts MAC address specified in str into u_int8_t array
596 // Usage: str2hex_mac ( "00:01:02:aa:ff:ee", src_addr )
597 int str2hex_mac (char* str, u_int8_t *addr);
599 // Converts ascii hex values (string) into integer array, similarly as above but for any size.
600 // Example: "1a 00:00-2f" => {26, 0, 0, 47}
601 // Note: apply any improvements here and prefer this function in future!
602 // Return value: Number of converted elements (=length of array)
603 int str2hex (char* str, u_int8_t *hp, int n);
605 // Converts ascii numbers (string) into integer array
606 // Every byte can be specified as integers {0..255}
607 // For example "192.16.1.1" will be converted to {C0, 10, 01, 01}
608 int num2hex(char* str, u_int8_t *hp);
610 // Convert array of integers into string of hex. Useful for verification messages.
611 // Example: {0,1,10} => "00-01-0A"
612 // Usage: bs2str ( src_mac, src_mac_txt, 6 )
613 int bs2str (u_int8_t *bs, char* str, int len);
615 // Extract contiguous sequence of bytes from an array. First element has index 1 !!!
616 // Usage: getbytes (bs, da, 1, 6);
617 int getbytes(u_int8_t *source, u_int8_t *target, int from, int to);
619 // For any IP address given in 'dotted decimal' returns an unsigned 32-bit integer.
620 // Example: "192.168.0.1" => 3232235521
621 // Note: Result is in LITTLE ENDIAN but usually with IP you need BIG ENDIAN, see next.
622 u_int32_t str2ip32 (char* str);
624 // For any IP address given in 'dotted decimal' into an unsigned 32-bit integer
625 // This version does the same as str2ip32() but in BIG ENDIAN.
626 // Note: With netlib you need this one, not the previous function.
627 u_int32_t str2ip32_rev (char* str);
629 // Converts a 2-byte value (e. g. a EtherType field)
630 // into a nice string using hex notation.
631 // Useful for verification messages.
632 // Example: type2str (tx.eth_type, msg) may result in msg="08:00"
633 // Return value: how many hex digits have been found.
634 int type2str(u_int16_t type, char *str);
637 // Parses string 'arg' for an IP range and finds start and stop IP addresses.
638 // Return value: 0 upon success, 1 upon failure.
640 // NOTE: The results are written in the following variables:
642 // (u_int32_t) tx.ip_dst_start ... contains start value
643 // (u_int32_t) tx.ip_dst_stop ... contains stop value
644 // int tx.ip_dst_isrange ... set to 1 if above values valid
646 // The other function does the same for the source address!
648 // Possible range specifications:
650 // 1) 192.168.0.0-192.168.0.12
651 // 2) 10.2.11.0-10.55.13.2
652 // 3) 172.18.96.0/19
654 // That is:
656 // FIRST detect a range by scanning for the "-" OR "/" chars
657 // THEN determine start and stop value and store them as normal unsigned integers
659 int get_ip_range_dst (char *arg);
660 int get_ip_range_src (char *arg);
661 int get_ip6_range_src (char *arg, libnet_t *l);
662 int get_ip6_range_dst (char *arg, libnet_t *l);
664 // Sets a random SA for a given IP packet.
665 // Return value: 0 upon success, 1 upon failure
667 int set_rand_SA (libnet_t *l, libnet_ptag_t t3);
669 // Scans tx.eth_dst_txt or tx.eth_src_txt and sets the corresponding
670 // MAC addresses (tx.eth_dst or tx.eth_src) accordingly.
671 // Argument: What string should be checked, ETH_SRC or ETH_DST.
672 // Return value:
673 // 0 when a MAC address has been set or
674 // 1 upon failure.
675 // Currently eth_src|dst_txt can be:
676 // 'rand', 'own', 'bc'|'bcast', 'stp', 'pvst',
677 // or a real mac address.
679 int check_eth_mac_txt(int src_or_dst);
681 // Scans argument for a port number or range
682 // and sets the corresponding values in the
683 // tx struct.
685 // Arguments: sp_or_dp is either SRC_PORT or DST_PORT
686 // Return value: 0 on success, 1 upon failure
688 int get_port_range (int sp_or_dp, char *arg);
690 // Return a 4-byte unsigned int random number
691 u_int32_t mz_rand32 (void);
693 // Scans argument for TCP flags and sets
694 // tx.tcp_control accordingly.
696 // Valid keywords are: fin, syn, rst, psh, ack, urg, ecn, cwr
697 // Valid delimiters are: | or + or -
698 // Return value: 0 on success, 1 upon failure
700 int get_tcp_flags (char* flags);
702 // Scans string 'params' for MPLS parameters
703 // and sets tx.mpls_* accordingly.
705 // CLI Syntax Examples:
707 // -M help .... shows syntax
709 // -M 800 .... label=800
710 // -M 800:S .... label=800 and BOS flag set
711 // -M 800:S:64 .... label=800, BOS, TTL=64
712 // -M 800:64:S .... same
713 // -M 64:77 .... label=64, TTL=77
714 // -M 64:800 .... INVALID
715 // -M 800:64 .... label=800, TTL=64
716 // -M 800:3:S:64 .... additionall the experimental bits are set (all fields required!)
718 // Note: S = BOS(1), s = NOT-BOS(0)
720 // Valid delimiters: :-.,+
721 // Return value: 0 on success, 1 upon failure
722 int get_mpls_params(char *params);
724 // Parses str for occurence of character or sequence ch.
725 // Returns number of occurences
726 int exists(char* str, char* ch);
729 // Applies another random Ethernet source address to a given Ethernet-PTAG.
730 // (The calling function should check 'tx.eth_src_rand' whether the SA
731 // should be randomized.)
732 int update_Eth_SA(libnet_t *l, libnet_ptag_t t);
735 // Update timestamp and sequence number in the RTP header.
736 // The actual RTP message is stored in tx.udp_payload.
737 int update_RTP(libnet_t *l, libnet_ptag_t t);
740 // Applies another SOURCE IP address,
741 // - either a random one (tx.ip_src_rand==1)
742 // - or from a specified range (tx.ip_src_isrange==1)
743 // to a given IP-PTAG.
745 // Note: tx.ip_src MUST be already initialized with tx.ip_src_start.
746 // This is done by 'get_ip_range_src()' in tools.c.
748 // RETURNS '1' if tx.ip_src restarts
749 int update_IP_SA (libnet_t *l, libnet_ptag_t t);
750 int update_IP6_SA (libnet_t *l, libnet_ptag_t t);
753 // Applies another DESTINATION IP address from a specified range (tx.ip_dst_isrange==1)
754 // to a given IP-PTAG.
756 // Note: tx.ip_dst MUST be already initialized with tx.ip_dst_start.
757 // This is done by 'get_ip_range_dst()' in tools.c.
759 // RETURN VALUE: '1' if tx.ip_dst restarts
760 int update_IP_DA(libnet_t *l, libnet_ptag_t t);
761 int update_IP6_DA (libnet_t *l, libnet_ptag_t t);
764 // Applies another DESTINATION PORT from a specified range to a given UDP- or TCP-PTAG.
766 // Note: tx.dp MUST be already initialized with tx.dp_start
767 // This is done by 'get_port_range()' in tools.c.
769 // RETURN VALUE: '1' if tx.dp restarts
770 int update_DPORT(libnet_t *l, libnet_ptag_t t);
773 // Applies another SOURCE PORT from a specified range to a given UDP- or TCP-PTAG.
775 // Note: tx.sp MUST be already initialized with tx.sp_start
776 // This is done by 'get_port_range()' in tools.c.
778 // RETURN VALUE: '1' if tx.sp restarts
779 int update_SPORT(libnet_t *l, libnet_ptag_t t);
782 // Applies another TCP SQNR from a specified range to a given TCP-PTAG
784 // RETURN VALUE: '1' if tx.txp_seq restarts
786 int update_TCP_SQNR(libnet_t *l, libnet_ptag_t t);
788 int update_ISUM(libnet_t *l, libnet_ptag_t t);
789 int update_USUM(libnet_t *l, libnet_ptag_t t);
790 int update_TSUM(libnet_t *l, libnet_ptag_t t);
794 int print_frame_details(void);
796 int in6_addr_cmp(struct libnet_in6_addr addr1, struct libnet_in6_addr addr2);
797 int incr_in6_addr(struct libnet_in6_addr src, struct libnet_in6_addr *dst);
798 uint64_t get_ip6_range_count(struct libnet_in6_addr start, struct libnet_in6_addr stop);
800 // Calculates the number of frames to be sent.
801 // Should be used as standard output except the
802 // 'quiet' option (-q) has been specified.
803 int complexity(void);
806 // Purpose: Calculate time deltas of two timestamps stored in struct timeval.
807 // Subtract the "struct timeval" values X and Y, storing the result in RESULT.
808 // Return 1 if the difference is negative, otherwise 0.
809 int timestamp_subtract (struct mz_timestamp *x,
810 struct mz_timestamp *y,
811 struct mz_timestamp *result);
813 void timestamp_add (struct mz_timestamp *x,
814 struct mz_timestamp *y,
815 struct mz_timestamp *result);
817 // Returns a human readable timestamp in the string result.
818 // Optionally a prefix can be specified, for example if the
819 // timestamp is part of a filename.
821 // Example:
822 // char myTimeStamp[128];
824 // timestamp_human(myTimeStamp, NULL);
826 // => "20080718_155521"
828 // /* or with prefix */
830 // timestamp_human(myTimeStamp, "MZ_RTP_jitter_");
832 // => MZ_RTP_jitter_20080718_155521
834 int timestamp_human(char* result, const char* prefix);
836 // Returns a human readable timestamp in the string result.
837 // Optionally a prefix can be specified, for example if the
838 // timestamp is part of a filename.
840 // Example:
841 // char myTimeStamp[8];
843 // timestamp_hms (myTimeStamp);
845 // => "15:55:21"
846 int timestamp_hms(char* result);
848 // Initialize the rcv_rtp process: Read user parameters and initialize globals
849 int rcv_rtp_init(void);
851 // Defines the pcap handler and the callback function
852 int rcv_rtp(void);
854 // Print current RFC-Jitter on screen
855 void print_jitterbar (long int j, unsigned int d);
857 // Compares two 4-byte variables byte by byte
858 // returns 0 if identical, 1 if different
859 int compare4B (u_int8_t *ip1, u_int8_t *ip2);
861 // PURPOSE: Find usable network devices
863 // NOTE:
865 // 1. Ignores devices without IP address
866 // 2. Ignores loopback (etc)
868 // RETURN VALUES:
870 // 0 if usable device found (device_list[] and tx.device set)
871 // 1 if no usable device found
873 int lookupdev(void);
876 // For a given device name, find out the following parameters:
878 // - MTU
879 // - Network
880 // - Mask
881 // - Default GW (IP)
883 int get_dev_params (char *name);
885 // Handler function to do something when RTP messages are received
886 void got_rtp_packet(u_char *args,
887 const struct pcap_pkthdr *header, // statistics about the packet (see 'struct pcap_pkthdr')
888 const u_char *packet); // the bytestring sniffed
891 // Check if current system supports the nanosecond timer functions.
892 // Additionally, measure the precision.
893 // This function should be called upon program start.
895 int check_timer(void);
897 // This is the replacement for gettimeofday() which would result in 'jumps' if
898 // the system clock is adjusted (e. g. via a NTP process) and finally the jitter
899 // measurement would include wrong datapoints.
901 // Furthermore the function below utilizes the newer hi-res nanosecond timers.
902 void getcurtime (struct mz_timestamp *t);
904 // Only print out the help text for the 02.1Q option
905 void print_dot1Q_help(void);
907 // Determines ip and mac address of specified interface 'ifname'
908 // Caller must provide an unsigned char ip[4], mac[6]
910 int get_if_addr (char *ifname, unsigned char *ip, unsigned char *mac);
912 // Takes filename and prepends valid configuration/logging directory
913 // NOTE: filename is overwritten and must be big enough to hold full path!
914 int getfullpath_cfg (char *filename);
915 int getfullpath_log (char *filename);
917 // A safer replacement for strncpy which ensures \0-termination
918 char * mz_strncpy(char *dest, const char *src, size_t n);
920 // Helper function to count the number of arguments
921 // in the Mausezahn argument string (comma separated args)
922 // RETURN VALUE: Number of arguments
923 int number_of_args (char *str);
925 int arptable_add(struct device_struct *dev,
926 u_int8_t *sa,
927 u_int8_t *da,
928 u_int8_t *smac,
929 u_int8_t *sip,
930 u_int32_t sec,
931 u_int32_t nsec);
933 // Validate ARP requests
934 int arpwatch(struct device_struct *dev,
935 u_int8_t *sa,
936 u_int8_t *da,
937 u_int8_t *smac,
938 u_int8_t *sip,
939 u_int8_t *tmac,
940 u_int8_t *tip,
941 u_int32_t sec,
942 u_int32_t nsec);
945 #endif