]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
cleanup: reindented C source with GNU indent 189/head
authorMatt Kimball <matt.kimball@gmail.com>
Sat, 4 Feb 2017 21:25:23 +0000 (13:25 -0800)
committerMatt Kimball <matt.kimball@gmail.com>
Sat, 4 Feb 2017 21:25:23 +0000 (13:25 -0800)
Ran the C source through:

    indent --k-and-r-style --no-tabs --break-function-decl-args

48 files changed:
packet/cmdparse.c
packet/cmdparse.h
packet/command.c
packet/command.h
packet/command_cygwin.c
packet/command_cygwin.h
packet/command_unix.c
packet/command_unix.h
packet/construct_unix.c
packet/deconstruct_unix.c
packet/deconstruct_unix.h
packet/packet.c
packet/probe.c
packet/probe.h
packet/probe_cygwin.c
packet/probe_cygwin.h
packet/probe_unix.c
packet/probe_unix.h
packet/protocols.h
packet/timeval.c
packet/wait_cygwin.c
packet/wait_unix.c
ui/asn.c
ui/asn.h
ui/cmdpipe.c
ui/cmdpipe.h
ui/curses.c
ui/display.c
ui/display.h
ui/dns.c
ui/dns.h
ui/gtk.c
ui/mtr-curses.h
ui/mtr-gtk.h
ui/mtr.c
ui/mtr.h
ui/net.c
ui/net.h
ui/raw.c
ui/raw.h
ui/report.c
ui/report.h
ui/select.c
ui/select.h
ui/split.c
ui/split.h
ui/utils.c
ui/utils.h

index e01b03fd61e1d9d3186035ff4114ca6efde4d2ce..1084714be88c5fffb67a5ad35d5c22f8053f31c8 100644 (file)
@@ -41,7 +41,7 @@ int tokenize_command(
 
     for (i = 0; command_string[i]; i++) {
         if (on_space) {
-            if (!isspace((unsigned char)command_string[i])) {
+            if (!isspace((unsigned char) command_string[i])) {
                 /*  Take care not to exceed the token array length  */
                 if (token_count >= max_tokens) {
                     return -1;
@@ -51,7 +51,7 @@ int tokenize_command(
                 on_space = 0;
             }
         } else {
-            if (isspace((unsigned char)command_string[i])) {
+            if (isspace((unsigned char) command_string[i])) {
                 command_string[i] = 0;
                 on_space = 1;
             }
@@ -83,7 +83,8 @@ int parse_command(
     memset(command, 0, sizeof(struct command_t));
 
     /*  Tokenize the string using whitespace  */
-    token_count = tokenize_command(tokens, MAX_COMMAND_TOKENS, command_string);
+    token_count =
+        tokenize_command(tokens, MAX_COMMAND_TOKENS, command_string);
     if (token_count < 2) {
         errno = EINVAL;
         return -1;
@@ -99,9 +100,9 @@ int parse_command(
     command->command_name = tokens[1];
 
     /*
-        The tokens beyond the command name are expected to be in
-        name, value pairs.
-    */
+       The tokens beyond the command name are expected to be in
+       name, value pairs.
+     */
     i = 2;
     command->argument_count = 0;
     while (i < token_count) {
index 9b9c3906e152378ce0472d21959796131314cb50..f52e48fb59eaecae8872c003b1443fa834cf3c52 100644 (file)
@@ -25,9 +25,8 @@ enum {
 };
 
 /*  Parsed commands, or command replies, ready for semantic interpretation  */
-struct command_t
-{
-       /*  A unique value for matching command requests with replies  */
+struct command_t {
+    /*  A unique value for matching command requests with replies  */
     int token;
 
     /*  Text indiciating the command type, or reply type  */
index 2fa9331b7bd422f23690f7e32c63902a0c2a3190..42b9a52f0feba64a48281e2649f69eeb777a608e 100644 (file)
@@ -114,7 +114,6 @@ const char *check_support(
     if (!strcmp(feature, "tcp")) {
         return check_protocol_support(net_state, IPPROTO_TCP);
     }
-
 #ifdef IPPROTO_SCTP
     if (!strcmp(feature, "sctp")) {
         return check_protocol_support(net_state, IPPROTO_SCTP);
@@ -216,9 +215,9 @@ bool decode_probe_argument(
         }
 
         /*
-            Don't allow using a local port which requires
-            privileged binding.
-        */
+           Don't allow using a local port which requires
+           privileged binding.
+         */
         if (param->local_port < 1024) {
             param->local_port = 0;
             return false;
@@ -288,17 +287,15 @@ bool validate_probe_parameters(
     struct probe_param_t *param)
 {
     if (!is_ip_version_supported(net_state, param->ip_version)) {
-        printf(
-            "%d invalid-argument reason ip-version-not-supported\n",
-            param->command_token);
+        printf("%d invalid-argument reason ip-version-not-supported\n",
+               param->command_token);
 
         return false;
     }
 
     if (!is_protocol_supported(net_state, param->protocol)) {
-        printf(
-            "%d invalid-argument reason protocol-not-supported\n",
-            param->command_token);
+        printf("%d invalid-argument reason protocol-not-supported\n",
+               param->command_token);
 
         return false;
     }
@@ -386,24 +383,26 @@ void dispatch_buffer_commands(
         end_of_command = index(buffer->incoming_buffer, '\n');
         if (end_of_command == NULL) {
             /*
-                No newlines found, so any data we've read so far is
-                not yet complete.
-            */
+               No newlines found, so any data we've read so far is
+               not yet complete.
+             */
             break;
         }
 
         command_length = end_of_command - buffer->incoming_buffer;
-        remaining_count = buffer->incoming_read_position - command_length - 1;
+        remaining_count =
+            buffer->incoming_read_position - command_length - 1;
 
         /*  Copy the completed command  */
         memmove(full_command, buffer->incoming_buffer, command_length);
         full_command[command_length] = 0;
 
         /*
-            Free the space used by the completed command by advancing the
-            remaining requests within the buffer.
-        */
-        memmove(buffer->incoming_buffer, end_of_command + 1, remaining_count);
+           Free the space used by the completed command by advancing the
+           remaining requests within the buffer.
+         */
+        memmove(buffer->incoming_buffer, end_of_command + 1,
+                remaining_count);
         buffer->incoming_read_position -= command_length + 1;
 
         if (parse_command(&command, full_command)) {
@@ -416,10 +415,10 @@ void dispatch_buffer_commands(
 
     if (buffer->incoming_read_position >= COMMAND_BUFFER_SIZE - 1) {
         /*
-            If we've filled the buffer without a complete command, the
-            only thing we can do is discard what we've read and hope that 
-            new data is better formatted.
-        */
+           If we've filled the buffer without a complete command, the
+           only thing we can do is discard what we've read and hope that 
+           new data is better formatted.
+         */
         printf("0 command-buffer-overflow\n");
         buffer->incoming_read_position = 0;
     }
index 03cb30b2b958b8655debcc46415fbcec0e50002e..a1fe0251bc654dd485a35f588f119287683f0be4 100644 (file)
@@ -31,9 +31,8 @@
 #endif
 
 /*  Storage for incoming commands, prior to command parsing  */
-struct command_buffer_t
-{
-       /*  The file descriptor of the incoming command stream  */
+struct command_buffer_t {
+    /*  The file descriptor of the incoming command stream  */
     int command_stream;
 
     /*  Storage to read commands into  */
index 7b32eb3511f52843a469a641ca0a1ddb63649404..5e12fd6fefae8a173be8b35a33275b0e5c2accbd 100644 (file)
@@ -30,16 +30,16 @@ static
 void CALLBACK finish_read_command(
     DWORD status,
     DWORD size_read,
-    OVERLAPPED *overlapped)
+    OVERLAPPED * overlapped)
 {
     struct command_buffer_t *buffer;
     char *read_position;
 
     /*
-        hEvent is unusuaed by ReadFileEx, so we use it to pass
-        our command_buffer structure.
-    */
-    buffer = (struct command_buffer_t *)overlapped->hEvent;
+       hEvent is unusuaed by ReadFileEx, so we use it to pass
+       our command_buffer structure.
+     */
+    buffer = (struct command_buffer_t *) overlapped->hEvent;
 
     if (status) {
         /*  When the stream is closed ERROR_BROKEN_PIPE will be the result  */
@@ -53,7 +53,8 @@ void CALLBACK finish_read_command(
     }
 
     /*  Copy from the overlapped I/O buffer to the incoming command buffer  */
-    read_position = &buffer->incoming_buffer[buffer->incoming_read_position];
+    read_position =
+        &buffer->incoming_buffer[buffer->incoming_read_position];
     memcpy(read_position, buffer->platform.overlapped_buffer, size_read);
 
     /*  Account for the newly read data  */
@@ -67,17 +68,18 @@ void CALLBACK finish_read_command(
 */
 static
 void CALLBACK empty_apc(
-    ULONG *param)
+    ULONG * param)
 {
 }
 
 /*  Wake from the next alertable wait without waiting for newly read data  */
 static
-void queue_empty_apc(void)
+void queue_empty_apc(
+    void)
 {
-    if (QueueUserAPC((PAPCFUNC)empty_apc, GetCurrentThread(), 0) == 0) {
-        fprintf(
-            stderr, "Unexpected QueueUserAPC failure %d\n", GetLastError());
+    if (QueueUserAPC((PAPCFUNC) empty_apc, GetCurrentThread(), 0) == 0) {
+        fprintf(stderr, "Unexpected QueueUserAPC failure %d\n",
+                GetLastError());
         exit(EXIT_FAILURE);
     }
 }
@@ -86,9 +88,8 @@ void queue_empty_apc(void)
 void start_read_command(
     struct command_buffer_t *buffer)
 {
-    HANDLE command_stream =
-        (HANDLE)get_osfhandle(buffer->command_stream);
-    int space_remaining = 
+    HANDLE command_stream = (HANDLE) get_osfhandle(buffer->command_stream);
+    int space_remaining =
         COMMAND_BUFFER_SIZE - buffer->incoming_read_position - 1;
     int err;
 
@@ -98,24 +99,25 @@ void start_read_command(
     }
 
     memset(&buffer->platform.overlapped, 0, sizeof(OVERLAPPED));
-    buffer->platform.overlapped.hEvent = (HANDLE)buffer;
+    buffer->platform.overlapped.hEvent = (HANDLE) buffer;
 
-    if (!ReadFileEx(
-        command_stream, buffer->platform.overlapped_buffer, space_remaining,
-        &buffer->platform.overlapped, finish_read_command)) {
+    if (!ReadFileEx
+        (command_stream, buffer->platform.overlapped_buffer,
+         space_remaining, &buffer->platform.overlapped,
+         finish_read_command)) {
 
         err = GetLastError();
 
         if (err == ERROR_BROKEN_PIPE) {
             /*  If the command stream has been closed, we need to wake from
-                the next altertable wait to exit the main loop  */
+               the next altertable wait to exit the main loop  */
             buffer->platform.pipe_open = false;
             queue_empty_apc();
 
             return;
         } else if (err != WAIT_IO_COMPLETION) {
-            fprintf(
-                stderr, "Unexpected ReadFileEx failure %d\n", GetLastError());
+            fprintf(stderr, "Unexpected ReadFileEx failure %d\n",
+                    GetLastError());
             exit(EXIT_FAILURE);
         }
     }
index 9a63ebadb7d70abd93167e1dcc6921176165433a..92244682ab03ecb271fe0bfa4adc53dc57d44518 100644 (file)
@@ -30,9 +30,8 @@
 */
 
 /*  Overlapped I/O manament for Windows command buffer reads  */
-struct command_buffer_platform_t
-{
-       /*  true if an overlapped I/O read is active  */
+struct command_buffer_platform_t {
+    /*  true if an overlapped I/O read is active  */
     bool read_active;
 
     /*  true if the command pipe is still open  */
index 917857725b67c34f6bf7b879578999679f4c0a79..f6d20aaf4781af21cdda5a0c343cc59708dcba10 100644 (file)
@@ -66,8 +66,7 @@ int read_commands(
     read_count = read(command_stream, read_position, space_remaining);
 
     /*  If the command stream has been closed, read will return zero.  */
-    if (read_count == 0)
-    {
+    if (read_count == 0) {
         errno = EPIPE;
         return -1;
     }
index 841874763d21ab92e1904b8aa09e2aee8ed7cd84..ab897260195e833d07794587f06087e223ea7080 100644 (file)
@@ -20,8 +20,7 @@
 #define COMMAND_UNIX_H
 
 /*  No platform specific data is required for Unix command streams  */
-struct command_buffer_platform_t
-{
+struct command_buffer_platform_t {
 };
 
 #endif
index 6895879f6376fd1f6fe01e1ea9163e0e35f3b048..b0f46795117a142821b223c2158809831dbbf863 100644 (file)
@@ -27,8 +27,7 @@
 #include "protocols.h"
 
 /*  A source of data for computing a checksum  */
-struct checksum_source_t
-{
+struct checksum_source_t {
     const void *data;
     size_t size;
 };
@@ -39,7 +38,7 @@ uint16_t compute_checksum(
     const void *packet,
     int size)
 {
-    const uint8_t *packet_bytes = (uint8_t *)packet;
+    const uint8_t *packet_bytes = (uint8_t *) packet;
     uint32_t sum = 0;
     int i;
 
@@ -52,17 +51,17 @@ uint16_t compute_checksum(
     }
 
     /*
-        Sums which overflow a 16-bit value have the high bits
-        added back into the low 16 bits.
-    */
+       Sums which overflow a 16-bit value have the high bits
+       added back into the low 16 bits.
+     */
     while (sum >> 16) {
         sum = (sum >> 16) + (sum & 0xffff);
     }
 
     /*
-        The value stored is the one's complement of the
-        mathematical sum.
-    */
+       The value stored is the one's complement of the
+       mathematical sum.
+     */
     return (~sum & 0xffff);
 }
 
@@ -92,10 +91,10 @@ void construct_addr_port(
     memcpy(addr_with_port, addr, sizeof(struct sockaddr_storage));
 
     if (addr->ss_family == AF_INET6) {
-        addr6 = (struct sockaddr_in6 *)addr_with_port;
+        addr6 = (struct sockaddr_in6 *) addr_with_port;
         addr6->sin6_port = htons(port);
     } else {
-        addr4 = (struct sockaddr_in *)addr_with_port;
+        addr4 = (struct sockaddr_in *) addr_with_port;
         addr4->sin_port = htons(port);
     }
 }
@@ -111,10 +110,10 @@ void construct_ip4_header(
     const struct probe_param_t *param)
 {
     struct IPHeader *ip;
-    struct sockaddr_in *srcaddr4 = (struct sockaddr_in *)srcaddr;
-    struct sockaddr_in *destaddr4 = (struct sockaddr_in *)destaddr;
+    struct sockaddr_in *srcaddr4 = (struct sockaddr_in *) srcaddr;
+    struct sockaddr_in *destaddr4 = (struct sockaddr_in *) destaddr;
 
-    ip = (struct IPHeader *)&packet_buffer[0];
+    ip = (struct IPHeader *) &packet_buffer[0];
 
     memset(ip, 0, sizeof(struct IPHeader));
 
@@ -139,7 +138,7 @@ void construct_icmp4_header(
     struct ICMPHeader *icmp;
     int icmp_size;
 
-    icmp = (struct ICMPHeader *)&packet_buffer[sizeof(struct IPHeader)];
+    icmp = (struct ICMPHeader *) &packet_buffer[sizeof(struct IPHeader)];
     icmp_size = packet_size - sizeof(struct IPHeader);
 
     memset(icmp, 0, sizeof(struct ICMPHeader));
@@ -161,7 +160,7 @@ int construct_icmp6_packet(
 {
     struct ICMPHeader *icmp;
 
-    icmp = (struct ICMPHeader *)packet_buffer;
+    icmp = (struct ICMPHeader *) packet_buffer;
 
     memset(icmp, 0, sizeof(struct ICMPHeader));
 
@@ -225,7 +224,7 @@ void construct_udp4_header(
     struct UDPHeader *udp;
     int udp_size;
 
-    udp = (struct UDPHeader *)&packet_buffer[sizeof(struct IPHeader)];
+    udp = (struct UDPHeader *) &packet_buffer[sizeof(struct IPHeader)];
     udp_size = packet_size - sizeof(struct IPHeader);
 
     memset(udp, 0, sizeof(struct UDPHeader));
@@ -247,7 +246,7 @@ int construct_udp6_packet(
     struct UDPHeader *udp;
     int udp_size;
 
-    udp = (struct UDPHeader *)packet_buffer;
+    udp = (struct UDPHeader *) packet_buffer;
     udp_size = packet_size;
 
     memset(udp, 0, sizeof(struct UDPHeader));
@@ -256,13 +255,12 @@ int construct_udp6_packet(
     udp->length = htons(udp_size);
 
     /*
-        Instruct the kernel to put the pseudoheader checksum into the
-        UDP header.
-    */
-    int chksum_offset = (char *)&udp->checksum - (char *)udp;
-    if (setsockopt(
-            udp_socket, IPPROTO_IPV6,
-            IPV6_CHECKSUM, &chksum_offset, sizeof(int))) {
+       Instruct the kernel to put the pseudoheader checksum into the
+       UDP header.
+     */
+    int chksum_offset = (char *) &udp->checksum - (char *) udp;
+    if (setsockopt(udp_socket, IPPROTO_IPV6,
+                   IPV6_CHECKSUM, &chksum_offset, sizeof(int))) {
         return -1;
     }
 
@@ -285,20 +283,18 @@ int set_stream_socket_options(
     /*  Allow binding to a local port previously in use  */
 #ifdef SO_REUSEPORT
     /*
-        FreeBSD wants SO_REUSEPORT in addition to SO_REUSEADDR to
-        bind to the same port
-    */
-    if (setsockopt(
-            stream_socket, SOL_SOCKET, SO_REUSEPORT,
-            &reuse, sizeof(int)) == -1) {
+       FreeBSD wants SO_REUSEPORT in addition to SO_REUSEADDR to
+       bind to the same port
+     */
+    if (setsockopt(stream_socket, SOL_SOCKET, SO_REUSEPORT,
+                   &reuse, sizeof(int)) == -1) {
 
         return -1;
     }
 #endif
 
-    if (setsockopt(
-            stream_socket, SOL_SOCKET, SO_REUSEADDR,
-            &reuse, sizeof(int)) == -1) {
+    if (setsockopt(stream_socket, SOL_SOCKET, SO_REUSEADDR,
+                   &reuse, sizeof(int)) == -1) {
 
         return -1;
     }
@@ -312,8 +308,8 @@ int set_stream_socket_options(
         opt = IP_TTL;
     }
 
-    if (setsockopt(
-            stream_socket, level, opt, &param->ttl, sizeof(int)) == -1) {
+    if (setsockopt(stream_socket, level, opt, &param->ttl, sizeof(int)) ==
+        -1) {
 
         return -1;
     }
@@ -327,18 +323,15 @@ int set_stream_socket_options(
         opt = IP_TOS;
     }
 
-    if (setsockopt(
-            stream_socket, level, opt,
-            &param->type_of_service, sizeof(int)) == -1) {
+    if (setsockopt(stream_socket, level, opt,
+                   &param->type_of_service, sizeof(int)) == -1) {
 
         return -1;
     }
-
 #ifdef SO_MARK
     if (param->routing_mark) {
-        if (setsockopt(
-                stream_socket, SOL_SOCKET,
-                SO_MARK, &param->routing_mark, sizeof(int))) {
+        if (setsockopt(stream_socket, SOL_SOCKET,
+                       SO_MARK, &param->routing_mark, sizeof(int))) {
             return -1;
         }
     }
@@ -389,11 +382,11 @@ int open_stream_socket(
     }
 
     /*
-        Bind to a known local port so we can identify which probe
-        causes a TTL expiration.
-    */
+       Bind to a known local port so we can identify which probe
+       causes a TTL expiration.
+     */
     construct_addr_port(&src_port_addr, src_sockaddr, port);
-    if (bind(stream_socket, (struct sockaddr *)&src_port_addr, addr_len)) {
+    if (bind(stream_socket, (struct sockaddr *) &src_port_addr, addr_len)) {
         close(stream_socket);
         return -1;
     }
@@ -407,8 +400,8 @@ int open_stream_socket(
 
     /*  Attempt a connection  */
     construct_addr_port(&dest_port_addr, dest_sockaddr, dest_port);
-    if (connect(
-            stream_socket, (struct sockaddr *)&dest_port_addr, addr_len)) {
+    if (connect
+        (stream_socket, (struct sockaddr *) &dest_port_addr, addr_len)) {
 
         /*  EINPROGRESS simply means the connection is in progress  */
         if (errno != EINPROGRESS) {
@@ -437,7 +430,6 @@ int compute_packet_size(
     if (param->protocol == IPPROTO_TCP) {
         return 0;
     }
-
 #ifdef IPPROTO_SCTP
     if (param->protocol == IPPROTO_SCTP) {
         return 0;
@@ -467,17 +459,17 @@ int compute_packet_size(
     }
 
     /*
-        If the requested size from send-probe is greater, extend the
-        packet size.
-    */
+       If the requested size from send-probe is greater, extend the
+       packet size.
+     */
     if (param->packet_size > packet_size) {
         packet_size = param->packet_size;
     }
 
     /*
-        Since we don't explicitly construct the IPv6 header, we
-        need to account for it in our transmitted size.
-    */
+       Since we don't explicitly construct the IPv6 header, we
+       need to account for it in our transmitted size.
+     */
     if (param->ip_version == 6) {
         packet_size -= sizeof(struct IP6Header);
     }
@@ -507,16 +499,15 @@ int construct_ip4_packet(
         is_stream_protocol = true;
 #endif
     } else {
-        construct_ip4_header(
-            net_state, packet_buffer, packet_size,
-            src_sockaddr, dest_sockaddr, param);
+        construct_ip4_header(net_state, packet_buffer, packet_size,
+                             src_sockaddr, dest_sockaddr, param);
 
         if (param->protocol == IPPROTO_ICMP) {
-            construct_icmp4_header(
-                net_state, sequence, packet_buffer, packet_size, param);
+            construct_icmp4_header(net_state, sequence, packet_buffer,
+                                   packet_size, param);
         } else if (param->protocol == IPPROTO_UDP) {
-            construct_udp4_header(
-                net_state, sequence, packet_buffer, packet_size, param);
+            construct_udp4_header(net_state, sequence, packet_buffer,
+                                  packet_size, param);
         } else {
             errno = EINVAL;
             return -1;
@@ -524,9 +515,9 @@ int construct_ip4_packet(
     }
 
     if (is_stream_protocol) {
-        send_socket = open_stream_socket(
-            net_state, param->protocol, sequence,
-            src_sockaddr, dest_sockaddr, param);
+        send_socket =
+            open_stream_socket(net_state, param->protocol, sequence,
+                               src_sockaddr, dest_sockaddr, param);
 
         if (send_socket == -1) {
             return -1;
@@ -537,20 +528,19 @@ int construct_ip4_packet(
     }
 
     /*
-        The routing mark requires CAP_NET_ADMIN, as opposed to the
-        CAP_NET_RAW which we are sometimes explicitly given.
-        If we don't have CAP_NET_ADMIN, this will fail, so we'll 
-        only set the mark if the user has explicitly requested it.
-
-        Unfortunately, this means that once the mark is set, it won't
-        be set on the socket again until a new mark is explicitly
-        specified.
-    */
+       The routing mark requires CAP_NET_ADMIN, as opposed to the
+       CAP_NET_RAW which we are sometimes explicitly given.
+       If we don't have CAP_NET_ADMIN, this will fail, so we'll 
+       only set the mark if the user has explicitly requested it.
+
+       Unfortunately, this means that once the mark is set, it won't
+       be set on the socket again until a new mark is explicitly
+       specified.
+     */
 #ifdef SO_MARK
     if (param->routing_mark) {
-        if (setsockopt(
-                send_socket, SOL_SOCKET,
-                SO_MARK, &param->routing_mark, sizeof(int))) {
+        if (setsockopt(send_socket, SOL_SOCKET,
+                       SO_MARK, &param->routing_mark, sizeof(int))) {
             return -1;
         }
     }
@@ -586,15 +576,15 @@ int construct_ip6_packet(
     } else if (param->protocol == IPPROTO_ICMP) {
         send_socket = net_state->platform.icmp6_send_socket;
 
-        if (construct_icmp6_packet(
-                net_state, sequence, packet_buffer, packet_size, param)) {
+        if (construct_icmp6_packet
+            (net_state, sequence, packet_buffer, packet_size, param)) {
             return -1;
         }
     } else if (param->protocol == IPPROTO_UDP) {
         send_socket = net_state->platform.udp6_send_socket;
 
-        if (construct_udp6_packet(
-                net_state, sequence, packet_buffer, packet_size, param)) {
+        if (construct_udp6_packet
+            (net_state, sequence, packet_buffer, packet_size, param)) {
             return -1;
         }
     } else {
@@ -603,9 +593,9 @@ int construct_ip6_packet(
     }
 
     if (is_stream_protocol) {
-        send_socket = open_stream_socket(
-            net_state, param->protocol, sequence,
-            src_sockaddr, dest_sockaddr, param);
+        send_socket =
+            open_stream_socket(net_state, param->protocol, sequence,
+                               src_sockaddr, dest_sockaddr, param);
 
         if (send_socket == -1) {
             return -1;
@@ -616,49 +606,46 @@ int construct_ip6_packet(
     }
 
     /*
-        Check the current socket address, and if it is the same
-        as the source address we intend, we will skip the bind.
-        This is to accomodate Solaris, which, as of Solaris 11.3,
-        will return an EINVAL error on bind if the socket is already
-        bound, even if the same address is used.
-    */
+       Check the current socket address, and if it is the same
+       as the source address we intend, we will skip the bind.
+       This is to accomodate Solaris, which, as of Solaris 11.3,
+       will return an EINVAL error on bind if the socket is already
+       bound, even if the same address is used.
+     */
     current_sockaddr_len = sizeof(struct sockaddr_in6);
-    if (getsockname(send_socket, (struct sockaddr *)&current_sockaddr,
-            &current_sockaddr_len) == 0) {
+    if (getsockname(send_socket, (struct sockaddr *) &current_sockaddr,
+                    &current_sockaddr_len) == 0) {
 
         if (memcmp(&current_sockaddr,
-                src_sockaddr, sizeof(struct sockaddr_in6)) == 0) {
+                   src_sockaddr, sizeof(struct sockaddr_in6)) == 0) {
             bind_send_socket = false;
         }
     }
 
     /*  Bind to our local address  */
     if (bind_send_socket) {
-        if (bind(send_socket, (struct sockaddr *)src_sockaddr,
-                sizeof(struct sockaddr_in6))) {
+        if (bind(send_socket, (struct sockaddr *) src_sockaddr,
+                 sizeof(struct sockaddr_in6))) {
             return -1;
         }
     }
 
     /*  The traffic class in IPv6 is analagous to ToS in IPv4  */
-    if (setsockopt(
-            send_socket, IPPROTO_IPV6,
-            IPV6_TCLASS, &param->type_of_service, sizeof(int))) {
+    if (setsockopt(send_socket, IPPROTO_IPV6,
+                   IPV6_TCLASS, &param->type_of_service, sizeof(int))) {
         return -1;
     }
 
     /*  Set the time-to-live  */
-    if (setsockopt(
-            send_socket, IPPROTO_IPV6,
-            IPV6_UNICAST_HOPS, &param->ttl, sizeof(int))) {
+    if (setsockopt(send_socket, IPPROTO_IPV6,
+                   IPV6_UNICAST_HOPS, &param->ttl, sizeof(int))) {
         return -1;
     }
-
 #ifdef SO_MARK
     if (param->routing_mark) {
-        if (setsockopt(
-                send_socket,
-                SOL_SOCKET, SO_MARK, &param->routing_mark, sizeof(int))) {
+        if (setsockopt(send_socket,
+                       SOL_SOCKET, SO_MARK, &param->routing_mark,
+                       sizeof(int))) {
             return -1;
         }
     }
@@ -693,17 +680,15 @@ int construct_packet(
     memset(packet_buffer, param->bit_pattern, packet_size);
 
     if (param->ip_version == 6) {
-        if (construct_ip6_packet(
-                net_state, packet_socket, sequence,
-                packet_buffer, packet_size,
-                src_sockaddr, dest_sockaddr, param)) {
+        if (construct_ip6_packet(net_state, packet_socket, sequence,
+                                 packet_buffer, packet_size,
+                                 src_sockaddr, dest_sockaddr, param)) {
             return -1;
         }
     } else if (param->ip_version == 4) {
-        if (construct_ip4_packet(
-                net_state, packet_socket, sequence,
-                packet_buffer, packet_size,
-                src_sockaddr, dest_sockaddr, param)) {
+        if (construct_ip4_packet(net_state, packet_socket, sequence,
+                                 packet_buffer, packet_size,
+                                 src_sockaddr, dest_sockaddr, param)) {
             return -1;
         }
     } else {
index bdb7dee6b0440844bcabc00cf1453691c37fa63b..ce889ca4add8fb54950f5139181374f2d4c8595d 100644 (file)
@@ -49,9 +49,8 @@ void find_and_receive_probe(
         return;
     }
 
-    receive_probe(
-        net_state, probe, icmp_type,
-        remote_addr, timestamp, mpls_count, mpls);
+    receive_probe(net_state, probe, icmp_type,
+                  remote_addr, timestamp, mpls_count, mpls);
 }
 
 /*
@@ -82,9 +81,8 @@ void handle_inner_udp_packet(
     }
 
     if (probe != NULL) {
-        receive_probe(
-            net_state, probe, icmp_result,
-            remote_addr, timestamp, mpls_count, mpls);
+        receive_probe(net_state, probe, icmp_result,
+                      remote_addr, timestamp, mpls_count, mpls);
     }
 }
 
@@ -125,43 +123,42 @@ void handle_inner_ip4_packet(
             return;
         }
 
-        icmp = (struct ICMPHeader *)(ip + 1);
+        icmp = (struct ICMPHeader *) (ip + 1);
 
-        find_and_receive_probe(
-            net_state, remote_addr, timestamp, icmp_result,
-            IPPROTO_ICMP, icmp->id, icmp->sequence, mpls_count, mpls);
+        find_and_receive_probe(net_state, remote_addr, timestamp,
+                               icmp_result, IPPROTO_ICMP, icmp->id,
+                               icmp->sequence, mpls_count, mpls);
     } else if (ip->protocol == IPPROTO_UDP) {
         if (packet_length < ip_udp_size) {
             return;
         }
 
-        udp = (struct UDPHeader *)(ip + 1);
+        udp = (struct UDPHeader *) (ip + 1);
         udp_length = packet_length - sizeof(struct IPHeader);
 
-        handle_inner_udp_packet(
-            net_state, remote_addr, icmp_result, udp, udp_length,
-            timestamp, mpls_count, mpls);
+        handle_inner_udp_packet(net_state, remote_addr, icmp_result, udp,
+                                udp_length, timestamp, mpls_count, mpls);
     } else if (ip->protocol == IPPROTO_TCP) {
         if (packet_length < ip_tcp_size) {
             return;
         }
 
-        tcp = (struct TCPHeader *)(ip + 1);
+        tcp = (struct TCPHeader *) (ip + 1);
 
-        find_and_receive_probe(
-            net_state, remote_addr, timestamp, icmp_result,
-            IPPROTO_TCP, 0, tcp->srcport, mpls_count, mpls);
+        find_and_receive_probe(net_state, remote_addr, timestamp,
+                               icmp_result, IPPROTO_TCP, 0, tcp->srcport,
+                               mpls_count, mpls);
 #ifdef IPPROTO_SCTP
     } else if (ip->protocol == IPPROTO_SCTP) {
         if (packet_length < ip_sctp_size) {
             return;
         }
 
-        sctp = (struct SCTPHeader *)(ip + 1);
+        sctp = (struct SCTPHeader *) (ip + 1);
 
-        find_and_receive_probe(
-            net_state, remote_addr, timestamp, icmp_result,
-            IPPROTO_SCTP, 0, sctp->srcport, mpls_count, mpls);
+        find_and_receive_probe(net_state, remote_addr, timestamp,
+                               icmp_result, IPPROTO_SCTP, 0, sctp->srcport,
+                               mpls_count, mpls);
 #endif
     }
 }
@@ -202,42 +199,41 @@ void handle_inner_ip6_packet(
             return;
         }
 
-        icmp = (struct ICMPHeader *)(ip + 1);
+        icmp = (struct ICMPHeader *) (ip + 1);
 
-        find_and_receive_probe(
-            net_state, remote_addr, timestamp, icmp_result,
-            IPPROTO_ICMP, icmp->id, icmp->sequence, mpls_count, mpls);
+        find_and_receive_probe(net_state, remote_addr, timestamp,
+                               icmp_result, IPPROTO_ICMP, icmp->id,
+                               icmp->sequence, mpls_count, mpls);
     } else if (ip->protocol == IPPROTO_UDP) {
         if (packet_length < ip_udp_size) {
             return;
         }
 
-        udp = (struct UDPHeader *)(ip + 1);
+        udp = (struct UDPHeader *) (ip + 1);
         udp_length = packet_length - sizeof(struct IP6Header);
 
-        handle_inner_udp_packet(
-            net_state, remote_addr, icmp_result, udp, udp_length,
-            timestamp, mpls_count, mpls);
+        handle_inner_udp_packet(net_state, remote_addr, icmp_result, udp,
+                                udp_length, timestamp, mpls_count, mpls);
     } else if (ip->protocol == IPPROTO_TCP) {
         if (packet_length < ip_tcp_size) {
             return;
         }
 
-        tcp = (struct TCPHeader *)(ip + 1);
-        find_and_receive_probe(
-            net_state, remote_addr, timestamp, icmp_result,
-            IPPROTO_TCP, 0, tcp->srcport, mpls_count, mpls);
+        tcp = (struct TCPHeader *) (ip + 1);
+        find_and_receive_probe(net_state, remote_addr, timestamp,
+                               icmp_result, IPPROTO_TCP, 0, tcp->srcport,
+                               mpls_count, mpls);
 #ifdef IPPROTO_SCTP
     } else if (ip->protocol == IPPROTO_SCTP) {
         if (packet_length < ip_sctp_size) {
             return;
         }
 
-        sctp = (struct SCTPHeader *)(ip + 1);
+        sctp = (struct SCTPHeader *) (ip + 1);
 
-        find_and_receive_probe(
-            net_state, remote_addr, timestamp, icmp_result,
-            IPPROTO_SCTP, 0, sctp->srcport, mpls_count, mpls);
+        find_and_receive_probe(net_state, remote_addr, timestamp,
+                               icmp_result, IPPROTO_SCTP, 0, sctp->srcport,
+                               mpls_count, mpls);
 #endif
     }
 }
@@ -260,7 +256,7 @@ int decode_mpls_object(
     label_bytes = obj_len - sizeof(struct ICMPExtensionObject);
     labels_present = label_bytes / sizeof(struct ICMPExtMPLSLabel);
 
-    ext_mpls = (struct ICMPExtMPLSLabel *)(icmp_obj + 1);
+    ext_mpls = (struct ICMPExtMPLSLabel *) (icmp_obj + 1);
     for (i = 0; i < mpls_count && i < labels_present; i++) {
         ext_label = &ext_mpls[i];
         label = &mpls[i];
@@ -269,8 +265,7 @@ int decode_mpls_object(
 
         label->label =
             ext_label->label[0] << 12 |
-            ext_label->label[1] << 4 |
-            ext_label->label[2] >> 4;
+            ext_label->label[1] << 4 | ext_label->label[2] >> 4;
         label->experimental_use = (ext_label->label[2] & 0x0E) >> 1;
         label->bottom_of_stack = ext_label->label[2] & 0x01;
         label->ttl = ext_label->ttl;
@@ -297,12 +292,11 @@ int decode_mpls_labels(
     int remaining_size;
     int obj_len;
 
-    if (packet_length < icmp_orig_icmp_ext_size)
-    {
+    if (packet_length < icmp_orig_icmp_ext_size) {
         return 0;
     }
 
-    inner_packet = (char *)(icmp + 1);
+    inner_packet = (char *) (icmp + 1);
     icmp_ext = (struct ICMPExtensionHeader *)
         (inner_packet + ICMP_ORIGINAL_DATAGRAM_MIN_SIZE);
 
@@ -311,15 +305,14 @@ int decode_mpls_labels(
     }
 
     remaining_size = packet_length - icmp_orig_icmp_ext_size;
-    icmp_object_bytes = (char *)(icmp_ext + 1);
+    icmp_object_bytes = (char *) (icmp_ext + 1);
 
     /*
-        Iterate through the chain of extension objects, looking for
-        an MPLS label extension.
-    */
-    while (remaining_size >= sizeof(struct ICMPExtensionObject))
-    {
-        icmp_obj = (struct ICMPExtensionObject *)icmp_object_bytes;
+       Iterate through the chain of extension objects, looking for
+       an MPLS label extension.
+     */
+    while (remaining_size >= sizeof(struct ICMPExtensionObject)) {
+        icmp_obj = (struct ICMPExtensionObject *) icmp_object_bytes;
         obj_len = ntohs(icmp_obj->len);
 
         if (obj_len > remaining_size) {
@@ -330,7 +323,7 @@ int decode_mpls_labels(
         }
 
         if (icmp_obj->classnum == ICMP_EXT_MPLS_CLASSNUM &&
-                icmp_obj->ctype == ICMP_EXT_MPLS_CTYPE) {
+            icmp_obj->ctype == ICMP_EXT_MPLS_CTYPE) {
 
             return decode_mpls_object(icmp_obj, obj_len, mpls, mpls_count);
         }
@@ -361,49 +354,46 @@ void handle_received_icmp4_packet(
     int mpls_count;
     struct mpls_label_t mpls[MAX_MPLS_LABELS];
 
-    mpls_count = decode_mpls_labels(
-        icmp, packet_length, mpls, MAX_MPLS_LABELS);
+    mpls_count =
+        decode_mpls_labels(icmp, packet_length, mpls, MAX_MPLS_LABELS);
 
     /*  If we get an echo reply, our probe reached the destination host  */
     if (icmp->type == ICMP_ECHOREPLY) {
-        find_and_receive_probe(
-            net_state, remote_addr, timestamp,
-            ICMP_ECHOREPLY, IPPROTO_ICMP, icmp->id, icmp->sequence,
-            mpls_count, mpls);
+        find_and_receive_probe(net_state, remote_addr, timestamp,
+                               ICMP_ECHOREPLY, IPPROTO_ICMP, icmp->id,
+                               icmp->sequence, mpls_count, mpls);
     }
 
     if (packet_length < icmp_ip_size) {
         return;
     }
-    inner_ip = (struct IPHeader *)(icmp + 1);
+    inner_ip = (struct IPHeader *) (icmp + 1);
 
     /*
-        If we get a time exceeded, we got a response from an intermediate
-        host along the path to our destination.
-    */
+       If we get a time exceeded, we got a response from an intermediate
+       host along the path to our destination.
+     */
     if (icmp->type == ICMP_TIME_EXCEEDED) {
         /*
-            The IP packet inside the ICMP response contains our original
-            IP header.  That's where we can get our original ID and
-            sequence number.
-        */
-        handle_inner_ip4_packet(
-            net_state, remote_addr,
-            ICMP_TIME_EXCEEDED, inner_ip, inner_size, timestamp,
-            mpls_count, mpls);
+           The IP packet inside the ICMP response contains our original
+           IP header.  That's where we can get our original ID and
+           sequence number.
+         */
+        handle_inner_ip4_packet(net_state, remote_addr,
+                                ICMP_TIME_EXCEEDED, inner_ip, inner_size,
+                                timestamp, mpls_count, mpls);
     }
 
     if (icmp->type == ICMP_DEST_UNREACH) {
         /*
-            We'll get a ICMP_PORT_UNREACH when a non-ICMP probe
-            reaches its final destination.  (Assuming that port isn't
-            open on the destination host.)
-        */
+           We'll get a ICMP_PORT_UNREACH when a non-ICMP probe
+           reaches its final destination.  (Assuming that port isn't
+           open on the destination host.)
+         */
         if (icmp->code == ICMP_PORT_UNREACH) {
-            handle_inner_ip4_packet(
-                net_state, remote_addr,
-                ICMP_ECHOREPLY, inner_ip, inner_size, timestamp,
-                mpls_count, mpls);
+            handle_inner_ip4_packet(net_state, remote_addr,
+                                    ICMP_ECHOREPLY, inner_ip, inner_size,
+                                    timestamp, mpls_count, mpls);
         }
     }
 }
@@ -428,33 +418,31 @@ void handle_received_icmp6_packet(
     int mpls_count;
     struct mpls_label_t mpls[MAX_MPLS_LABELS];
 
-    mpls_count = decode_mpls_labels(
-        icmp, packet_length, mpls, MAX_MPLS_LABELS);
+    mpls_count =
+        decode_mpls_labels(icmp, packet_length, mpls, MAX_MPLS_LABELS);
 
     if (icmp->type == ICMP6_ECHOREPLY) {
-        find_and_receive_probe(
-            net_state, remote_addr, timestamp, ICMP_ECHOREPLY,
-            IPPROTO_ICMP, icmp->id, icmp->sequence, mpls_count, mpls);
+        find_and_receive_probe(net_state, remote_addr, timestamp,
+                               ICMP_ECHOREPLY, IPPROTO_ICMP, icmp->id,
+                               icmp->sequence, mpls_count, mpls);
     }
 
     if (packet_length < icmp_ip_size) {
         return;
     }
-    inner_ip = (struct IP6Header *)(icmp + 1);
+    inner_ip = (struct IP6Header *) (icmp + 1);
 
     if (icmp->type == ICMP6_TIME_EXCEEDED) {
-        handle_inner_ip6_packet(
-            net_state, remote_addr,
-            ICMP_TIME_EXCEEDED, inner_ip, inner_size, timestamp,
-            mpls_count, mpls);
+        handle_inner_ip6_packet(net_state, remote_addr,
+                                ICMP_TIME_EXCEEDED, inner_ip, inner_size,
+                                timestamp, mpls_count, mpls);
     }
 
     if (icmp->type == ICMP6_DEST_UNREACH) {
         if (icmp->code == ICMP6_PORT_UNREACH) {
-            handle_inner_ip6_packet(
-                net_state, remote_addr,
-                ICMP_ECHOREPLY, inner_ip, inner_size, timestamp,
-                mpls_count, mpls);
+            handle_inner_ip6_packet(net_state, remote_addr,
+                                    ICMP_ECHOREPLY, inner_ip, inner_size,
+                                    timestamp, mpls_count, mpls);
         }
     }
 }
@@ -482,16 +470,16 @@ void handle_received_ip4_packet(
         return;
     }
 
-    ip = (struct IPHeader *)packet;
+    ip = (struct IPHeader *) packet;
     if (ip->protocol != IPPROTO_ICMP) {
         return;
     }
 
-    icmp = (struct ICMPHeader *)(ip + 1);
+    icmp = (struct ICMPHeader *) (ip + 1);
     icmp_length = packet_length - sizeof(struct IPHeader);
 
-    handle_received_icmp4_packet(
-        net_state, remote_addr, icmp, icmp_length, timestamp);
+    handle_received_icmp4_packet(net_state, remote_addr, icmp, icmp_length,
+                                 timestamp);
 }
 
 /*
@@ -508,8 +496,8 @@ void handle_received_ip6_packet(
 {
     const struct ICMPHeader *icmp;
 
-    icmp = (struct ICMPHeader *)packet;
+    icmp = (struct ICMPHeader *) packet;
 
-    handle_received_icmp6_packet(
-        net_state, remote_addr, icmp, packet_length, timestamp);
+    handle_received_icmp6_packet(net_state, remote_addr, icmp,
+                                 packet_length, timestamp);
 }
index 33dd0ec7d22bc133baeda3b5a00e83037deb2e63..69186cd625292e835b3285cc3bad0f4cac47505b 100644 (file)
 
 #include "probe.h"
 
-typedef void (*received_packet_func_t)(
-    struct net_state_t *net_state,
-    const struct sockaddr_storage *remote_addr,
+typedef void (
+    *received_packet_func_t) (
+    struct net_state_t * net_state,
+    const struct sockaddr_storage * remote_addr,
     const void *packet,
     int packet_length,
-    struct timeval *timestamp);
+    struct timeval * timestamp);
 
 void handle_received_ip4_packet(
     struct net_state_t *net_state,
index b09f36f883a80237311c188edd717cdf53f11a59..f32f729997ee8ff8f4dc44839641042a01352343 100644 (file)
 #include <unistd.h>
 
 #ifdef HAVE_LIBCAP
-#   include <sys/capability.h>
+#include <sys/capability.h>
 #endif
 
 #include "wait.h"
 
 /*  Drop SUID privileges.  To be used after accquiring raw sockets.  */
 static
-int drop_elevated_permissions(void)
+int drop_elevated_permissions(
+    void)
 {
 #ifdef HAVE_LIBCAP
     cap_t cap;
@@ -48,9 +49,9 @@ int drop_elevated_permissions(void)
     }
 
     /*
-        Drop all process capabilities.
-        This will revoke anything granted by a commandline 'setcap'
-    */
+       Drop all process capabilities.
+       This will revoke anything granted by a commandline 'setcap'
+     */
 #ifdef HAVE_LIBCAP
     cap = cap_get_proc();
     if (cap == NULL) {
@@ -76,10 +77,10 @@ int main(
     struct net_state_t net_state;
 
     /*
-        To minimize security risk, the only thing done prior to 
-        dropping SUID should be opening the network state for
-        raw sockets.
-    */
+       To minimize security risk, the only thing done prior to 
+       dropping SUID should be opening the network state for
+       raw sockets.
+     */
     init_net_state_privileged(&net_state);
     if (drop_elevated_permissions()) {
         perror("Unable to drop elevated permissions");
@@ -92,24 +93,23 @@ int main(
     command_pipe_open = true;
 
     /*
-        Dispatch commands and respond to probe replies until the
-        command stream is closed.
-    */
+       Dispatch commands and respond to probe replies until the
+       command stream is closed.
+     */
     while (true) {
         /*  Ensure any responses are written before waiting  */
         fflush(stdout);
         wait_for_activity(&command_buffer, &net_state);
 
         /*
-            Receive replies first so that the timestamps are as
-            close to the response arrival time as possible.
-        */
+           Receive replies first so that the timestamps are as
+           close to the response arrival time as possible.
+         */
         receive_replies(&net_state);
 
         if (command_pipe_open) {
             if (read_commands(&command_buffer)) {
-                if (errno == EPIPE)
-                {
+                if (errno == EPIPE) {
                     command_pipe_open = false;
                 }
             }
@@ -118,15 +118,15 @@ int main(
         check_probe_timeouts(&net_state);
 
         /*
-            Dispatch commands late so that the window between probe
-            departure and arriving replies is as small as possible.
-        */
+           Dispatch commands late so that the window between probe
+           departure and arriving replies is as small as possible.
+         */
         dispatch_buffer_commands(&command_buffer, &net_state);
 
         /*
-            If the command pipe has been closed, exit after all
-            in-flight probes have reported their status.
-        */
+           If the command pipe has been closed, exit after all
+           in-flight probes have reported their status.
+         */
         if (!command_pipe_open) {
             if (net_state.outstanding_probe_count == 0) {
                 break;
index 31f47f3c9a425eae84f71c7793c2434fe0e3e956..34ff368467f78722e8bcfa06ecbc3da98356bab7 100644 (file)
@@ -51,7 +51,7 @@ int decode_address_string(
     }
 
     if (ip_version == 6) {
-        sockaddr6 = (struct sockaddr_in6 *)address;
+        sockaddr6 = (struct sockaddr_in6 *) address;
 
         if (inet_pton(AF_INET6, address_string, &addr6) != 1) {
             errno = EINVAL;
@@ -64,7 +64,7 @@ int decode_address_string(
         sockaddr6->sin6_addr = addr6;
         sockaddr6->sin6_scope_id = 0;
     } else if (ip_version == 4) {
-        sockaddr4 = (struct sockaddr_in *)address;
+        sockaddr4 = (struct sockaddr_in *) address;
 
         if (inet_pton(AF_INET, address_string, &addr4) != 1) {
             errno = EINVAL;
@@ -91,14 +91,14 @@ int resolve_probe_addresses(
     struct sockaddr_storage *dest_sockaddr,
     struct sockaddr_storage *src_sockaddr)
 {
-    if (decode_address_string(
-            param->ip_version, param->remote_address, dest_sockaddr)) {
+    if (decode_address_string
+        (param->ip_version, param->remote_address, dest_sockaddr)) {
         return -1;
     }
 
     if (param->local_address) {
-        if (decode_address_string(
-                param->ip_version, param->local_address, src_sockaddr)) {
+        if (decode_address_string
+            (param->ip_version, param->local_address, src_sockaddr)) {
             return -1;
         }
     } else {
@@ -132,7 +132,8 @@ struct probe_t *alloc_probe(
     platform_alloc_probe(net_state, probe);
 
     net_state->outstanding_probe_count++;
-    LIST_INSERT_HEAD(&net_state->outstanding_probes, probe, probe_list_entry);
+    LIST_INSERT_HEAD(&net_state->outstanding_probes, probe,
+                     probe_list_entry);
 
     return probe;
 }
@@ -163,14 +164,14 @@ struct probe_t *find_probe(
     struct probe_t *probe;
 
     /*
-        ICMP has room for an id to check against our process, but
-        UDP doesn't.
-    */
+       ICMP has room for an id to check against our process, but
+       UDP doesn't.
+     */
     if (protocol == IPPROTO_ICMP) {
         /*
-            If the ICMP id doesn't match our process ID, it wasn't a
-            probe generated by this process, so ignore it.
-        */
+           If the ICMP id doesn't match our process ID, it wasn't a
+           probe generated by this process, so ignore it.
+         */
         if (id != htons(getpid())) {
             return NULL;
         }
@@ -213,10 +214,9 @@ void format_mpls_string(
             append_pos += strlen(append_pos);
         }
 
-        snprintf(
-            append_pos, buffer_size, "%d,%d,%d,%d",
-            mpls->label, mpls->experimental_use,
-            mpls->bottom_of_stack, mpls->ttl);
+        snprintf(append_pos, buffer_size, "%d,%d,%d,%d",
+                 mpls->label, mpls->experimental_use,
+                 mpls->bottom_of_stack, mpls->ttl);
 
         buffer_size -= strlen(append_pos);
         append_pos += strlen(append_pos);
@@ -255,28 +255,28 @@ void respond_to_probe(
 
     if (remote_addr->ss_family == AF_INET6) {
         ip_argument = "ip-6";
-        sockaddr6 = (struct sockaddr_in6 *)remote_addr;
+        sockaddr6 = (struct sockaddr_in6 *) remote_addr;
         addr = &sockaddr6->sin6_addr;
     } else {
         ip_argument = "ip-4";
-        sockaddr4 = (struct sockaddr_in *)remote_addr;
+        sockaddr4 = (struct sockaddr_in *) remote_addr;
         addr = &sockaddr4->sin_addr;
     }
 
-    if (inet_ntop(
-            remote_addr->ss_family, addr, ip_text, IP_TEXT_LENGTH) == NULL) {
+    if (inet_ntop(remote_addr->ss_family, addr, ip_text, IP_TEXT_LENGTH) ==
+        NULL) {
 
         perror("inet_ntop failure");
         exit(EXIT_FAILURE);
     }
 
-    snprintf(
-        response, COMMAND_BUFFER_SIZE,
-        "%d %s %s %s round-trip-time %d",
-        probe->token, result, ip_argument, ip_text, round_trip_us);
+    snprintf(response, COMMAND_BUFFER_SIZE,
+             "%d %s %s %s round-trip-time %d",
+             probe->token, result, ip_argument, ip_text, round_trip_us);
 
     if (mpls_count) {
-        format_mpls_string(mpls_str, COMMAND_BUFFER_SIZE, mpls_count, mpls);
+        format_mpls_string(mpls_str, COMMAND_BUFFER_SIZE, mpls_count,
+                           mpls);
 
         remaining_size = COMMAND_BUFFER_SIZE - strlen(response) - 1;
         strncat(response, " mpls ", remaining_size);
@@ -315,18 +315,18 @@ int find_source_addr(
     dest_with_port = *destaddr;
 
     /*
-        MacOS requires a non-zero sin_port when used as an
-        address for a UDP connect.  If we provide a zero port,
-        the connect will fail.  We aren't actually sending
-        anything to the port.
-    */
+       MacOS requires a non-zero sin_port when used as an
+       address for a UDP connect.  If we provide a zero port,
+       the connect will fail.  We aren't actually sending
+       anything to the port.
+     */
     if (destaddr->ss_family == AF_INET6) {
-        destaddr6 = (struct sockaddr_in6 *)&dest_with_port;
+        destaddr6 = (struct sockaddr_in6 *) &dest_with_port;
         destaddr6->sin6_port = htons(1);
 
         len = sizeof(struct sockaddr_in6);
     } else {
-        destaddr4 = (struct sockaddr_in *)&dest_with_port;
+        destaddr4 = (struct sockaddr_in *) &dest_with_port;
         destaddr4->sin_port = htons(1);
 
         len = sizeof(struct sockaddr_in);
@@ -337,12 +337,12 @@ int find_source_addr(
         return -1;
     }
 
-    if (connect(sock, (struct sockaddr *)&dest_with_port, len)) {
+    if (connect(sock, (struct sockaddr *) &dest_with_port, len)) {
         close(sock);
         return -1;
     }
 
-    if (getsockname(sock, (struct sockaddr *)srcaddr, &len)) {
+    if (getsockname(sock, (struct sockaddr *) srcaddr, &len)) {
         close(sock);
         return -1;
     }
@@ -350,15 +350,15 @@ int find_source_addr(
     close(sock);
 
     /*
-        Zero the port, as we may later use this address to finding, and
-        we don't want to use the port from the socket we just created.
-    */
+       Zero the port, as we may later use this address to finding, and
+       we don't want to use the port from the socket we just created.
+     */
     if (destaddr->ss_family == AF_INET6) {
-        srcaddr6 = (struct sockaddr_in6 *)srcaddr;
+        srcaddr6 = (struct sockaddr_in6 *) srcaddr;
 
         srcaddr6->sin6_port = 0;
     } else {
-        srcaddr4 = (struct sockaddr_in *)srcaddr;
+        srcaddr4 = (struct sockaddr_in *) srcaddr;
 
         srcaddr4->sin_port = 0;
     }
index 1bb2bb000ac62d4cc39e8340c5235892709210b5..9c8dfc68a1f1a5fcf6a8d43a953dcc8e023f69b4 100644 (file)
@@ -40,8 +40,7 @@
 #define PACKET_BUFFER_SIZE 9000
 
 /*  Parameters for sending a new probe  */
-struct probe_param_t
-{
+struct probe_param_t {
     /*  The version of the Internet Protocol to use.  (4 or 6)  */
     int ip_version;
 
@@ -83,17 +82,17 @@ struct probe_param_t
 };
 
 /*  Tracking information for an outstanding probe  */
-struct probe_t
-{
+struct probe_t {
     /*  Our entry in the probe list  */
-    LIST_ENTRY(probe_t) probe_list_entry;
+    LIST_ENTRY(
+    probe_t) probe_list_entry;
 
     /*
-        Also the ICMP sequence ID used to identify the probe.
+       Also the ICMP sequence ID used to identify the probe.
 
-        Also used as the port number to use when binding stream protocol
-        sockets for this probe.  (i.e. TCP or SCTP)
-    */
+       Also used as the port number to use when binding stream protocol
+       sockets for this probe.  (i.e. TCP or SCTP)
+     */
     int sequence;
 
     /*  Command token of the probe request  */
@@ -107,21 +106,21 @@ struct probe_t
 };
 
 /*  Global state for interacting with the network  */
-struct net_state_t
-{
+struct net_state_t {
     /*  The number of entries in the outstanding_probes list  */
     int outstanding_probe_count;
 
     /*  Tracking information for in-flight probes  */
-    LIST_HEAD(probe_list_head_t, probe_t) outstanding_probes;
+     LIST_HEAD(
+    probe_list_head_t,
+    probe_t) outstanding_probes;
 
     /*  Platform specific tracking information  */
     struct net_state_platform_t platform;
 };
 
 /*  Multiprotocol Label Switching information  */
-struct mpls_label_t
-{
+struct mpls_label_t {
     uint32_t label;
     uint8_t experimental_use;
     uint8_t bottom_of_stack;
index ae221d00d79c8bdf8f77255807ade549cf6cbaa2..56bd2b99dfd7b09113273371619044571f55aecc 100644 (file)
@@ -40,8 +40,7 @@ void init_net_state(
     net_state->platform.icmp6 = Icmp6CreateFile();
 
     if (net_state->platform.icmp4 == INVALID_HANDLE_VALUE
-            && net_state->platform.icmp6 == INVALID_HANDLE_VALUE)
-    {
+        && net_state->platform.icmp6 == INVALID_HANDLE_VALUE) {
         fprintf(stderr, "Failure opening ICMP %d\n", GetLastError());
         exit(EXIT_FAILURE);
     }
@@ -66,7 +65,7 @@ bool is_ip_version_supported(
 
 /*  On Windows, we only support ICMP probes  */
 bool is_protocol_supported(
-    struct net_state_t *net_state,
+    struct net_state_t * net_state,
     int protocol)
 {
     if (protocol == IPPROTO_ICMP) {
@@ -101,17 +100,15 @@ void report_win_error(
     int err)
 {
     /*  It could be that we got no reply because of timeout  */
-    if (err == IP_REQ_TIMED_OUT
-            || err == IP_SOURCE_QUENCH) {
+    if (err == IP_REQ_TIMED_OUT || err == IP_SOURCE_QUENCH) {
         printf("%d no-reply\n", command_token);
     } else if (err == IP_DEST_HOST_UNREACHABLE
-            || err == IP_DEST_PORT_UNREACHABLE
-            || err == IP_DEST_PROT_UNREACHABLE
-            || err == IP_DEST_NET_UNREACHABLE
-            || err == IP_DEST_UNREACHABLE
-            || err == IP_DEST_NO_ROUTE
-            || err == IP_BAD_ROUTE
-            || err == IP_BAD_DESTINATION) {
+               || err == IP_DEST_PORT_UNREACHABLE
+               || err == IP_DEST_PROT_UNREACHABLE
+               || err == IP_DEST_NET_UNREACHABLE
+               || err == IP_DEST_UNREACHABLE
+               || err == IP_DEST_NO_ROUTE
+               || err == IP_BAD_ROUTE || err == IP_BAD_DESTINATION) {
         printf("%d no-route\n", command_token);
     } else if (err == ERROR_INVALID_NETNAME) {
         printf("%d address-not-available\n", command_token);
@@ -133,7 +130,7 @@ void WINAPI on_icmp_reply(
     PIO_STATUS_BLOCK status,
     ULONG reserved)
 {
-    struct probe_t *probe = (struct probe_t *)context;
+    struct probe_t *probe = (struct probe_t *) context;
     struct net_state_t *net_state = probe->platform.net_state;
     int icmp_type;
     int round_trip_us = 0;
@@ -155,13 +152,12 @@ void WINAPI on_icmp_reply(
             /*  Unfortunately, ICMP.DLL only has millisecond precision  */
             round_trip_us = reply6->RoundTripTime * 1000;
 
-            remote_addr6 = (struct sockaddr_in6 *)&remote_addr;
+            remote_addr6 = (struct sockaddr_in6 *) &remote_addr;
             remote_addr6->sin6_family = AF_INET6;
             remote_addr6->sin6_port = 0;
             remote_addr6->sin6_flowinfo = 0;
-            memcpy(
-                &remote_addr6->sin6_addr, reply6->AddressBits,
-                sizeof(struct in6_addr));
+            memcpy(&remote_addr6->sin6_addr, reply6->AddressBits,
+                   sizeof(struct in6_addr));
             remote_addr6->sin6_scope_id = 0;
         }
     } else {
@@ -174,7 +170,7 @@ void WINAPI on_icmp_reply(
             /*  Unfortunately, ICMP.DLL only has millisecond precision  */
             round_trip_us = reply4->RoundTripTime * 1000;
 
-            remote_addr4 = (struct sockaddr_in *)&remote_addr;
+            remote_addr4 = (struct sockaddr_in *) &remote_addr;
             remote_addr4->sin_family = AF_INET;
             remote_addr4->sin_port = 0;
             remote_addr4->sin_addr.s_addr = reply4->Address;
@@ -189,15 +185,14 @@ void WINAPI on_icmp_reply(
     if (reply_status == IP_SUCCESS) {
         icmp_type = ICMP_ECHOREPLY;
     } else if (reply_status == IP_TTL_EXPIRED_TRANSIT
-            || reply_status == IP_TTL_EXPIRED_REASSEM) {
+               || reply_status == IP_TTL_EXPIRED_REASSEM) {
         icmp_type = ICMP_TIME_EXCEEDED;
     }
 
     if (icmp_type != -1) {
         /*  Record probe result  */
-        respond_to_probe(
-            net_state, probe, icmp_type,
-            &remote_addr, round_trip_us, 0, NULL);
+        respond_to_probe(net_state, probe, icmp_type,
+                         &remote_addr, round_trip_us, 0, NULL);
     } else {
         report_win_error(probe->token, reply_status);
         free_probe(net_state, probe);
@@ -228,10 +223,10 @@ void icmp_send_probe(
         timeout = 1000 * param->timeout;
     } else {
         /*
-            IcmpSendEcho2 will return invalid argument on a timeout of 
-            zero.  Our Unix implementation allows it.  Bump up the timeout
-            to 1 millisecond.
-        */
+           IcmpSendEcho2 will return invalid argument on a timeout of 
+           zero.  Our Unix implementation allows it.  Bump up the timeout
+           to 1 millisecond.
+         */
         timeout = 1;
     }
 
@@ -251,31 +246,33 @@ void icmp_send_probe(
     }
 
     if (param->ip_version == 6) {
-        src_sockaddr6 = (struct sockaddr_in6 *)src_sockaddr;
-        dest_sockaddr6 = (struct sockaddr_in6 *)dest_sockaddr;
-
-        send_result = Icmp6SendEcho2(
-            net_state->platform.icmp6, NULL,
-            (FARPROC)on_icmp_reply, probe,
-            src_sockaddr6, dest_sockaddr6, payload, payload_size, &option,
-            probe->platform.reply6, reply_size, timeout);
+        src_sockaddr6 = (struct sockaddr_in6 *) src_sockaddr;
+        dest_sockaddr6 = (struct sockaddr_in6 *) dest_sockaddr;
+
+        send_result = Icmp6SendEcho2(net_state->platform.icmp6, NULL,
+                                     (FARPROC) on_icmp_reply, probe,
+                                     src_sockaddr6, dest_sockaddr6,
+                                     payload, payload_size, &option,
+                                     probe->platform.reply6, reply_size,
+                                     timeout);
     } else {
-        dest_sockaddr4 = (struct sockaddr_in *)dest_sockaddr;
-
-        send_result = IcmpSendEcho2(
-            net_state->platform.icmp4, NULL,
-            (FARPROC)on_icmp_reply, probe,
-            dest_sockaddr4->sin_addr.s_addr, payload, payload_size, &option,
-            probe->platform.reply4, reply_size, timeout);
+        dest_sockaddr4 = (struct sockaddr_in *) dest_sockaddr;
+
+        send_result = IcmpSendEcho2(net_state->platform.icmp4, NULL,
+                                    (FARPROC) on_icmp_reply, probe,
+                                    dest_sockaddr4->sin_addr.s_addr,
+                                    payload, payload_size, &option,
+                                    probe->platform.reply4, reply_size,
+                                    timeout);
     }
 
     if (send_result == 0) {
         err = GetLastError();
 
         /*
-            ERROR_IO_PENDING is expected for asynchronous probes,
-            but any other error is unexpected.
-        */
+           ERROR_IO_PENDING is expected for asynchronous probes,
+           but any other error is unexpected.
+         */
         if (err != ERROR_IO_PENDING) {
             report_win_error(probe->token, err);
             free_probe(net_state, probe);
@@ -294,7 +291,8 @@ int fill_payload(
     int payload_size;
 
     if (param->ip_version == 6) {
-        ip_icmp_size = sizeof(struct IP6Header) + sizeof(struct ICMPHeader);
+        ip_icmp_size =
+            sizeof(struct IP6Header) + sizeof(struct ICMPHeader);
     } else if (param->ip_version == 4) {
         ip_icmp_size = sizeof(struct IPHeader) + sizeof(struct ICMPHeader);
     } else {
@@ -347,9 +345,8 @@ void send_probe(
         exit(EXIT_FAILURE);
     }
 
-    icmp_send_probe(
-        net_state, probe, param,
-        &src_sockaddr, &dest_sockaddr, payload, payload_size);
+    icmp_send_probe(net_state, probe, param,
+                    &src_sockaddr, &dest_sockaddr, payload, payload_size);
 }
 
 /*
index 5012c2122f8d747c7afb98291a67c70d9992ddb8..29ef98282cfb2e537d508a3c3aa73b3132b27e76 100644 (file)
     This should be in the Windows headers, but is missing from
     Cygwin's Windows headers.
 */
-typedef struct icmpv6_echo_reply_lh
-{
+typedef struct icmpv6_echo_reply_lh {
     /*
-        Although Windows uses an IPV6_ADDRESS_EX here, we are using uint8_t
-        fields to avoid structure padding differences between gcc and
-        Visual C++.  (gcc wants to align the flow info to a 4 byte boundary,
-        and Windows uses it unaligned.)
-    */
+       Although Windows uses an IPV6_ADDRESS_EX here, we are using uint8_t
+       fields to avoid structure padding differences between gcc and
+       Visual C++.  (gcc wants to align the flow info to a 4 byte boundary,
+       and Windows uses it unaligned.)
+     */
     uint8_t PortBits[2];
     uint8_t FlowInfoBits[4];
     uint8_t AddressBits[16];
@@ -43,18 +42,18 @@ typedef struct icmpv6_echo_reply_lh
 
     ULONG Status;
     unsigned int RoundTripTime;
-} ICMPV6_ECHO_REPLY, *PICMPV6_ECHO_REPLY;
+} ICMPV6_ECHO_REPLY,
+*PICMPV6_ECHO_REPLY;
 
 /*
        Windows requires an echo reply structure for each in-flight
        ICMP probe.
 */
-struct probe_platform_t
-{
+struct probe_platform_t {
     /*
-        We need a backpointer to the net_state because of the way
-        IcmpSendEcho2 passes our context.
-    */
+       We need a backpointer to the net_state because of the way
+       IcmpSendEcho2 passes our context.
+     */
     struct net_state_t *net_state;
 
     /*  IP version (4 or 6) used for the probe  */
@@ -67,8 +66,7 @@ struct probe_platform_t
 };
 
 /*  A Windows HANDLE for the ICMP session  */
-struct net_state_platform_t
-{
+struct net_state_platform_t {
     HANDLE icmp4;
     HANDLE icmp6;
 };
index e115ffe2d5b324c25eeaf6197f86de3da257a330..53863eb69a5a00694276bb526c2ae703a93413c8 100644 (file)
@@ -64,9 +64,8 @@ int send_packet(
         return -1;
     }
 
-    return sendto(
-        send_socket, packet, packet_size, 0,
-        (struct sockaddr *)sockaddr, sockaddr_length);
+    return sendto(send_socket, packet, packet_size, 0,
+                  (struct sockaddr *) sockaddr, sockaddr_length);
 }
 
 /*
@@ -105,17 +104,17 @@ void check_length_order(
     /*  First attempt to ping the localhost with network byte order  */
     net_state->platform.ip_length_host_order = false;
 
-    packet_size = construct_packet(
-        net_state, NULL, MIN_PORT,
-        packet, PACKET_BUFFER_SIZE,
-        &dest_sockaddr, &src_sockaddr, &param);
+    packet_size = construct_packet(net_state, NULL, MIN_PORT,
+                                   packet, PACKET_BUFFER_SIZE,
+                                   &dest_sockaddr, &src_sockaddr, &param);
     if (packet_size < 0) {
         perror("Unable to send to localhost");
         exit(EXIT_FAILURE);
     }
 
-    bytes_sent = send_packet(
-        net_state, &param, packet, packet_size, &dest_sockaddr);
+    bytes_sent =
+        send_packet(net_state, &param, packet, packet_size,
+                    &dest_sockaddr);
     if (bytes_sent > 0) {
         return;
     }
@@ -123,17 +122,17 @@ void check_length_order(
     /*  Since network byte order failed, try host byte order  */
     net_state->platform.ip_length_host_order = true;
 
-    packet_size = construct_packet(
-        net_state, NULL, MIN_PORT,
-        packet, PACKET_BUFFER_SIZE,
-        &dest_sockaddr, &src_sockaddr, &param);
+    packet_size = construct_packet(net_state, NULL, MIN_PORT,
+                                   packet, PACKET_BUFFER_SIZE,
+                                   &dest_sockaddr, &src_sockaddr, &param);
     if (packet_size < 0) {
         perror("Unable to send to localhost");
         exit(EXIT_FAILURE);
     }
 
-    bytes_sent = send_packet(
-        net_state, &param, packet, packet_size, &dest_sockaddr);
+    bytes_sent =
+        send_packet(net_state, &param, packet, packet_size,
+                    &dest_sockaddr);
     if (bytes_sent < 0) {
         perror("Unable to send with swapped length");
         exit(EXIT_FAILURE);
@@ -195,20 +194,20 @@ int open_ip4_sockets(
     }
 
     /*
-        We will be including the IP header in transmitted packets.
-        Linux doesn't require this, but BSD derived network stacks do.
-    */
-    if (setsockopt(
-        send_socket, IPPROTO_IP, IP_HDRINCL, &trueopt, sizeof(int))) {
+       We will be including the IP header in transmitted packets.
+       Linux doesn't require this, but BSD derived network stacks do.
+     */
+    if (setsockopt
+        (send_socket, IPPROTO_IP, IP_HDRINCL, &trueopt, sizeof(int))) {
 
         close(send_socket);
         return -1;
     }
 
     /*
-        Open a second socket with IPPROTO_ICMP because we are only
-        interested in receiving ICMP packets, not all packets.
-    */
+       Open a second socket with IPPROTO_ICMP because we are only
+       interested in receiving ICMP packets, not all packets.
+     */
     recv_socket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
     if (recv_socket == -1) {
         close(send_socket);
@@ -282,11 +281,11 @@ void init_net_state_privileged(
     }
 
     /*
-        If we couldn't open either IPv4 or IPv6 sockets, we can't do
-        much, so print errors and exit.
-    */
+       If we couldn't open either IPv4 or IPv6 sockets, we can't do
+       much, so print errors and exit.
+     */
     if (!net_state->platform.ip4_present
-            && !net_state->platform.ip6_present) {
+        && !net_state->platform.ip6_present) {
 
         errno = ip4_err;
         perror("Failure to open IPv4 sockets");
@@ -334,7 +333,7 @@ bool is_ip_version_supported(
 
 /*  Returns true if we can transmit probes using the specified protocol  */
 bool is_protocol_supported(
-    struct net_state_t *net_state,
+    struct net_state_t * net_state,
     int protocol)
 {
     if (protocol == IPPROTO_ICMP) {
@@ -348,7 +347,6 @@ bool is_protocol_supported(
     if (protocol == IPPROTO_TCP) {
         return true;
     }
-
 #ifdef IPPROTO_SCTP
     if (protocol == IPPROTO_SCTP) {
         return net_state->platform.sctp_support;
@@ -409,22 +407,21 @@ void send_probe(
         exit(EXIT_FAILURE);
     }
 
-    packet_size = construct_packet(
-        net_state, &probe->platform.socket, probe->sequence,
-        packet, PACKET_BUFFER_SIZE,
-        &probe->remote_addr, &src_sockaddr, param);
+    packet_size =
+        construct_packet(net_state, &probe->platform.socket,
+                         probe->sequence, packet, PACKET_BUFFER_SIZE,
+                         &probe->remote_addr, &src_sockaddr, param);
 
     if (packet_size < 0) {
         /*
-            When using a stream protocol, FreeBSD will return ECONNREFUSED
-            when connecting to localhost if the port doesn't exist,
-            even if the socket is non-blocking, so we should be
-            prepared for that.
-        */
+           When using a stream protocol, FreeBSD will return ECONNREFUSED
+           when connecting to localhost if the port doesn't exist,
+           even if the socket is non-blocking, so we should be
+           prepared for that.
+         */
         if (errno == ECONNREFUSED) {
-            receive_probe(
-                net_state, probe, ICMP_ECHOREPLY,
-                &probe->remote_addr, NULL, 0, NULL);
+            receive_probe(net_state, probe, ICMP_ECHOREPLY,
+                          &probe->remote_addr, NULL, 0, NULL);
         } else {
             report_packet_error(param->command_token);
             free_probe(net_state, probe);
@@ -434,9 +431,8 @@ void send_probe(
     }
 
     if (packet_size > 0) {
-        if (send_packet(
-                net_state, param,
-                packet, packet_size, &probe->remote_addr) == -1) {
+        if (send_packet(net_state, param,
+                        packet, packet_size, &probe->remote_addr) == -1) {
 
             report_packet_error(param->command_token);
             free_probe(net_state, probe);
@@ -478,7 +474,7 @@ void platform_free_probe(
     to the platform agnostic response handling.
 */
 void receive_probe(
-    struct net_state_t *net_state, 
+    struct net_state_t *net_state,
     struct probe_t *probe,
     int icmp_type,
     const struct sockaddr_storage *remote_addr,
@@ -503,9 +499,8 @@ void receive_probe(
         (timestamp->tv_sec - departure_time->tv_sec) * 1000000 +
         timestamp->tv_usec - departure_time->tv_usec;
 
-    respond_to_probe(
-        net_state, probe, icmp_type,
-        remote_addr, round_trip_us, mpls_count, mpls);
+    respond_to_probe(net_state, probe, icmp_type,
+                     remote_addr, round_trip_us, mpls_count, mpls);
 }
 
 /*
@@ -527,14 +522,14 @@ void receive_replies_from_icmp_socket(
     /*  Read until no more packets are available  */
     while (true) {
         sockaddr_length = sizeof(struct sockaddr_storage);
-        packet_length = recvfrom(
-            socket, packet, PACKET_BUFFER_SIZE, 0,
-            (struct sockaddr *)&remote_addr, &sockaddr_length);
+        packet_length = recvfrom(socket, packet, PACKET_BUFFER_SIZE, 0,
+                                 (struct sockaddr *) &remote_addr,
+                                 &sockaddr_length);
 
         /*
-            Get the time immediately after reading the packet to
-            keep the timing as precise as we can.
-        */
+           Get the time immediately after reading the packet to
+           keep the timing as precise as we can.
+         */
         if (gettimeofday(&timestamp, NULL)) {
             perror("gettimeofday failure");
             exit(EXIT_FAILURE);
@@ -542,17 +537,17 @@ void receive_replies_from_icmp_socket(
 
         if (packet_length == -1) {
             /*
-                EAGAIN will be returned if there is no current packet
-                available.
-            */
+               EAGAIN will be returned if there is no current packet
+               available.
+             */
             if (errno == EAGAIN) {
                 return;
             }
 
             /*
-                EINTER will be returned if we received a signal during
-                receive.
-            */
+               EINTER will be returned if we received a signal during
+               receive.
+             */
             if (errno == EINTR) {
                 continue;
             }
@@ -561,8 +556,8 @@ void receive_replies_from_icmp_socket(
             exit(EXIT_FAILURE);
         }
 
-        handle_received_packet(
-            net_state, &remote_addr, packet, packet_length, &timestamp);
+        handle_received_packet(net_state, &remote_addr, packet,
+                               packet_length, &timestamp);
     }
 }
 
@@ -603,8 +598,8 @@ void receive_replies_from_probe_socket(
     }
 
     /*
-        If the socket is writable, the connection attempt has completed.
-    */
+       If the socket is writable, the connection attempt has completed.
+     */
     if (!FD_ISSET(probe_socket, &write_set)) {
         return;
     }
@@ -615,13 +610,12 @@ void receive_replies_from_probe_socket(
     }
 
     /*
-        If the connection complete successfully, or was refused, we can
-        assume our probe arrived at the destination.
-    */
+       If the connection complete successfully, or was refused, we can
+       assume our probe arrived at the destination.
+     */
     if (!err || err == ECONNREFUSED) {
-        receive_probe(
-            net_state, probe, ICMP_ECHOREPLY,
-            &probe->remote_addr, NULL, 0, NULL);
+        receive_probe(net_state, probe, ICMP_ECHOREPLY,
+                      &probe->remote_addr, NULL, 0, NULL);
     } else {
         errno = err;
         report_packet_error(probe->token);
@@ -637,20 +631,21 @@ void receive_replies(
     struct probe_t *probe_safe_iter;
 
     if (net_state->platform.ip4_present) {
-        receive_replies_from_icmp_socket(
-            net_state, net_state->platform.ip4_recv_socket,
-            handle_received_ip4_packet);
+        receive_replies_from_icmp_socket(net_state,
+                                         net_state->platform.
+                                         ip4_recv_socket,
+                                         handle_received_ip4_packet);
     }
 
     if (net_state->platform.ip6_present) {
-        receive_replies_from_icmp_socket(
-            net_state, net_state->platform.ip6_recv_socket,
-            handle_received_ip6_packet);
+        receive_replies_from_icmp_socket(net_state,
+                                         net_state->platform.
+                                         ip6_recv_socket,
+                                         handle_received_ip6_packet);
     }
 
-    LIST_FOREACH_SAFE(
-            probe, &net_state->outstanding_probes,
-            probe_list_entry, probe_safe_iter) {
+    LIST_FOREACH_SAFE(probe, &net_state->outstanding_probes,
+                      probe_list_entry, probe_safe_iter) {
 
         receive_replies_from_probe_socket(net_state, probe);
     }
@@ -662,7 +657,7 @@ void receive_replies(
 */
 int gather_probe_sockets(
     const struct net_state_t *net_state,
-    fd_set *write_set)
+    fd_set * write_set)
 {
     int probe_socket;
     int nfds;
@@ -701,9 +696,8 @@ void check_probe_timeouts(
         exit(EXIT_FAILURE);
     }
 
-    LIST_FOREACH_SAFE(
-            probe, &net_state->outstanding_probes,
-            probe_list_entry, probe_safe_iter) {
+    LIST_FOREACH_SAFE(probe, &net_state->outstanding_probes,
+                      probe_list_entry, probe_safe_iter) {
 
         if (compare_timeval(probe->platform.timeout_time, now) < 0) {
             /*  Report timeout to the command stream  */
index f895a63a0684cc03e5439cd96a253d97199a8a75..36b31596738b180deb92865cc264a54e16ed6764 100644 (file)
@@ -24,8 +24,7 @@
 #define MAX_PORT 65535
 
 /*  We need to track the transmission and timeouts on Unix systems  */
-struct probe_platform_t
-{
+struct probe_platform_t {
     /*  The socket for the outgoing connection  (used by TCP probes)  */
     int socket;
 
@@ -37,8 +36,7 @@ struct probe_platform_t
 };
 
 /*  We'll use rack sockets to send and recieve probes on Unix systems  */
-struct net_state_platform_t
-{
+struct net_state_platform_t {
     /*  true if we were successful at opening IPv4 sockets  */
     bool ip4_present;
 
@@ -61,9 +59,9 @@ struct net_state_platform_t
     int ip6_recv_socket;
 
     /*
-        true if we should encode the IP header length in host order.
-        (as opposed to network order)
-    */
+       true if we should encode the IP header length in host order.
+       (as opposed to network order)
+     */
     bool ip_length_host_order;
 
     /*  true if the operating system supports SCTP sockets  */
@@ -91,6 +89,6 @@ void receive_probe(
 
 int gather_probe_sockets(
     const struct net_state_t *net_state,
-    fd_set *write_set);
+    fd_set * write_set);
 
 #endif
index ea3f07e457a009b03709a9182fb2d72cc693374c..75a82297c02219b2331b6cd581e029f9eef31b37 100644 (file)
@@ -78,7 +78,7 @@ struct ICMPExtensionObject {
 /*  An MPLS label included in an ICMP extension  */
 /*  See RFC 4950  */
 struct ICMPExtMPLSLabel {
-    uint8_t label[3];  // Low 4 bits are Experimental Use, Stack
+    uint8_t label[3];           // Low 4 bits are Experimental Use, Stack
     uint8_t ttl;
 };
 
index ae8c3f66501e0a759a9873665d83e1aea5295e40..0f88a3af20da277d8efefa56cb05a1d456e1286c 100644 (file)
@@ -28,9 +28,9 @@ void normalize_timeval(
     int full_sec;
 
     /*
-        If tv_usec has overflowed a full second, convert the overflow
-        to tv_sec.
-    */
+       If tv_usec has overflowed a full second, convert the overflow
+       to tv_sec.
+     */
     full_sec = timeval->tv_usec / 1000000;
     timeval->tv_sec += full_sec;
     timeval->tv_usec -= 1000000 * full_sec;
index 1b9f81a26c9e3b0f8b42019878638df66b595ea0..33cbbb995df4e6e55ec6c01ca5a3d3b6a8407e5e 100644 (file)
@@ -37,12 +37,12 @@ void wait_for_activity(
     DWORD wait_result;
 
     /*
-        Start the command read overlapped I/O just prior to sleeping.
-        During development of the Cygwin port, there was a bug where the
-        overlapped I/O was started earlier in the mtr-packet loop, and
-        an intermediate alertable wait could leave us in this Sleep
-        without an active command read.  So now we do this here, instead.
-    */
+       Start the command read overlapped I/O just prior to sleeping.
+       During development of the Cygwin port, there was a bug where the
+       overlapped I/O was started earlier in the mtr-packet loop, and
+       an intermediate alertable wait could leave us in this Sleep
+       without an active command read.  So now we do this here, instead.
+     */
     start_read_command(command_buffer);
 
     /*  Sleep until an I/O completion routine runs  */
index c4ca5c5d7647e56de50475593f88a2e50859a433..f347e2312a4cafc7cd3a976d17e614fdd6c63036 100644 (file)
@@ -34,8 +34,8 @@ static
 int gather_read_fds(
     const struct command_buffer_t *command_buffer,
     const struct net_state_t *net_state,
-    fd_set *read_set,
-    fd_set *write_set)
+    fd_set * read_set,
+    fd_set * write_set)
 {
     int nfds;
     int probe_nfds;
@@ -84,7 +84,8 @@ void wait_for_activity(
     struct timeval *select_timeout;
     int ready_count;
 
-    nfds = gather_read_fds(command_buffer, net_state, &read_set, &write_set);
+    nfds =
+        gather_read_fds(command_buffer, net_state, &read_set, &write_set);
 
     while (true) {
         select_timeout = NULL;
@@ -95,24 +96,24 @@ void wait_for_activity(
             select_timeout = &probe_timeout;
         }
 
-        ready_count = select(
-            nfds, &read_set, &write_set, NULL, select_timeout);
+        ready_count =
+            select(nfds, &read_set, &write_set, NULL, select_timeout);
 
         /*
-            If we didn't have an error, either one of our descriptors is
-            readable, or we timed out.  So we can now return.
-        */
+           If we didn't have an error, either one of our descriptors is
+           readable, or we timed out.  So we can now return.
+         */
         if (ready_count != -1) {
             break;
         }
 
         /*
-            We will get EINTR if we received a signal during the select, so
-            retry in that case.  We may get EAGAIN if "the kernel was
-            (perhaps temporarily) unable to allocate the requested number of
-            file descriptors."  I haven't seen this in practice, but selecting
-            again seems like the right thing to do.
-        */
+           We will get EINTR if we received a signal during the select, so
+           retry in that case.  We may get EAGAIN if "the kernel was
+           (perhaps temporarily) unable to allocate the requested number of
+           file descriptors."  I haven't seen this in practice, but selecting
+           again seems like the right thing to do.
+         */
         if (errno != EINTR && errno != EAGAIN) {
             /*  We don't expect other errors, so report them  */
             perror("unexpected select error");
index 622d7ba050e5264d8feec86f923bcdae76588c8b..04c8e3a6eae8f584a4eeb9a7275c23774485705c 100644 (file)
--- a/ui/asn.c
+++ b/ui/asn.c
 #include <stdlib.h>
 #include <sys/types.h>
 #ifdef HAVE_ERROR_H
-# include <error.h>
+#include <error.h>
 #else
-# include "portability/error.h"
+#include "portability/error.h"
 #endif
 #include <errno.h>
 
 #ifdef __APPLE__
-# define BIND_8_COMPAT
+#define BIND_8_COMPAT
 #endif
 #include <arpa/nameser.h>
 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
+#include <arpa/nameser_compat.h>
 #endif
 #include <netdb.h>
 #include <netinet/in.h>
 
 /* #define IIDEBUG */
 #ifdef IIDEBUG
-# include <syslog.h>
-# define DEB_syslog syslog
+#include <syslog.h>
+#define DEB_syslog syslog
 #else
-# define DEB_syslog(...) do {} while (0)
+#define DEB_syslog(...) do {} while (0)
 #endif
 
 #define IIHASH_HI      128
 #define NAMELEN        127
 #define UNKN   "???"
 
-static int  iihash = 0;
+static int iihash = 0;
 static char fmtinfo[32];
 
 /* items width: ASN, Route, Country, Registry, Allocated */
-static const int iiwidth[] = { 7, 19, 4, 8, 11 };    /* item len + space */
+static const int iiwidth[] = { 7, 19, 4, 8, 11 };       /* item len + space */
 
-typedef charitems_t[ITEMSMAX + 1];
-static items_t items_a;                /* without hash: items */
-static char txtrec[NAMELEN + 1];       /* without hash: txtrec */
-static items_titems = &items_a;
+typedef char *items_t[ITEMSMAX + 1];
+static items_t items_a;         /* without hash: items */
+static char txtrec[NAMELEN + 1];        /* without hash: txtrec */
+static items_t *items = &items_a;
 
 
-static char *ipinfo_lookup(const char *domain) {
-    unsigned char answer[PACKETSZ],  *pt;
+static char *ipinfo_lookup(
+    const char *domain)
+{
+    unsigned char answer[PACKETSZ], *pt;
     char host[128];
     char *txt;
     int len, exp, size, txtlen, type;
 
 
-    if(res_init() < 0) {
+    if (res_init() < 0) {
         error(0, 0, "@res_init failed");
         return NULL;
     }
 
     memset(answer, 0, PACKETSZ);
-    if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
+    if ((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
         if (iihash)
             DEB_syslog(LOG_INFO, "Malloc-txt: %s", UNKN);
         return xstrdup(UNKN);
@@ -94,37 +96,45 @@ static char *ipinfo_lookup(const char *domain) {
 
     pt = answer + sizeof(HEADER);
 
-    if((exp = dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) {
-        printf("@dn_expand failed\n"); return NULL;
+    if ((exp =
+         dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) {
+        printf("@dn_expand failed\n");
+        return NULL;
     }
 
     pt += exp;
 
     GETSHORT(type, pt);
-    if(type != T_TXT) {
-        printf("@Broken DNS reply.\n"); return NULL;
+    if (type != T_TXT) {
+        printf("@Broken DNS reply.\n");
+        return NULL;
     }
 
-    pt += INT16SZ; /* class */
+    pt += INT16SZ;              /* class */
 
-    if((exp = dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) {
-        printf("@second dn_expand failed\n"); return NULL;
+    if ((exp =
+         dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) {
+        printf("@second dn_expand failed\n");
+        return NULL;
     }
 
     pt += exp;
     GETSHORT(type, pt);
-    if(type != T_TXT) {
-        printf("@Not a TXT record\n"); return NULL;
+    if (type != T_TXT) {
+        printf("@Not a TXT record\n");
+        return NULL;
     }
 
-    pt += INT16SZ; /* class */
-    pt += INT32SZ; /* ttl */
+    pt += INT16SZ;              /* class */
+    pt += INT32SZ;              /* ttl */
     GETSHORT(size, pt);
     txtlen = *pt;
 
 
-    if(txtlen >= size || !txtlen) {
-        printf("@Broken TXT record (txtlen = %d, size = %d)\n", txtlen, size); return NULL;
+    if (txtlen >= size || !txtlen) {
+        printf("@Broken TXT record (txtlen = %d, size = %d)\n", txtlen,
+               size);
+        return NULL;
     }
 
     if (txtlen > NAMELEN)
@@ -133,10 +143,10 @@ static char *ipinfo_lookup(const char *domain) {
     if (iihash) {
         txt = xmalloc(txtlen + 1);
     } else
-        txt = (char*)txtrec;
+        txt = (char *) txtrec;
 
     pt++;
-    xstrncpy(txt, (char*) pt, txtlen + 1);
+    xstrncpy(txt, (char *) pt, txtlen + 1);
 
     if (iihash)
         DEB_syslog(LOG_INFO, "Malloc-txt(%p): %s", txt, txt);
@@ -145,13 +155,16 @@ static char *ipinfo_lookup(const char *domain) {
 }
 
 /* originX.asn.cymru.com txtrec:    ASN | Route | Country | Registry | Allocated */
-static char* split_txtrec(struct mtr_ctl *ctl, char *txt_rec) {
-    char* prev;
-    char* next;
+static char *split_txtrec(
+    struct mtr_ctl *ctl,
+    char *txt_rec)
+{
+    char *prev;
+    char *next;
     int i = 0, j;
 
     if (!txt_rec)
-       return NULL;
+        return NULL;
     if (iihash) {
         DEB_syslog(LOG_INFO, "Malloc-tbl: %s", txt_rec);
         if (!(items = malloc(sizeof(*items)))) {
@@ -174,7 +187,7 @@ static char* split_txtrec(struct mtr_ctl *ctl, char *txt_rec) {
 
     if (i < ITEMSMAX)
         i++;
-    for (j = i;  j <= ITEMSMAX; j++)
+    for (j = i; j <= ITEMSMAX; j++)
         (*items)[j] = NULL;
 
     if (i > ctl->ipinfo_max)
@@ -182,26 +195,32 @@ static char* split_txtrec(struct mtr_ctl *ctl, char *txt_rec) {
     if (ctl->ipinfo_no >= i) {
         if (ctl->ipinfo_no >= ctl->ipinfo_max)
             ctl->ipinfo_no = 0;
-       return (*items)[0];
+        return (*items)[0];
     } else
-       return (*items)[ctl->ipinfo_no];
+        return (*items)[ctl->ipinfo_no];
 }
 
 #ifdef ENABLE_IPV6
 /* from dns.c:addr2ip6arpa() */
-static void reverse_host6(struct in6_addr *addr, char *buff, int buff_length) {
+static void reverse_host6(
+    struct in6_addr *addr,
+    char *buff,
+    int buff_length)
+{
     int i;
     char *b = buff;
-    for (i=(sizeof(*addr)/2-1); i>=0; i--, b+=4) /* 64b portion */
-        snprintf(
-            b, buff_length,
-            "%x.%x.", addr->s6_addr[i] & 0xf, addr->s6_addr[i] >> 4);
+    for (i = (sizeof(*addr) / 2 - 1); i >= 0; i--, b += 4)      /* 64b portion */
+        snprintf(b, buff_length,
+                 "%x.%x.", addr->s6_addr[i] & 0xf, addr->s6_addr[i] >> 4);
 
     buff[strlen(buff) - 1] = '\0';
 }
 #endif
 
-static char *get_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
+static char *get_ipinfo(
+    struct mtr_ctl *ctl,
+    ip_t * addr)
+{
     char key[NAMELEN];
     char lookup_key[NAMELEN];
     char *val = NULL;
@@ -213,17 +232,21 @@ static char *get_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
     if (ctl->af == AF_INET6) {
 #ifdef ENABLE_IPV6
         reverse_host6(addr, key, NAMELEN);
-        if (snprintf(lookup_key, NAMELEN, "%s.origin6.asn.cymru.com", key) >= NAMELEN)
+        if (snprintf(lookup_key, NAMELEN, "%s.origin6.asn.cymru.com", key)
+            >= NAMELEN)
             return NULL;
 #else
-       return NULL;
+        return NULL;
 #endif
     } else {
         unsigned char buff[4];
         memcpy(buff, addr, 4);
-        if (snprintf(key, NAMELEN, "%d.%d.%d.%d", buff[3], buff[2], buff[1], buff[0]) >= NAMELEN)
+        if (snprintf
+            (key, NAMELEN, "%d.%d.%d.%d", buff[3], buff[2], buff[1],
+             buff[0]) >= NAMELEN)
             return NULL;
-        if (snprintf(lookup_key, NAMELEN, "%s.origin.asn.cymru.com", key) >= NAMELEN)
+        if (snprintf(lookup_key, NAMELEN, "%s.origin.asn.cymru.com", key)
+            >= NAMELEN)
             return NULL;
     }
 
@@ -233,9 +256,9 @@ static char *get_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
         DEB_syslog(LOG_INFO, ">> Search: %s", key);
         item.key = key;;
         if ((found_item = hsearch(item, FIND))) {
-            if (!(val = (*((items_t*)found_item->data))[ctl->ipinfo_no]))
-                val = (*((items_t*)found_item->data))[0];
-        DEB_syslog(LOG_INFO, "Found (hashed): %s", val);
+            if (!(val = (*((items_t *) found_item->data))[ctl->ipinfo_no]))
+                val = (*((items_t *) found_item->data))[0];
+            DEB_syslog(LOG_INFO, "Found (hashed): %s", val);
         }
     }
 
@@ -245,7 +268,7 @@ static char *get_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
             DEB_syslog(LOG_INFO, "Looked up: %s", key);
             if (iihash)
                 if ((item.key = xstrdup(key))) {
-                    item.data = (void *)items;
+                    item.data = (void *) items;
                     hsearch(item, ENTER);
                     DEB_syslog(LOG_INFO, "Insert into hash: %s", key);
                 }
@@ -255,11 +278,15 @@ static char *get_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
     return val;
 }
 
-ATTRIBUTE_CONST size_t get_iiwidth_len(void) {
+ATTRIBUTE_CONST size_t get_iiwidth_len(
+    void)
+{
     return (sizeof(iiwidth) / sizeof((iiwidth)[0]));
 }
 
-ATTRIBUTE_CONST int get_iiwidth(int ipinfo_no) {
+ATTRIBUTE_CONST int get_iiwidth(
+    int ipinfo_no)
+{
     static const int len = (sizeof(iiwidth) / sizeof((iiwidth)[0]));
 
     if (ipinfo_no < len)
@@ -267,19 +294,27 @@ ATTRIBUTE_CONST int get_iiwidth(int ipinfo_no) {
     return iiwidth[ipinfo_no % len];
 }
 
-char *fmt_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
+char *fmt_ipinfo(
+    struct mtr_ctl *ctl,
+    ip_t * addr)
+{
     char *ipinfo = get_ipinfo(ctl, addr);
     char fmt[8];
-    snprintf(fmt, sizeof(fmt), "%s%%-%ds", ctl->ipinfo_no?"":"AS", get_iiwidth(ctl->ipinfo_no));
-    snprintf(fmtinfo, sizeof(fmtinfo), fmt, ipinfo?ipinfo:UNKN);
+    snprintf(fmt, sizeof(fmt), "%s%%-%ds", ctl->ipinfo_no ? "" : "AS",
+             get_iiwidth(ctl->ipinfo_no));
+    snprintf(fmtinfo, sizeof(fmtinfo), fmt, ipinfo ? ipinfo : UNKN);
     return fmtinfo;
 }
 
-int is_printii(struct mtr_ctl *ctl) {
+int is_printii(
+    struct mtr_ctl *ctl)
+{
     return ((ctl->ipinfo_no >= 0) && (ctl->ipinfo_no != ctl->ipinfo_max));
 }
 
-void asn_open(struct mtr_ctl *ctl) {
+void asn_open(
+    struct mtr_ctl *ctl)
+{
     if (ctl->ipinfo_no >= 0) {
         DEB_syslog(LOG_INFO, "hcreate(%d)", IIHASH_HI);
         if (!(iihash = hcreate(IIHASH_HI)))
@@ -287,11 +322,12 @@ void asn_open(struct mtr_ctl *ctl) {
     }
 }
 
-void asn_close(struct mtr_ctl *ctl) {
+void asn_close(
+    struct mtr_ctl *ctl)
+{
     if ((ctl->ipinfo_no >= 0) && iihash) {
         DEB_syslog(LOG_INFO, "hdestroy()");
         hdestroy();
         iihash = 0;
     }
 }
-
index 9d02e5f78147c94b3215c78ff1cfcdcbb563b145..5301e9b4f33b2304125096562f13e206013fc52b 100644 (file)
--- a/ui/asn.h
+++ b/ui/asn.h
 
 #include "mtr.h"
 
-extern void asn_open(struct mtr_ctl *ctl);
-extern void asn_close(struct mtr_ctl *ctl);
-extern char *fmt_ipinfo(struct mtr_ctl *ctl, ip_t *addr);
-extern ATTRIBUTE_CONST size_t get_iiwidth_len(void);
-extern ATTRIBUTE_CONST int get_iiwidth(int ipinfo_no);
-extern int is_printii(struct mtr_ctl *ctl);
+extern void asn_open(
+    struct mtr_ctl *ctl);
+extern void asn_close(
+    struct mtr_ctl *ctl);
+extern char *fmt_ipinfo(
+    struct mtr_ctl *ctl,
+    ip_t * addr);
+extern ATTRIBUTE_CONST size_t get_iiwidth_len(
+    void);
+extern ATTRIBUTE_CONST int get_iiwidth(
+    int ipinfo_no);
+extern int is_printii(
+    struct mtr_ctl *ctl);
index effabe293a6929347a4b6a02185d3a7299ee4058..c7120e2cb1ea787bddf9e1e61856feddb30cf8ba 100644 (file)
@@ -31,9 +31,9 @@
 #include <unistd.h>
 
 #ifdef HAVE_ERROR_H
-# include <error.h>
+#include <error.h>
 #else
-# include "portability/error.h"
+#include "portability/error.h"
 #endif
 
 #include "packet/cmdparse.h"
@@ -94,7 +94,8 @@ int send_synchronous_command(
     }
 
     /*  Read the reply to our query  */
-    read_length = read(cmdpipe->read_fd, reply, PACKET_REPLY_BUFFER_SIZE - 1);
+    read_length =
+        read(cmdpipe->read_fd, reply, PACKET_REPLY_BUFFER_SIZE - 1);
 
     if (read_length < 0) {
         return -1;
@@ -120,19 +121,19 @@ int check_feature(
     char check_command[COMMAND_BUFFER_SIZE];
     struct command_t reply;
 
-    snprintf(
-        check_command, COMMAND_BUFFER_SIZE,
-        "1 check-support feature %s\n", feature);
+    snprintf(check_command, COMMAND_BUFFER_SIZE,
+             "1 check-support feature %s\n", feature);
 
-    if (send_synchronous_command(ctl, cmdpipe, check_command, &reply) == -1) {
+    if (send_synchronous_command(ctl, cmdpipe, check_command, &reply) ==
+        -1) {
         return -1;
     }
 
     /*  Check that the feature is supported  */
     if (!strcmp(reply.command_name, "feature-support")
-            && reply.argument_count >= 1
-            && !strcmp(reply.argument_name[0], "support")
-            && !strcmp(reply.argument_value[0], "ok")) {
+        && reply.argument_count >= 1
+        && !strcmp(reply.argument_name[0], "support")
+        && !strcmp(reply.argument_value[0], "ok")) {
 
         /*  Looks good  */
         return 0;
@@ -194,7 +195,7 @@ int check_packet_features(
 #ifdef SO_MARK
     if (ctl->mark) {
         if (check_feature(ctl, cmdpipe, "mark")) {
-        return -1;
+            return -1;
         }
     }
 #endif
@@ -208,28 +209,29 @@ int check_packet_features(
     the PATH when locating the executable.
 */
 static
-void execute_packet_child(void)
+void execute_packet_child(
+    void)
 {
     /*
-        Allow the MTR_PACKET environment variable to override
-        the path to the mtr-packet executable.  This is necessary
-        for debugging changes for mtr-packet.
-    */
+       Allow the MTR_PACKET environment variable to override
+       the path to the mtr-packet executable.  This is necessary
+       for debugging changes for mtr-packet.
+     */
     char *mtr_packet_path = getenv("MTR_PACKET");
     if (mtr_packet_path == NULL) {
         mtr_packet_path = "mtr-packet";
     }
 
     /*
-        First, try to execute mtr-packet from PATH
-        or MTR_PACKET environment variable.
-    */
-    execlp(mtr_packet_path, "mtr-packet", (char *)NULL);
+       First, try to execute mtr-packet from PATH
+       or MTR_PACKET environment variable.
+     */
+    execlp(mtr_packet_path, "mtr-packet", (char *) NULL);
 
     /*
-        If mtr-packet is not found, try to use mtr-packet from current directory
-    */
-    execl("./mtr-packet", "./mtr-packet", (char *)NULL);
+       If mtr-packet is not found, try to use mtr-packet from current directory
+     */
+    execl("./mtr-packet", "./mtr-packet", (char *) NULL);
 
     /*  Both exec attempts failed, so nothing to do but exit  */
     exit(1);
@@ -247,9 +249,9 @@ int open_command_pipe(
     int i;
 
     /*
-        We actually need two Unix pipes.  One for stdin and one for
-        stdout on the new process.
-    */
+       We actually need two Unix pipes.  One for stdin and one for
+       stdout on the new process.
+     */
     if (pipe(stdin_pipe) || pipe(stdout_pipe)) {
         return errno;
     }
@@ -261,9 +263,9 @@ int open_command_pipe(
 
     if (child_pid == 0) {
         /*
-            In the child process, attach our created pipes to stdin
-            and stdout
-        */
+           In the child process, attach our created pipes to stdin
+           and stdout
+         */
         dup2(stdin_pipe[0], STDIN_FILENO);
         dup2(stdout_pipe[1], STDOUT_FILENO);
 
@@ -277,9 +279,9 @@ int open_command_pipe(
         memset(cmdpipe, 0, sizeof(struct packet_command_pipe_t));
 
         /*
-            In the parent process, save the opposite ends of the pipes
-            attached as stdin and stdout in the child.
-        */
+           In the parent process, save the opposite ends of the pipes
+           attached as stdin and stdout in the child.
+         */
         cmdpipe->pid = child_pid;
         cmdpipe->read_fd = stdout_pipe[0];
         cmdpipe->write_fd = stdin_pipe[1];
@@ -289,9 +291,9 @@ int open_command_pipe(
         close(stdin_pipe[0]);
 
         /*
-            Check that we can communicate with the client.  If we failed to
-            execute the mtr-packet binary, we will discover that here.
-        */
+           Check that we can communicate with the client.  If we failed to
+           execute the mtr-packet binary, we will discover that here.
+         */
         if (check_feature(ctl, cmdpipe, "send-probe")) {
             error(EXIT_FAILURE, errno, "Failure to start mtr-packet");
         }
@@ -333,8 +335,8 @@ void construct_base_command(
     char *command,
     int buffer_size,
     int command_token,
-    ip_t *address,
-    ip_t *localaddress)
+    ip_t * address,
+    ip_t * localaddress)
 {
     char ip_string[INET6_ADDRSTRLEN];
     char local_ip_string[INET6_ADDRSTRLEN];
@@ -343,17 +345,14 @@ void construct_base_command(
     const char *protocol = NULL;
 
     /*  Conver the remote IP address to a string  */
-    if (inet_ntop(
-            ctl->af, address,
-            ip_string, INET6_ADDRSTRLEN) == NULL) {
+    if (inet_ntop(ctl->af, address, ip_string, INET6_ADDRSTRLEN) == NULL) {
 
         display_close(ctl);
         error(EXIT_FAILURE, errno, "invalid remote IP address");
     }
 
-    if (inet_ntop(
-            ctl->af, localaddress,
-            local_ip_string, INET6_ADDRSTRLEN) == NULL) {
+    if (inet_ntop(ctl->af, localaddress,
+                  local_ip_string, INET6_ADDRSTRLEN) == NULL) {
 
         display_close(ctl);
         error(EXIT_FAILURE, errno, "invalid local IP address");
@@ -379,15 +378,14 @@ void construct_base_command(
 #endif
     } else {
         display_close(ctl);
-        error(EXIT_FAILURE, 0, "protocol unsupported by mtr-packet interface");
+        error(EXIT_FAILURE, 0,
+              "protocol unsupported by mtr-packet interface");
     }
 
-    snprintf(
-        command, buffer_size,
-        "%d send-probe %s %s %s %s protocol %s",
-        command_token,
-        ip_type, ip_string, local_ip_type, local_ip_string,
-        protocol);
+    snprintf(command, buffer_size,
+             "%d send-probe %s %s %s %s protocol %s",
+             command_token,
+             ip_type, ip_string, local_ip_type, local_ip_string, protocol);
 }
 
 
@@ -413,8 +411,8 @@ void append_command_argument(
 void send_probe_command(
     struct mtr_ctl *ctl,
     struct packet_command_pipe_t *cmdpipe,
-    ip_t *address,
-    ip_t *localaddress,
+    ip_t * address,
+    ip_t * localaddress,
     int packet_size,
     int sequence,
     int time_to_live)
@@ -423,39 +421,37 @@ void send_probe_command(
     int remaining_size;
     int timeout;
 
-    construct_base_command(
-        ctl, command, COMMAND_BUFFER_SIZE, sequence, address, localaddress);
+    construct_base_command(ctl, command, COMMAND_BUFFER_SIZE, sequence,
+                           address, localaddress);
 
-    append_command_argument(
-        command, COMMAND_BUFFER_SIZE, "size", packet_size);
+    append_command_argument(command, COMMAND_BUFFER_SIZE, "size",
+                            packet_size);
 
-    append_command_argument(
-        command, COMMAND_BUFFER_SIZE, "bit-pattern", ctl->bitpattern);
+    append_command_argument(command, COMMAND_BUFFER_SIZE, "bit-pattern",
+                            ctl->bitpattern);
 
-    append_command_argument(
-        command, COMMAND_BUFFER_SIZE, "tos", ctl->tos);
+    append_command_argument(command, COMMAND_BUFFER_SIZE, "tos", ctl->tos);
 
-    append_command_argument(
-        command, COMMAND_BUFFER_SIZE, "ttl", time_to_live);
+    append_command_argument(command, COMMAND_BUFFER_SIZE, "ttl",
+                            time_to_live);
 
     timeout = ctl->probe_timeout / 1000000;
-    append_command_argument(
-        command, COMMAND_BUFFER_SIZE, "timeout", timeout);
+    append_command_argument(command, COMMAND_BUFFER_SIZE, "timeout",
+                            timeout);
 
     if (ctl->remoteport) {
-        append_command_argument(
-            command, COMMAND_BUFFER_SIZE, "port", ctl->remoteport);
+        append_command_argument(command, COMMAND_BUFFER_SIZE, "port",
+                                ctl->remoteport);
     }
 
     if (ctl->localport) {
-        append_command_argument(
-            command, COMMAND_BUFFER_SIZE, "local-port", ctl->localport);
+        append_command_argument(command, COMMAND_BUFFER_SIZE, "local-port",
+                                ctl->localport);
     }
-
 #ifdef SO_MARK
     if (ctl->mark) {
-        append_command_argument(
-            command, COMMAND_BUFFER_SIZE, "mark", ctl->mark);
+        append_command_argument(command, COMMAND_BUFFER_SIZE, "mark",
+                                ctl->mark);
     }
 #endif
 
@@ -465,7 +461,8 @@ void send_probe_command(
     /*  Send a probe using the mtr-packet subprocess  */
     if (write(cmdpipe->write_fd, command, strlen(command)) == -1) {
         display_close(ctl);
-        error(EXIT_FAILURE, errno, "mtr-packet command pipe write failure");
+        error(EXIT_FAILURE, errno,
+              "mtr-packet command pipe write failure");
     }
 }
 
@@ -494,7 +491,7 @@ void parse_mpls_values(
         }
 
         /*  If the next character is not a comma or a NUL, we have
-            an invalid string  */
+           an invalid string  */
         if (*end_of_value == ',') {
             next_value = end_of_value + 1;
         } else if (*end_of_value == 0) {
@@ -504,9 +501,9 @@ void parse_mpls_values(
         }
 
         /*
-            Store the converted value in the next field of the MPLS
-            structure.
-        */
+           Store the converted value in the next field of the MPLS
+           structure.
+         */
         if (label_field == 0) {
             mpls->label[label_count] = value;
         } else if (label_field == 1) {
@@ -524,9 +521,9 @@ void parse_mpls_values(
         }
 
         /*
-            If we've used up all MPLS labels in the structure, return with
-            what we've got
-        */
+           If we've used up all MPLS labels in the structure, return with
+           what we've got
+         */
         if (label_count >= MAXLABELS) {
             break;
         }
@@ -544,7 +541,7 @@ static
 bool parse_reply_arguments(
     struct mtr_ctl *ctl,
     struct command_t *reply,
-    ip_t *fromaddress,
+    ip_t * fromaddress,
     int *round_trip_time,
     struct mplslen *mpls)
 {
@@ -677,10 +674,10 @@ void handle_command_reply(
     /*  Parse the reply string  */
     if (parse_command(&reply, reply_str)) {
         /*
-            If the reply isn't well structured, something is fundamentally
-            wrong, as we might as well exit.  Even if the reply is of an
-            unknown type, it should still parse.
-        */
+           If the reply isn't well structured, something is fundamentally
+           wrong, as we might as well exit.  Even if the reply is of an
+           unknown type, it should still parse.
+         */
         display_close(ctl);
         error(EXIT_FAILURE, errno, "reply parse failure");
         return;
@@ -697,14 +694,14 @@ void handle_command_reply(
     }
 
     /*
-        If the reply had an IP address and a round trip time, we can
-        record the result.
-    */
-    if (parse_reply_arguments(
-            ctl, &reply, &fromaddress, &round_trip_time, &mpls)) {
+       If the reply had an IP address and a round trip time, we can
+       record the result.
+     */
+    if (parse_reply_arguments
+        (ctl, &reply, &fromaddress, &round_trip_time, &mpls)) {
 
-        reply_func(
-            ctl, seq_num, &mpls, (void *) &fromaddress, round_trip_time);
+        reply_func(ctl, seq_num, &mpls, (void *) &fromaddress,
+                   round_trip_time);
     }
 }
 
@@ -734,9 +731,9 @@ void consume_reply_buffer(
     reply_start = reply_buffer;
 
     /*
-        We may have multiple completed replies.  Loop until we don't
-        have any more newlines termininating replies.
-    */
+       We may have multiple completed replies.  Loop until we don't
+       have any more newlines termininating replies.
+     */
     while (true) {
         /*  If no newline is found, our reply isn't yet complete  */
         end_of_reply = index(reply_start, '\n');
@@ -746,10 +743,10 @@ void consume_reply_buffer(
         }
 
         /*
-            Terminate the reply string at the newline, which
-            is necessary in the case where we are able to read
-            mulitple replies arriving simultaneously.
-        */
+           Terminate the reply string at the newline, which
+           is necessary in the case where we are able to read
+           mulitple replies arriving simultaneously.
+         */
         *end_of_reply = 0;
 
         /*  Parse and record the reply results  */
@@ -759,10 +756,10 @@ void consume_reply_buffer(
     }
 
     /*
-        After replies have been processed, free the space used
-        by the replies, and move any remaining partial reply text
-        to the start of the reply buffer.
-    */
+       After replies have been processed, free the space used
+       by the replies, and move any remaining partial reply text
+       to the start of the reply buffer.
+     */
     used_size = reply_start - reply_buffer;
     move_size = cmdpipe->reply_buffer_used - used_size;
     memmove(reply_buffer, reply_start, move_size);
@@ -770,10 +767,10 @@ void consume_reply_buffer(
 
     if (cmdpipe->reply_buffer_used >= PACKET_REPLY_BUFFER_SIZE - 1) {
         /*
-            We've overflowed the reply buffer without a complete reply.
-            There's not much we can do about it but discard the data
-            we've got and hope new data coming in fits.
-        */
+           We've overflowed the reply buffer without a complete reply.
+           There's not much we can do about it but discard the data
+           we've got and hope new data coming in fits.
+         */
         cmdpipe->reply_buffer_used = 0;
     }
 }
@@ -796,20 +793,19 @@ void handle_command_replies(
     reply_buffer = cmdpipe->reply_buffer;
 
     /*
-        Read the available reply text, up to the the remaining
-        buffer space.  (Minus one for the terminating NUL.)
-    */
+       Read the available reply text, up to the the remaining
+       buffer space.  (Minus one for the terminating NUL.)
+     */
     read_buffer = &reply_buffer[cmdpipe->reply_buffer_used];
     buffer_remaining =
         PACKET_REPLY_BUFFER_SIZE - cmdpipe->reply_buffer_used;
-    read_count = read(
-        cmdpipe->read_fd, read_buffer, buffer_remaining - 1);
+    read_count = read(cmdpipe->read_fd, read_buffer, buffer_remaining - 1);
 
     if (read_count < 0) {
         /*
-            EAGAIN simply indicates that there is no data currently
-            available on our non-blocking pipe.
-        */
+           EAGAIN simply indicates that there is no data currently
+           available on our non-blocking pipe.
+         */
         if (errno == EAGAIN) {
             return;
         }
index 8f2cb7069d5499dcef25492dc901b21486b79ae2..7a5b68719386669c71861105437402aa75cd2fc8 100644 (file)
@@ -43,11 +43,12 @@ struct packet_command_pipe_t {
 };
 
 typedef
-void (*probe_reply_func_t)(
-    struct mtr_ctl *ctl,
+void (
+    *probe_reply_func_t) (
+    struct mtr_ctl * ctl,
     int sequence,
-    struct mplslen *mpls,
-    ip_t *addr,
+    struct mplslen * mpls,
+    ip_t * addr,
     int round_trip_time);
 
 int open_command_pipe(
@@ -60,8 +61,8 @@ void close_command_pipe(
 void send_probe_command(
     struct mtr_ctl *ctl,
     struct packet_command_pipe_t *cmdpipe,
-    ip_t *address,
-    ip_t *localaddress,
+    ip_t * address,
+    ip_t * localaddress,
     int packet_size,
     int sequence,
     int time_to_live);
index 0ec2e56571b5778160dfc57db68422ada52cc7eb..a7588ca3f9b4e744603e46ca27c8c64339656241 100644 (file)
@@ -30,7 +30,7 @@
 
 /* MacOSX may need this before socket.h...*/
 #if defined(HAVE_SYS_TYPES_H)
-# include <sys/types.h>
+#include <sys/types.h>
 #endif
 
 #include <sys/socket.h>
 #include <arpa/inet.h>
 
 #if defined(HAVE_NCURSES_H)
-# include <ncurses.h>
+#include <ncurses.h>
 #elif defined(HAVE_NCURSES_CURSES_H)
-# include <ncurses/curses.h>
+#include <ncurses/curses.h>
 #elif defined(HAVE_CURSES_H)
-# include <curses.h>
+#include <curses.h>
 #elif defined(HAVE_CURSESX_H)
-# include <cursesX.h>
+#include <cursesX.h>
 #else
-# error No curses header file available
+#error No curses header file available
 #endif
 
 /* This go-around is needed only when compiling with antique version of curses.
    getmaxyx is part of Technical Standard X/Open Curses Issue 4, Version 2 (1996).
    http://pubs.opengroup.org/onlinepubs/9693989999/toc.pdf see page 106 */
 #ifndef getmaxyx
-# define getmaxyx(win,y,x)     ((y) = (win)->_maxy + 1, (x) = (win)->_maxx + 1)
+#define getmaxyx(win,y,x)      ((y) = (win)->_maxy + 1, (x) = (win)->_maxx + 1)
 #endif
 
 #include "mtr.h"
@@ -72,669 +72,741 @@ static char block_map[NUM_FACTORS];
 
 enum { black = 1, red, green, yellow, blue, magenta, cyan, white };
 static const int block_col[NUM_FACTORS + 1] = {
-  COLOR_PAIR(red) | A_BOLD,
-  A_NORMAL,
-  COLOR_PAIR(green),
-  COLOR_PAIR(green) | A_BOLD,
-  COLOR_PAIR(yellow) | A_BOLD,
-  COLOR_PAIR(magenta) | A_BOLD,
-  COLOR_PAIR(magenta),
-  COLOR_PAIR(red),
-  COLOR_PAIR(red) | A_BOLD
+    COLOR_PAIR(red) | A_BOLD,
+    A_NORMAL,
+    COLOR_PAIR(green),
+    COLOR_PAIR(green) | A_BOLD,
+    COLOR_PAIR(yellow) | A_BOLD,
+    COLOR_PAIR(magenta) | A_BOLD,
+    COLOR_PAIR(magenta),
+    COLOR_PAIR(red),
+    COLOR_PAIR(red) | A_BOLD
 };
 
-static void pwcenter(char *str) 
+static void pwcenter(
+    char *str)
 {
-  int maxx;
-  size_t cx;
-  int __unused_int ATTRIBUTE_UNUSED;
+    int maxx;
+    size_t cx;
+    int __unused_int ATTRIBUTE_UNUSED;
 
-  getmaxyx(stdscr, __unused_int, maxx);
-  cx = (size_t)(maxx - strlen(str)) / 2;
-  printw("%*s%s", (int)cx, "", str);
+    getmaxyx(stdscr, __unused_int, maxx);
+    cx = (size_t) (maxx - strlen(str)) / 2;
+    printw("%*s%s", (int) cx, "", str);
 }
 
 
-static char *format_number (int n, int w, char *buf)
+static char *format_number(
+    int n,
+    int w,
+    char *buf)
 {
-  if (w != 5)
-    /* XXX todo: implement w != 5.. */
-    snprintf(buf, w + 1, "%s", "unimpl");
-  else if (n < 100000)
-    /* buf is good as-is */ ;
-  else if (n < 1000000)
-    snprintf(buf, w + 1, "%3dk%1d", n / 1000, (n % 1000) / 100);
-  else if (n < 10000000)
-    snprintf(buf, w + 1, "%1dM%03d", n / 1000000, (n % 1000000) / 1000);
-  else if (n < 100000000)
-    snprintf(buf, w + 1, "%2dM%02d", n / 1000000, (n % 1000000) / 10000);
-  else if (n < 1000000000)
-    snprintf(buf, w + 1, "%3dM%01d", n / 1000000, (n % 1000000) / 100000);
-  else /* if (n < 10000000000) */
-    snprintf(buf, w + 1, "%1dG%03d", n / 1000000000, (n % 1000000000) / 1000000);
-
-  return buf;
+    if (w != 5)
+        /* XXX todo: implement w != 5.. */
+        snprintf(buf, w + 1, "%s", "unimpl");
+    else if (n < 100000)
+        /* buf is good as-is */ ;
+    else if (n < 1000000)
+        snprintf(buf, w + 1, "%3dk%1d", n / 1000, (n % 1000) / 100);
+    else if (n < 10000000)
+        snprintf(buf, w + 1, "%1dM%03d", n / 1000000,
+                 (n % 1000000) / 1000);
+    else if (n < 100000000)
+        snprintf(buf, w + 1, "%2dM%02d", n / 1000000,
+                 (n % 1000000) / 10000);
+    else if (n < 1000000000)
+        snprintf(buf, w + 1, "%3dM%01d", n / 1000000,
+                 (n % 1000000) / 100000);
+    else                        /* if (n < 10000000000) */
+        snprintf(buf, w + 1, "%1dG%03d", n / 1000000000,
+                 (n % 1000000000) / 1000000);
+
+    return buf;
 }
 
 
-int mtr_curses_keyaction(struct mtr_ctl *ctl)
+int mtr_curses_keyaction(
+    struct mtr_ctl *ctl)
 {
-  int c = getch();
-  int i = 0;
-  float f = 0.0;
-  char buf[MAXFLD + 1];
-
-  if (c == 'Q') {    /* must be checked before c = tolower(c) */
-    mvprintw(2, 0, "Type of Service(tos): %d\n", ctl->tos);
-    mvprintw(3, 0, "default 0x00, min cost 0x02, rel 0x04,, thr 0x08, low del 0x10...\n");
-    move(2, 22);
-    refresh();
-    while ((c = getch()) != '\n' && i < MAXFLD) {
-      attron(A_BOLD);
-      printw("%c", c);
-      attroff(A_BOLD);
-      refresh();
-      buf[i++] = c;   /* need more checking on 'c' */
+    int c = getch();
+    int i = 0;
+    float f = 0.0;
+    char buf[MAXFLD + 1];
+
+    if (c == 'Q') {             /* must be checked before c = tolower(c) */
+        mvprintw(2, 0, "Type of Service(tos): %d\n", ctl->tos);
+        mvprintw(3, 0,
+                 "default 0x00, min cost 0x02, rel 0x04,, thr 0x08, low del 0x10...\n");
+        move(2, 22);
+        refresh();
+        while ((c = getch()) != '\n' && i < MAXFLD) {
+            attron(A_BOLD);
+            printw("%c", c);
+            attroff(A_BOLD);
+            refresh();
+            buf[i++] = c;       /* need more checking on 'c' */
+        }
+        buf[i] = '\0';
+        ctl->tos = atoi(buf);
+        if (ctl->tos > 255 || ctl->tos < 0)
+            ctl->tos = 0;
+        return ActionNone;
     }
-    buf[i] = '\0';
-    ctl->tos = atoi(buf);
-    if (ctl->tos > 255 || ctl->tos < 0)
-      ctl->tos = 0;
-    return ActionNone;
-  }
-
-  c = tolower(c);
-
-  switch (c) {
-  case 'q':
-  case 3:
-    return ActionQuit;
-  case 12:
-    return ActionClear;
-  case 19:
-  case 'p':
-    return ActionPause;
-  case 17:
-  case ' ':
-    return ActionResume;
-  case 'r':
-    return ActionReset;
-  case 'd':
-    return ActionDisplay;
-  case 'e':
-    return ActionMPLS;
-  case 'n':
-    return ActionDNS;
+
+    c = tolower(c);
+
+    switch (c) {
+    case 'q':
+    case 3:
+        return ActionQuit;
+    case 12:
+        return ActionClear;
+    case 19:
+    case 'p':
+        return ActionPause;
+    case 17:
+    case ' ':
+        return ActionResume;
+    case 'r':
+        return ActionReset;
+    case 'd':
+        return ActionDisplay;
+    case 'e':
+        return ActionMPLS;
+    case 'n':
+        return ActionDNS;
 #ifdef HAVE_IPINFO
-  case 'y':
-    return ActionII;
-  case 'z':
-    return ActionAS;
+    case 'y':
+        return ActionII;
+    case 'z':
+        return ActionAS;
 #endif
-  case '+':
-    return ActionScrollDown;
-  case '-':
-    return ActionScrollUp;
-  case 's':
-    mvprintw(2, 0, "Change Packet Size: %d\n", ctl->cpacketsize);
-    mvprintw(3, 0, "Size Range: %d-%d, < 0:random.\n", MINPACKET, MAXPACKET);
-    move(2, 20);
-    refresh();
-    while ((c = getch()) != '\n' && i < MAXFLD) {
-      attron(A_BOLD);
-      printw("%c", c);
-      attroff(A_BOLD);
-      refresh();
-      buf[i++] = c;   /* need more checking on 'c' */
-    }
-    buf[i] = '\0';
-    ctl->cpacketsize = atoi(buf);
-    return ActionNone;
-  case 'b':
-    mvprintw(2, 0, "Ping Bit Pattern: %d\n", ctl->bitpattern);
-    mvprintw(3, 0, "Pattern Range: 0(0x00)-255(0xff), <0 random.\n");
-    move(2, 18);
-    refresh();
-    while ((c = getch()) != '\n' && i < MAXFLD) {
-      attron(A_BOLD);
-      printw("%c", c);
-      attroff(A_BOLD);
-      refresh();
-      buf[i++] = c;   /* need more checking on 'c' */
-    }
-    buf[i] = '\0';
-    ctl->bitpattern = atoi(buf);
-    if (ctl->bitpattern > 255)
-      ctl->bitpattern = -1;
-    return ActionNone;
-  case 'i':
-    mvprintw(2, 0, "Interval : %0.0f\n\n", ctl->WaitTime);
-    move(2, 11);
-    refresh();
-    while ((c = getch()) != '\n' && i < MAXFLD) {
-      attron(A_BOLD);
-      printw("%c", c);
-      attroff(A_BOLD);
-      refresh();
-      buf[i++] = c;   /* need more checking on 'c' */
-    }
-    buf[i] = '\0';
-
-    f = atof(buf);
+    case '+':
+        return ActionScrollDown;
+    case '-':
+        return ActionScrollUp;
+    case 's':
+        mvprintw(2, 0, "Change Packet Size: %d\n", ctl->cpacketsize);
+        mvprintw(3, 0, "Size Range: %d-%d, < 0:random.\n", MINPACKET,
+                 MAXPACKET);
+        move(2, 20);
+        refresh();
+        while ((c = getch()) != '\n' && i < MAXFLD) {
+            attron(A_BOLD);
+            printw("%c", c);
+            attroff(A_BOLD);
+            refresh();
+            buf[i++] = c;       /* need more checking on 'c' */
+        }
+        buf[i] = '\0';
+        ctl->cpacketsize = atoi(buf);
+        return ActionNone;
+    case 'b':
+        mvprintw(2, 0, "Ping Bit Pattern: %d\n", ctl->bitpattern);
+        mvprintw(3, 0, "Pattern Range: 0(0x00)-255(0xff), <0 random.\n");
+        move(2, 18);
+        refresh();
+        while ((c = getch()) != '\n' && i < MAXFLD) {
+            attron(A_BOLD);
+            printw("%c", c);
+            attroff(A_BOLD);
+            refresh();
+            buf[i++] = c;       /* need more checking on 'c' */
+        }
+        buf[i] = '\0';
+        ctl->bitpattern = atoi(buf);
+        if (ctl->bitpattern > 255)
+            ctl->bitpattern = -1;
+        return ActionNone;
+    case 'i':
+        mvprintw(2, 0, "Interval : %0.0f\n\n", ctl->WaitTime);
+        move(2, 11);
+        refresh();
+        while ((c = getch()) != '\n' && i < MAXFLD) {
+            attron(A_BOLD);
+            printw("%c", c);
+            attroff(A_BOLD);
+            refresh();
+            buf[i++] = c;       /* need more checking on 'c' */
+        }
+        buf[i] = '\0';
 
-    if (f <= 0.0)
-      return ActionNone;
-    if (getuid() != 0 && f < 1.0)
-      return ActionNone;
-    ctl->WaitTime = f;
+        f = atof(buf);
 
-    return ActionNone;
-  case 'f':
-    mvprintw(2, 0, "First TTL: %d\n\n", ctl->fstTTL);
-    move(2, 11);
-    refresh();
-    while ((c = getch()) != '\n' && i < MAXFLD) {
-      attron(A_BOLD);
-      printw("%c", c);
-      attroff(A_BOLD);
-      refresh();
-      buf[i++] = c;   /* need more checking on 'c' */
-    }
-    buf[i] = '\0';
-    i = atoi(buf);
+        if (f <= 0.0)
+            return ActionNone;
+        if (getuid() != 0 && f < 1.0)
+            return ActionNone;
+        ctl->WaitTime = f;
 
-    if (i < 1 || i > ctl->maxTTL)
-      return ActionNone;
-    ctl->fstTTL = i;
+        return ActionNone;
+    case 'f':
+        mvprintw(2, 0, "First TTL: %d\n\n", ctl->fstTTL);
+        move(2, 11);
+        refresh();
+        while ((c = getch()) != '\n' && i < MAXFLD) {
+            attron(A_BOLD);
+            printw("%c", c);
+            attroff(A_BOLD);
+            refresh();
+            buf[i++] = c;       /* need more checking on 'c' */
+        }
+        buf[i] = '\0';
+        i = atoi(buf);
 
-    return ActionNone;
-  case 'm':
-    mvprintw(2, 0, "Max TTL: %d\n\n", ctl->maxTTL);
-    move(2, 9);
-    refresh();
-    while ((c = getch()) != '\n' && i < MAXFLD) {
-      attron(A_BOLD);
-      printw("%c", c);
-      attroff(A_BOLD);
-      refresh();
-      buf[i++] = c;   /* need more checking on 'c' */
-    }
-    buf[i] = '\0';
-    i = atoi(buf);
+        if (i < 1 || i > ctl->maxTTL)
+            return ActionNone;
+        ctl->fstTTL = i;
 
-    if (i < ctl->fstTTL || i > (MaxHost - 1))
-      return ActionNone;
-    ctl->maxTTL = i;
+        return ActionNone;
+    case 'm':
+        mvprintw(2, 0, "Max TTL: %d\n\n", ctl->maxTTL);
+        move(2, 9);
+        refresh();
+        while ((c = getch()) != '\n' && i < MAXFLD) {
+            attron(A_BOLD);
+            printw("%c", c);
+            attroff(A_BOLD);
+            refresh();
+            buf[i++] = c;       /* need more checking on 'c' */
+        }
+        buf[i] = '\0';
+        i = atoi(buf);
 
-    return ActionNone;
-  /* fields to display & their ordering */
-  case 'o':
-    mvprintw(2, 0, "Fields: %s\n\n", ctl->fld_active);
+        if (i < ctl->fstTTL || i > (MaxHost - 1))
+            return ActionNone;
+        ctl->maxTTL = i;
 
-    for (i = 0; i < MAXFLD; i++) {
-      if (data_fields[i].descr != NULL)
-        printw("  %s\n", data_fields[i].descr);
-    }
-    printw("\n");
-    move(2, 8);       /* length of "Fields: " */
-    refresh();
+        return ActionNone;
+        /* fields to display & their ordering */
+    case 'o':
+        mvprintw(2, 0, "Fields: %s\n\n", ctl->fld_active);
 
-    i = 0;
-    while ((c = getch()) != '\n' && i < MAXFLD) {
-      if (strchr(ctl->available_options, c)) {
-        attron(A_BOLD);
-        printw("%c", c);
-        attroff(A_BOLD);
+        for (i = 0; i < MAXFLD; i++) {
+            if (data_fields[i].descr != NULL)
+                printw("  %s\n", data_fields[i].descr);
+        }
+        printw("\n");
+        move(2, 8);             /* length of "Fields: " */
         refresh();
-        buf[i++] = c;  /* Only permit values in "available_options" be entered */
-      } else {
-        printf("\a");  /* Illegal character. Beep, ring the bell. */
-      }
-    }
-    buf[i] = '\0';
-    if (strlen(buf) > 0)
-      xstrncpy(ctl->fld_active, buf, 2 * MAXFLD);
-
-    return ActionNone;
-  case 'j':
-    if (strchr(ctl->fld_active, 'N'))
-      /* GeoMean and jitter */
-      xstrncpy(ctl->fld_active, "DR AGJMXI", 2 * MAXFLD);
-    else
-      /* default */
-      xstrncpy(ctl->fld_active, "LS NABWV", 2 * MAXFLD);
-    return ActionNone;
-  case 'u':
-    switch (ctl->mtrtype) {
-    case IPPROTO_ICMP:
-    case IPPROTO_TCP:
-      ctl->mtrtype = IPPROTO_UDP;
-      break;
-    case IPPROTO_UDP:
-      ctl->mtrtype = IPPROTO_ICMP;
-      break;
-    }
-    return ActionNone;
-  case 't':
-    switch (ctl->mtrtype) {
-    case IPPROTO_ICMP:
-    case IPPROTO_UDP:
-      ctl->mtrtype = IPPROTO_TCP;
-      break;
-    case IPPROTO_TCP:
-      ctl->mtrtype = IPPROTO_ICMP;
-      break;
-    }
-    return ActionNone;
-  /* reserve to display help message -Min */
-  case '?':
-  case 'h':
-    mvprintw(2, 0, "Command:\n");
-    printw("  ?|h     help\n");
-    printw("  p       pause (SPACE to resume)\n");
-    printw("  d       switching display mode\n");
-    printw("  e       toggle MPLS information on/off\n");
-    printw("  n       toggle DNS on/off\n");
-    printw("  r       reset all counters\n");
-    printw("  o str   set the columns to display, default str='LRS N BAWV'\n");
-    printw("  j       toggle latency(LS NABWV)/jitter(DR AGJMXI) stats\n");
-    printw("  c <n>   report cycle n, default n=infinite\n");
-    printw("  i <n>   set the ping interval to n seconds, default n=1\n");
-    printw("  f <n>   set the initial time-to-live(ttl), default n=1\n");
-    printw("  m <n>   set the max time-to-live, default n= # of hops\n");
-    printw("  s <n>   set the packet size to n or random(n<0)\n");
-    printw("  b <c>   set ping bit pattern to c(0..255) or random(c<0)\n");
-    printw("  Q <t>   set ping packet's TOS to t\n");
-    printw("  u       switch between ICMP ECHO and UDP datagrams\n");
+
+        i = 0;
+        while ((c = getch()) != '\n' && i < MAXFLD) {
+            if (strchr(ctl->available_options, c)) {
+                attron(A_BOLD);
+                printw("%c", c);
+                attroff(A_BOLD);
+                refresh();
+                buf[i++] = c;   /* Only permit values in "available_options" be entered */
+            } else {
+                printf("\a");   /* Illegal character. Beep, ring the bell. */
+            }
+        }
+        buf[i] = '\0';
+        if (strlen(buf) > 0)
+            xstrncpy(ctl->fld_active, buf, 2 * MAXFLD);
+
+        return ActionNone;
+    case 'j':
+        if (strchr(ctl->fld_active, 'N'))
+            /* GeoMean and jitter */
+            xstrncpy(ctl->fld_active, "DR AGJMXI", 2 * MAXFLD);
+        else
+            /* default */
+            xstrncpy(ctl->fld_active, "LS NABWV", 2 * MAXFLD);
+        return ActionNone;
+    case 'u':
+        switch (ctl->mtrtype) {
+        case IPPROTO_ICMP:
+        case IPPROTO_TCP:
+            ctl->mtrtype = IPPROTO_UDP;
+            break;
+        case IPPROTO_UDP:
+            ctl->mtrtype = IPPROTO_ICMP;
+            break;
+        }
+        return ActionNone;
+    case 't':
+        switch (ctl->mtrtype) {
+        case IPPROTO_ICMP:
+        case IPPROTO_UDP:
+            ctl->mtrtype = IPPROTO_TCP;
+            break;
+        case IPPROTO_TCP:
+            ctl->mtrtype = IPPROTO_ICMP;
+            break;
+        }
+        return ActionNone;
+        /* reserve to display help message -Min */
+    case '?':
+    case 'h':
+        mvprintw(2, 0, "Command:\n");
+        printw("  ?|h     help\n");
+        printw("  p       pause (SPACE to resume)\n");
+        printw("  d       switching display mode\n");
+        printw("  e       toggle MPLS information on/off\n");
+        printw("  n       toggle DNS on/off\n");
+        printw("  r       reset all counters\n");
+        printw
+            ("  o str   set the columns to display, default str='LRS N BAWV'\n");
+        printw
+            ("  j       toggle latency(LS NABWV)/jitter(DR AGJMXI) stats\n");
+        printw("  c <n>   report cycle n, default n=infinite\n");
+        printw
+            ("  i <n>   set the ping interval to n seconds, default n=1\n");
+        printw
+            ("  f <n>   set the initial time-to-live(ttl), default n=1\n");
+        printw
+            ("  m <n>   set the max time-to-live, default n= # of hops\n");
+        printw("  s <n>   set the packet size to n or random(n<0)\n");
+        printw
+            ("  b <c>   set ping bit pattern to c(0..255) or random(c<0)\n");
+        printw("  Q <t>   set ping packet's TOS to t\n");
+        printw("  u       switch between ICMP ECHO and UDP datagrams\n");
 #ifdef HAVE_IPINFO
-    printw("  y       switching IP info\n");
-    printw("  z       toggle ASN info on/off\n");
+        printw("  y       switching IP info\n");
+        printw("  z       toggle ASN info on/off\n");
 #endif
-    printw("\n");
-    printw(" press any key to go back...");
-    getch();          /* read and ignore 'any key' */
-    return ActionNone;
-  default:            /* ignore unknown input */
-    return ActionNone;
-  }
+        printw("\n");
+        printw(" press any key to go back...");
+        getch();                /* read and ignore 'any key' */
+        return ActionNone;
+    default:                   /* ignore unknown input */
+        return ActionNone;
+    }
 }
 
 
-static void format_field (char *dst, int dst_length, const char *format, int n)
+static void format_field(
+    char *dst,
+    int dst_length,
+    const char *format,
+    int n)
 {
-  if (index (format, 'N' ) ) {
-    *dst++ = ' ';
-    format_number (n, 5, dst);
-  } else if (strchr( format, 'f' ) ) {
-    /* this is for fields where we measure integer microseconds but
-       display floating point miliseconds. Convert to float here. */
-    snprintf(dst, dst_length, format, n / 1000.0 );
-    /* this was marked as a temporary hack over 10 years ago. -- REW */
-  } else {
-    snprintf(dst, dst_length, format, n);
-  } 
-} 
-
-static void mtr_curses_hosts(struct mtr_ctl *ctl, int startstat)
+    if (index(format, 'N')) {
+        *dst++ = ' ';
+        format_number(n, 5, dst);
+    } else if (strchr(format, 'f')) {
+        /* this is for fields where we measure integer microseconds but
+           display floating point miliseconds. Convert to float here. */
+        snprintf(dst, dst_length, format, n / 1000.0);
+        /* this was marked as a temporary hack over 10 years ago. -- REW */
+    } else {
+        snprintf(dst, dst_length, format, n);
+    }
+}
+
+static void mtr_curses_hosts(
+    struct mtr_ctl *ctl,
+    int startstat)
 {
-  int max;
-  int at;
-  struct mplslen *mpls, *mplss;
-  ip_t *addr, *addrs;
-  int y;
-  char *name;
-
-  int i, j, k;
-  int hd_len;
-  char buf[1024];
-  int __unused_int ATTRIBUTE_UNUSED;
-
-  max = net_max(ctl);
-
-  for(at = net_min(ctl) + ctl->display_offset; at < max; at++) {
-    printw("%2d. ", at + 1);
-    addr = net_addr(at);
-    mpls = net_mpls(at);
-
-    if( addrcmp( (void *) addr, (void *) &ctl->unspec_addr, ctl->af ) != 0 ) {
-      name = dns_lookup(ctl, addr);
-      if (! net_up(at))
-       attron(A_BOLD);
+    int max;
+    int at;
+    struct mplslen *mpls, *mplss;
+    ip_t *addr, *addrs;
+    int y;
+    char *name;
+
+    int i, j, k;
+    int hd_len;
+    char buf[1024];
+    int __unused_int ATTRIBUTE_UNUSED;
+
+    max = net_max(ctl);
+
+    for (at = net_min(ctl) + ctl->display_offset; at < max; at++) {
+        printw("%2d. ", at + 1);
+        addr = net_addr(at);
+        mpls = net_mpls(at);
+
+        if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af) !=
+            0) {
+            name = dns_lookup(ctl, addr);
+            if (!net_up(at))
+                attron(A_BOLD);
 #ifdef HAVE_IPINFO
-      if (is_printii(ctl))
-        printw(fmt_ipinfo(ctl, addr));
+            if (is_printii(ctl))
+                printw(fmt_ipinfo(ctl, addr));
 #endif
-      if(name != NULL) {
-        if (ctl->show_ips) printw("%s (%s)", name, strlongip(ctl, addr));
-        else printw("%s", name);
-      } else {
-       printw("%s", strlongip(ctl,  addr ) );
-      }
-      attroff(A_BOLD);
-
-      getyx(stdscr, y, __unused_int);
-      move(y, startstat);
-
-      /* net_xxx returns times in usecs. Just display millisecs */
-      hd_len = 0;
-      for( i=0; i<MAXFLD; i++ ) {
-       /* Ignore options that don't exist */
-       /* On the other hand, we now check the input side. Shouldn't happen, 
-          can't be careful enough. */
-       j = ctl->fld_index[ctl->fld_active[i]];
-       if (j == -1) continue; 
-        format_field (
-          buf+hd_len, sizeof(buf) - hd_len,
-          data_fields[j].format, data_fields[j].net_xxx(at));
-       hd_len +=  data_fields[j].length;
-      }
-      buf[hd_len] = 0;
-      printw("%s", buf);
-
-      for (k=0; k < mpls->labels && ctl->enablempls; k++) {
-        printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
-      }
-
-      /* Multi path */
-      for (i=0; i < MAXPATH; i++ ) {
-        addrs = net_addrs(at, i);
-        mplss = net_mplss(at, i);
-       if ( addrcmp( (void *) addrs, (void *) addr, ctl->af ) == 0 ) continue;
-       if ( addrcmp( (void *) addrs, (void *) &ctl->unspec_addr, ctl->af ) == 0 ) break;
-
-        name = dns_lookup(ctl, addrs);
-        if (! net_up(at)) attron(A_BOLD);
-        printw("\n    ");
+            if (name != NULL) {
+                if (ctl->show_ips)
+                    printw("%s (%s)", name, strlongip(ctl, addr));
+                else
+                    printw("%s", name);
+            } else {
+                printw("%s", strlongip(ctl, addr));
+            }
+            attroff(A_BOLD);
+
+            getyx(stdscr, y, __unused_int);
+            move(y, startstat);
+
+            /* net_xxx returns times in usecs. Just display millisecs */
+            hd_len = 0;
+            for (i = 0; i < MAXFLD; i++) {
+                /* Ignore options that don't exist */
+                /* On the other hand, we now check the input side. Shouldn't happen, 
+                   can't be careful enough. */
+                j = ctl->fld_index[ctl->fld_active[i]];
+                if (j == -1)
+                    continue;
+                format_field(buf + hd_len, sizeof(buf) - hd_len,
+                             data_fields[j].format,
+                             data_fields[j].net_xxx(at));
+                hd_len += data_fields[j].length;
+            }
+            buf[hd_len] = 0;
+            printw("%s", buf);
+
+            for (k = 0; k < mpls->labels && ctl->enablempls; k++) {
+                printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]",
+                       mpls->label[k], mpls->exp[k], mpls->s[k],
+                       mpls->ttl[k]);
+            }
+
+            /* Multi path */
+            for (i = 0; i < MAXPATH; i++) {
+                addrs = net_addrs(at, i);
+                mplss = net_mplss(at, i);
+                if (addrcmp((void *) addrs, (void *) addr, ctl->af) == 0)
+                    continue;
+                if (addrcmp
+                    ((void *) addrs, (void *) &ctl->unspec_addr,
+                     ctl->af) == 0)
+                    break;
+
+                name = dns_lookup(ctl, addrs);
+                if (!net_up(at))
+                    attron(A_BOLD);
+                printw("\n    ");
 #ifdef HAVE_IPINFO
-        if (is_printii(ctl))
-          printw(fmt_ipinfo(ctl, addrs));
+                if (is_printii(ctl))
+                    printw(fmt_ipinfo(ctl, addrs));
 #endif
-        if (name != NULL) {
-         if (ctl->show_ips) printw("%s (%s)", name, strlongip(ctl, addrs));
-         else printw("%s", name);
+                if (name != NULL) {
+                    if (ctl->show_ips)
+                        printw("%s (%s)", name, strlongip(ctl, addrs));
+                    else
+                        printw("%s", name);
+                } else {
+                    printw("%s", strlongip(ctl, addrs));
+                }
+                for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
+                    printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]",
+                           mplss->label[k], mplss->exp[k], mplss->s[k],
+                           mplss->ttl[k]);
+                }
+                attroff(A_BOLD);
+            }
+
         } else {
-         printw("%s", strlongip(ctl,  addrs ) );
+            printw("???");
         }
-        for (k=0; k < mplss->labels && ctl->enablempls; k++) {
-          printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]", mplss->label[k], mplss->exp[k], mplss->s[k], mplss->ttl[k]);
-        }
-        attroff(A_BOLD);
-      }
 
-    } else {
-      printw("???");
+        printw("\n");
     }
-
-    printw("\n");
-  }
-  move(2, 0);
+    move(2, 0);
 }
 
-static void mtr_gen_scale(struct mtr_ctl *ctl)
+static void mtr_gen_scale(
+    struct mtr_ctl *ctl)
 {
-       int *saved, i, max, at;
-       int range;
-       static int low_ms, high_ms;
-
-       low_ms = 1000000;
-       high_ms = -1;
-
-       for (i = 0; i < NUM_FACTORS; i++) {
-               scale[i] = 0;
-       }
-       max = net_max(ctl);
-       for (at = ctl->display_offset; at < max; at++) {
-               saved = net_saved_pings(at);
-               for (i = 0; i < SAVED_PINGS; i++) {
-                       if (saved[i] < 0) continue;
-                       if (saved[i] < low_ms) {
-                               low_ms = saved[i];
-                       }
-                       if (saved[i] > high_ms) {
-                               high_ms = saved[i];
-                       }
-               }
-       }
-       range = high_ms - low_ms;
-       for (i = 0; i < NUM_FACTORS; i++) {
-               scale[i] = low_ms + ((double)range * factors[i]);
-       }
+    int *saved, i, max, at;
+    int range;
+    static int low_ms, high_ms;
+
+    low_ms = 1000000;
+    high_ms = -1;
+
+    for (i = 0; i < NUM_FACTORS; i++) {
+        scale[i] = 0;
+    }
+    max = net_max(ctl);
+    for (at = ctl->display_offset; at < max; at++) {
+        saved = net_saved_pings(at);
+        for (i = 0; i < SAVED_PINGS; i++) {
+            if (saved[i] < 0)
+                continue;
+            if (saved[i] < low_ms) {
+                low_ms = saved[i];
+            }
+            if (saved[i] > high_ms) {
+                high_ms = saved[i];
+            }
+        }
+    }
+    range = high_ms - low_ms;
+    for (i = 0; i < NUM_FACTORS; i++) {
+        scale[i] = low_ms + ((double) range * factors[i]);
+    }
 }
 
-static void mtr_curses_init(void) {
-       int i;
-       int block_split;
-
-       /* Initialize factors to a log scale. */
-       for (i = 0; i < NUM_FACTORS; i++) {
-               factors[i] = ((double)1 / NUM_FACTORS) * (i + 1);
-               factors[i] *= factors[i]; /* Squared. */
-       }
-
-       /* Initialize block_map.  The block_split is always smaller than 9 */
-       block_split = (NUM_FACTORS - 2) / 2;
-       for (i = 1; i <= block_split; i++) {
-               block_map[i] = '0' + i;
-       }
-       for (i = block_split+1; i < NUM_FACTORS-1; i++) {
-               block_map[i] = 'a' + i - block_split - 1;
-       }
-       block_map[0] = '.';
-       block_map[NUM_FACTORS-1] = '>';
+static void mtr_curses_init(
+    void)
+{
+    int i;
+    int block_split;
+
+    /* Initialize factors to a log scale. */
+    for (i = 0; i < NUM_FACTORS; i++) {
+        factors[i] = ((double) 1 / NUM_FACTORS) * (i + 1);
+        factors[i] *= factors[i];       /* Squared. */
+    }
+
+    /* Initialize block_map.  The block_split is always smaller than 9 */
+    block_split = (NUM_FACTORS - 2) / 2;
+    for (i = 1; i <= block_split; i++) {
+        block_map[i] = '0' + i;
+    }
+    for (i = block_split + 1; i < NUM_FACTORS - 1; i++) {
+        block_map[i] = 'a' + i - block_split - 1;
+    }
+    block_map[0] = '.';
+    block_map[NUM_FACTORS - 1] = '>';
 }
 
-static void mtr_print_scaled(int ms) 
+static void mtr_print_scaled(
+    int ms)
 {
-       int i;
-
-       for (i = 0; i < NUM_FACTORS; i++) {
-               if (ms <= scale[i]) {
-                       attrset(block_col[i+1]);
-                       printw("%c", block_map[i]);
-                       attrset(A_NORMAL);
-                       return;
-               }
-       }
-       printw(">");
+    int i;
+
+    for (i = 0; i < NUM_FACTORS; i++) {
+        if (ms <= scale[i]) {
+            attrset(block_col[i + 1]);
+            printw("%c", block_map[i]);
+            attrset(A_NORMAL);
+            return;
+        }
+    }
+    printw(">");
 }
 
 
-static void mtr_fill_graph(struct mtr_ctl *ctl, int at, int cols)
+static void mtr_fill_graph(
+    struct mtr_ctl *ctl,
+    int at,
+    int cols)
 {
-       int* saved;
-       int i;
-
-       saved = net_saved_pings(at);
-       for (i = SAVED_PINGS-cols; i < SAVED_PINGS; i++) {
-               if (saved[i] == -2) {
-                       printw(" ");
-               } else if (saved[i] == -1) {
-                       attrset(block_col[0]);
-                       printw("%c", '?');
-                       attrset(A_NORMAL);
-               } else {
-                       if (ctl->display_mode == DisplayModeBlockmap) {
-                               if (saved[i] > scale[6]) {
-                                       printw("%c", block_map[NUM_FACTORS-1]);
-                               } else {
-                                       printw(".");
-                               }
-                       } else {
-                               mtr_print_scaled(saved[i]);
-                       }
-               }
-       }
+    int *saved;
+    int i;
+
+    saved = net_saved_pings(at);
+    for (i = SAVED_PINGS - cols; i < SAVED_PINGS; i++) {
+        if (saved[i] == -2) {
+            printw(" ");
+        } else if (saved[i] == -1) {
+            attrset(block_col[0]);
+            printw("%c", '?');
+            attrset(A_NORMAL);
+        } else {
+            if (ctl->display_mode == DisplayModeBlockmap) {
+                if (saved[i] > scale[6]) {
+                    printw("%c", block_map[NUM_FACTORS - 1]);
+                } else {
+                    printw(".");
+                }
+            } else {
+                mtr_print_scaled(saved[i]);
+            }
+        }
+    }
 }
 
 
-static void mtr_curses_graph(struct mtr_ctl *ctl, int startstat, int cols)
+static void mtr_curses_graph(
+    struct mtr_ctl *ctl,
+    int startstat,
+    int cols)
 {
-       int max, at, y;
-       ip_t * addr;
-       char* name;
-       int __unused_int ATTRIBUTE_UNUSED;
+    int max, at, y;
+    ip_t *addr;
+    char *name;
+    int __unused_int ATTRIBUTE_UNUSED;
 
-       max = net_max(ctl);
+    max = net_max(ctl);
 
-       for (at = ctl->display_offset; at < max; at++) {
-               printw("%2d. ", at+1);
+    for (at = ctl->display_offset; at < max; at++) {
+        printw("%2d. ", at + 1);
 
-               addr = net_addr(at);
-               if (!addr) {
-                       printw("???\n");
-                       continue;
-               }
+        addr = net_addr(at);
+        if (!addr) {
+            printw("???\n");
+            continue;
+        }
 
-               if (! net_up(at))
-                       attron(A_BOLD);
-               if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
+        if (!net_up(at))
+            attron(A_BOLD);
+        if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
 #ifdef HAVE_IPINFO
-                       if (is_printii(ctl))
-                               printw(fmt_ipinfo(ctl, addr));
+            if (is_printii(ctl))
+                printw(fmt_ipinfo(ctl, addr));
 #endif
-                       name = dns_lookup(ctl, addr);
-                       printw("%s", name?name:strlongip(ctl, addr));
-               } else
-                       printw("???");
-               attroff(A_BOLD);
-
-               getyx(stdscr, y, __unused_int);
-               move(y, startstat);
-
-               printw(" ");
-               mtr_fill_graph(ctl, at, cols);
-               printw("\n");
-       }
+            name = dns_lookup(ctl, addr);
+            printw("%s", name ? name : strlongip(ctl, addr));
+        } else
+            printw("???");
+        attroff(A_BOLD);
+
+        getyx(stdscr, y, __unused_int);
+        move(y, startstat);
+
+        printw(" ");
+        mtr_fill_graph(ctl, at, cols);
+        printw("\n");
+    }
 }
 
 
-void mtr_curses_redraw(struct mtr_ctl *ctl)
+void mtr_curses_redraw(
+    struct mtr_ctl *ctl)
 {
-  int maxx;
-  int startstat;
-  int rowstat;
-  time_t t;
-  int __unused_int ATTRIBUTE_UNUSED;
-
-  int i, j;
-  int  hd_len = 0;
-  char buf[1024];
-  char fmt[16];
-  
-
-  erase();
-  getmaxyx(stdscr, __unused_int, maxx);
-
-  rowstat = 5;
-
-  move(0, 0);
-  attron(A_BOLD);
-  snprintf(buf, sizeof(buf), "%s%s%s", "My traceroute  [v", PACKAGE_VERSION, "]");
-  pwcenter(buf);
-  attroff(A_BOLD);
-
-  mvprintw(1, 0, "%s (%s)", ctl->LocalHostname, net_localaddr());
-  t = time(NULL);
-  mvprintw(1, maxx-25, iso_time(&t));
-  printw("\n");
-
-  printw("Keys:  ");
-  attron(A_BOLD); printw("H"); attroff(A_BOLD); printw("elp   ");
-  attron(A_BOLD); printw("D"); attroff(A_BOLD); printw("isplay mode   ");
-  attron(A_BOLD); printw("R"); attroff(A_BOLD); printw("estart statistics   ");
-  attron(A_BOLD); printw("O"); attroff(A_BOLD); printw("rder of fields   ");
-  attron(A_BOLD); printw("q"); attroff(A_BOLD); printw("uit\n");
-  
-  if (ctl->display_mode == DisplayModeDefault) {
-    for (i=0; i < MAXFLD; i++ ) {
-       j = ctl->fld_index[ctl->fld_active[i]];
-       if (j < 0) continue;
-
-       snprintf( fmt, sizeof(fmt), "%%%ds", data_fields[j].length );
-        snprintf(
-            buf + hd_len, sizeof(buf) - hd_len, fmt, data_fields[j].title );
-       hd_len +=  data_fields[j].length;
-    }
+    int maxx;
+    int startstat;
+    int rowstat;
+    time_t t;
+    int __unused_int ATTRIBUTE_UNUSED;
+
+    int i, j;
+    int hd_len = 0;
+    char buf[1024];
+    char fmt[16];
+
+
+    erase();
+    getmaxyx(stdscr, __unused_int, maxx);
+
+    rowstat = 5;
+
+    move(0, 0);
     attron(A_BOLD);
-    mvprintw(rowstat - 1, 0, " Host");
-    mvprintw(rowstat - 1, maxx-hd_len-1, "%s", buf);
-    mvprintw(rowstat - 2, maxx-hd_len-1, "   Packets               Pings");
+    snprintf(buf, sizeof(buf), "%s%s%s", "My traceroute  [v",
+             PACKAGE_VERSION, "]");
+    pwcenter(buf);
     attroff(A_BOLD);
 
-    move(rowstat, 0);
-    mtr_curses_hosts(ctl, maxx-hd_len-1);
+    mvprintw(1, 0, "%s (%s)", ctl->LocalHostname, net_localaddr());
+    t = time(NULL);
+    mvprintw(1, maxx - 25, iso_time(&t));
+    printw("\n");
 
-  } else {
-    char msg[80];
-    int padding = 30;
-    int max_cols;
+    printw("Keys:  ");
+    attron(A_BOLD);
+    printw("H");
+    attroff(A_BOLD);
+    printw("elp   ");
+    attron(A_BOLD);
+    printw("D");
+    attroff(A_BOLD);
+    printw("isplay mode   ");
+    attron(A_BOLD);
+    printw("R");
+    attroff(A_BOLD);
+    printw("estart statistics   ");
+    attron(A_BOLD);
+    printw("O");
+    attroff(A_BOLD);
+    printw("rder of fields   ");
+    attron(A_BOLD);
+    printw("q");
+    attroff(A_BOLD);
+    printw("uit\n");
+
+    if (ctl->display_mode == DisplayModeDefault) {
+        for (i = 0; i < MAXFLD; i++) {
+            j = ctl->fld_index[ctl->fld_active[i]];
+            if (j < 0)
+                continue;
+
+            snprintf(fmt, sizeof(fmt), "%%%ds", data_fields[j].length);
+            snprintf(buf + hd_len, sizeof(buf) - hd_len, fmt,
+                     data_fields[j].title);
+            hd_len += data_fields[j].length;
+        }
+        attron(A_BOLD);
+        mvprintw(rowstat - 1, 0, " Host");
+        mvprintw(rowstat - 1, maxx - hd_len - 1, "%s", buf);
+        mvprintw(rowstat - 2, maxx - hd_len - 1,
+                 "   Packets               Pings");
+        attroff(A_BOLD);
+
+        move(rowstat, 0);
+        mtr_curses_hosts(ctl, maxx - hd_len - 1);
+
+    } else {
+        char msg[80];
+        int padding = 30;
+        int max_cols;
 
 #ifdef HAVE_IPINFO
-    if (is_printii(ctl))
-      padding += get_iiwidth(ctl->ipinfo_no);
+        if (is_printii(ctl))
+            padding += get_iiwidth(ctl->ipinfo_no);
 #endif
-    max_cols = maxx <= SAVED_PINGS + padding ? maxx-padding : SAVED_PINGS;
-    startstat = padding - 2;
+        max_cols =
+            maxx <= SAVED_PINGS + padding ? maxx - padding : SAVED_PINGS;
+        startstat = padding - 2;
 
-    snprintf(msg, sizeof(msg), " Last %3d pings", max_cols);
-    mvprintw(rowstat - 1, startstat, msg);
-    
-    attroff(A_BOLD);
-    move(rowstat, 0);
+        snprintf(msg, sizeof(msg), " Last %3d pings", max_cols);
+        mvprintw(rowstat - 1, startstat, msg);
 
-    mtr_gen_scale(ctl);
-    mtr_curses_graph(ctl, startstat, max_cols);
+        attroff(A_BOLD);
+        move(rowstat, 0);
 
-    printw("\n");
-    attron(A_BOLD);
-    printw("Scale:");
-    attroff(A_BOLD);
-    
-    for (i = 0; i < NUM_FACTORS-1; i++) {
-      printw("  ");
-      attrset(block_col[i+1]);
-      printw("%c", block_map[i]);
-      attrset(A_NORMAL);
-      printw(":%d ms", scale[i]/1000);
+        mtr_gen_scale(ctl);
+        mtr_curses_graph(ctl, startstat, max_cols);
+
+        printw("\n");
+        attron(A_BOLD);
+        printw("Scale:");
+        attroff(A_BOLD);
+
+        for (i = 0; i < NUM_FACTORS - 1; i++) {
+            printw("  ");
+            attrset(block_col[i + 1]);
+            printw("%c", block_map[i]);
+            attrset(A_NORMAL);
+            printw(":%d ms", scale[i] / 1000);
+        }
+        printw("  ");
+        attrset(block_col[NUM_FACTORS]);
+        printw("%c", block_map[NUM_FACTORS - 1]);
+        attrset(A_NORMAL);
     }
-    printw("  ");
-    attrset(block_col[NUM_FACTORS]);
-    printw("%c", block_map[NUM_FACTORS-1]);
-    attrset(A_NORMAL);
-  }
 
-  refresh();
+    refresh();
 }
 
 
-void mtr_curses_open(struct mtr_ctl *ctl)
+void mtr_curses_open(
+    struct mtr_ctl *ctl)
 {
-  int bg_col = 0;
-  int i;
-
-  initscr();
-  raw();
-  noecho(); 
-  start_color();
-  if (use_default_colors() == OK)
-    bg_col = -1;
-  for (i = 0; i < NUM_FACTORS; i++)
-      init_pair(i+1, i, bg_col);
-
-  mtr_curses_init();
-  mtr_curses_redraw(ctl);
+    int bg_col = 0;
+    int i;
+
+    initscr();
+    raw();
+    noecho();
+    start_color();
+    if (use_default_colors() == OK)
+        bg_col = -1;
+    for (i = 0; i < NUM_FACTORS; i++)
+        init_pair(i + 1, i, bg_col);
+
+    mtr_curses_init();
+    mtr_curses_redraw(ctl);
 }
 
 
-void mtr_curses_close(void)
-{  
-  printw("\n");
-  endwin();
+void mtr_curses_close(
+    void)
+{
+    printw("\n");
+    endwin();
 }
 
 
-void mtr_curses_clear(struct mtr_ctl *ctl)
+void mtr_curses_clear(
+    struct mtr_ctl *ctl)
 {
-  mtr_curses_close();
-  mtr_curses_open(ctl);
+    mtr_curses_close();
+    mtr_curses_open(ctl);
 }
index 00fa5d552e173548f50a0cc81904861dbbfe68ec..4c088896c781fbd7fcc2ecf3728ed63d7ea13b3a 100644 (file)
 #include "asn.h"
 
 #ifdef HAVE_CURSES
-# include "mtr-curses.h"
+#include "mtr-curses.h"
 #endif
 
 #ifdef HAVE_GTK
-# include "mtr-gtk.h"
+#include "mtr-gtk.h"
 #endif
 
 #include "split.h"
 
 #ifdef HAVE_CURSES
-# define DEFAULT_DISPLAY DisplayCurses
+#define DEFAULT_DISPLAY DisplayCurses
 #else
-# define DEFAULT_DISPLAY DisplayReport
+#define DEFAULT_DISPLAY DisplayReport
 #endif
 
 #ifdef HAVE_GTK
-# define UNUSED_IF_NO_GTK       /* empty */
+#define UNUSED_IF_NO_GTK        /* empty */
 #else
-# define UNUSED_IF_NO_GTK ATTRIBUTE_UNUSED
+#define UNUSED_IF_NO_GTK ATTRIBUTE_UNUSED
 #endif
 
-void display_detect(struct mtr_ctl *ctl, int *argc UNUSED_IF_NO_GTK,
-                          char ***argv UNUSED_IF_NO_GTK)
+void display_detect(
+    struct mtr_ctl *ctl,
+    int *argc UNUSED_IF_NO_GTK,
+    char ***argv UNUSED_IF_NO_GTK)
 {
-  ctl->DisplayMode = DEFAULT_DISPLAY;
+    ctl->DisplayMode = DEFAULT_DISPLAY;
 
 #ifdef HAVE_GTK
-  if(gtk_detect(argc, argv)) {
-    ctl->DisplayMode = DisplayGTK;
-  }
+    if (gtk_detect(argc, argv)) {
+        ctl->DisplayMode = DisplayGTK;
+    }
 #endif
 }
 
 
-void display_open(struct mtr_ctl *ctl)
+void display_open(
+    struct mtr_ctl *ctl)
 {
-  switch(ctl->DisplayMode) {
-
-  case DisplayReport:
-    report_open();
-    break;
-  case DisplayTXT:
-    txt_open();
-    break;
-  case DisplayJSON:
-    json_open();
-    break;
-  case DisplayXML:
-    xml_open();
-    break;
-  case DisplayCSV:
-    csv_open();
-    break;
+    switch (ctl->DisplayMode) {
+
+    case DisplayReport:
+        report_open();
+        break;
+    case DisplayTXT:
+        txt_open();
+        break;
+    case DisplayJSON:
+        json_open();
+        break;
+    case DisplayXML:
+        xml_open();
+        break;
+    case DisplayCSV:
+        csv_open();
+        break;
 #ifdef HAVE_CURSES
-  case DisplayCurses:
-    mtr_curses_open(ctl);
-# ifdef HAVE_IPINFO
-    asn_open(ctl);
-# endif
-    break;
-#endif
-  case DisplaySplit:
-    split_open();
-    break;
+    case DisplayCurses:
+        mtr_curses_open(ctl);
+#ifdef HAVE_IPINFO
+        asn_open(ctl);
+#endif
+        break;
+#endif
+    case DisplaySplit:
+        split_open();
+        break;
 #ifdef HAVE_GTK
-  case DisplayGTK:
-    gtk_open(ctl);
-# ifdef HAVE_IPINFO
-    asn_open(ctl);
-# endif
-    break;
-#endif
-  }
+    case DisplayGTK:
+        gtk_open(ctl);
+#ifdef HAVE_IPINFO
+        asn_open(ctl);
+#endif
+        break;
+#endif
+    }
 }
 
 
-void display_close(struct mtr_ctl *ctl)
+void display_close(
+    struct mtr_ctl *ctl)
 {
-  time_t now;
-
-  now = time(NULL);
-
-  switch(ctl->DisplayMode) {
-  case DisplayReport:
-    report_close(ctl);
-    break;
-  case DisplayTXT:
-    txt_close(ctl);
-    break;
-  case DisplayJSON:
-    json_close(ctl);
-    break;
-  case DisplayXML:
-    xml_close(ctl);
-    break;
-  case DisplayCSV:
-    csv_close(ctl, now);
-    break;
+    time_t now;
+
+    now = time(NULL);
+
+    switch (ctl->DisplayMode) {
+    case DisplayReport:
+        report_close(ctl);
+        break;
+    case DisplayTXT:
+        txt_close(ctl);
+        break;
+    case DisplayJSON:
+        json_close(ctl);
+        break;
+    case DisplayXML:
+        xml_close(ctl);
+        break;
+    case DisplayCSV:
+        csv_close(ctl, now);
+        break;
 #ifdef HAVE_CURSES
-  case DisplayCurses:
-# ifdef HAVE_IPINFO
-    asn_close(ctl);
-# endif
-    mtr_curses_close();
-    break;
-#endif
-  case DisplaySplit:
-    split_close();
-    break;
+    case DisplayCurses:
+#ifdef HAVE_IPINFO
+        asn_close(ctl);
+#endif
+        mtr_curses_close();
+        break;
+#endif
+    case DisplaySplit:
+        split_close();
+        break;
 #ifdef HAVE_GTK
-  case DisplayGTK:
-    gtk_close();
-    break;
+    case DisplayGTK:
+        gtk_close();
+        break;
 #endif
-  }
+    }
 }
 
 
-void display_redraw(struct mtr_ctl *ctl)
+void display_redraw(
+    struct mtr_ctl *ctl)
 {
-  switch(ctl->DisplayMode) {
+    switch (ctl->DisplayMode) {
 
 #ifdef HAVE_CURSES
-  case DisplayCurses:
-    mtr_curses_redraw(ctl);
-    break;
+    case DisplayCurses:
+        mtr_curses_redraw(ctl);
+        break;
 #endif
 
-  case DisplaySplit:
-    split_redraw(ctl);
-    break;
+    case DisplaySplit:
+        split_redraw(ctl);
+        break;
 
 #ifdef HAVE_GTK
-  case DisplayGTK:
-    gtk_redraw(ctl);
-    break;
+    case DisplayGTK:
+        gtk_redraw(ctl);
+        break;
 #endif
-  }
+    }
 }
 
 
-int display_keyaction(struct mtr_ctl *ctl)
+int display_keyaction(
+    struct mtr_ctl *ctl)
 {
-  switch(ctl->DisplayMode) {
+    switch (ctl->DisplayMode) {
 #ifdef HAVE_CURSES
-  case DisplayCurses:
-    return mtr_curses_keyaction(ctl);
+    case DisplayCurses:
+        return mtr_curses_keyaction(ctl);
 #endif
 
-  case DisplaySplit:
-    return split_keyaction();
+    case DisplaySplit:
+        return split_keyaction();
 
 #ifdef HAVE_GTK
-  case DisplayGTK:
-    return gtk_keyaction();
+    case DisplayGTK:
+        return gtk_keyaction();
 #endif
-  }
-  return 0;
+    }
+    return 0;
 }
 
 
-void display_rawxmit(struct mtr_ctl *ctl, int host, int seq)
+void display_rawxmit(
+    struct mtr_ctl *ctl,
+    int host,
+    int seq)
 {
-  if (ctl->DisplayMode == DisplayRaw)
-    raw_rawxmit (host, seq);
+    if (ctl->DisplayMode == DisplayRaw)
+        raw_rawxmit(host, seq);
 }
 
 
-void display_rawping(struct mtr_ctl *ctl, int host, int msec, int seq)
+void display_rawping(
+    struct mtr_ctl *ctl,
+    int host,
+    int msec,
+    int seq)
 {
-  if (ctl->DisplayMode == DisplayRaw)
-    raw_rawping (ctl, host, msec, seq);
+    if (ctl->DisplayMode == DisplayRaw)
+        raw_rawping(ctl, host, msec, seq);
 }
 
 
-void display_rawhost(struct mtr_ctl *ctl, int host, ip_t *ip_addr)
+void display_rawhost(
+    struct mtr_ctl *ctl,
+    int host,
+    ip_t * ip_addr)
 {
-  if (ctl->DisplayMode == DisplayRaw)
-    raw_rawhost (ctl, host, ip_addr);
+    if (ctl->DisplayMode == DisplayRaw)
+        raw_rawhost(ctl, host, ip_addr);
 }
 
 
-void display_loop(struct mtr_ctl *ctl)
+void display_loop(
+    struct mtr_ctl *ctl)
 {
 #ifdef HAVE_GTK
-  if (ctl->DisplayMode == DisplayGTK)
-    gtk_loop(ctl);
-  else
+    if (ctl->DisplayMode == DisplayGTK)
+        gtk_loop(ctl);
+    else
 #endif
-    select_loop(ctl);
+        select_loop(ctl);
 }
 
 
-void display_clear(struct mtr_ctl *ctl)
+void display_clear(
+    struct mtr_ctl *ctl)
 {
 #ifdef HAVE_CURSES
-  if (ctl->DisplayMode == DisplayCurses)
-    mtr_curses_clear(ctl);
+    if (ctl->DisplayMode == DisplayCurses)
+        mtr_curses_clear(ctl);
 #endif
 }
index 956d1cd092a30bd7108b4bf4dc1c36f7ffe6592f..d82752886458eb1ae53440aca0e2186b78520ae4 100644 (file)
 #include <netinet/in.h>
 
 /* Don't put a trailing comma in enumeration lists. Some compilers 
-   (notably the one on Irix 5.2) do not like that. */ 
-enum { ActionNone,  ActionQuit,  ActionReset,  ActionDisplay, 
-       ActionClear, ActionPause, ActionResume, ActionMPLS, ActionDNS, 
+   (notably the one on Irix 5.2) do not like that. */
+enum { ActionNone, ActionQuit, ActionReset, ActionDisplay,
+    ActionClear, ActionPause, ActionResume, ActionMPLS, ActionDNS,
 #ifdef HAVE_IPINFO
-       ActionII, ActionAS,
+    ActionII, ActionAS,
 #endif
-       ActionScrollDown, ActionScrollUp  };
+    ActionScrollDown, ActionScrollUp
+};
 
 enum {
-  DisplayReport,
+    DisplayReport,
 #ifdef HAVE_CURSES
-  DisplayCurses,
+    DisplayCurses,
 #endif
 #ifdef HAVE_GTK
-  DisplayGTK,
+    DisplayGTK,
 #endif
-  DisplaySplit,
-  DisplayRaw,
-  DisplayXML,
-  DisplayCSV,
-  DisplayTXT,
-  DisplayJSON
+    DisplaySplit,
+    DisplayRaw,
+    DisplayXML,
+    DisplayCSV,
+    DisplayTXT,
+    DisplayJSON
 };
 
 enum {
-  DisplayModeDefault,
-  DisplayModeBlockmap,
-  DisplayModeBlockmapScale,
-  DisplayModeMAX       /* this must be the last DisplayMode entry */
+    DisplayModeDefault,
+    DisplayModeBlockmap,
+    DisplayModeBlockmapScale,
+    DisplayModeMAX              /* this must be the last DisplayMode entry */
 };
 
 /*  Prototypes for display.c  */
-extern void display_detect(struct mtr_ctl *ctl, int *argc, char ***argv);
-extern void display_open(struct mtr_ctl *ctl);
-extern void display_close(struct mtr_ctl *ctl);
-extern void display_redraw(struct mtr_ctl *ctl);
-extern void display_rawxmit(struct mtr_ctl *ctl, int hostnum, int seq);
-extern void display_rawping(struct mtr_ctl *ctl, int hostnum, int msec, int seq);
-extern void display_rawhost(struct mtr_ctl *ctl, int hostnum, ip_t *ip_addr);
-extern int display_keyaction(struct mtr_ctl *ctl);
-extern void display_loop(struct mtr_ctl *ctl);
-extern void display_clear(struct mtr_ctl *ctl);
+extern void display_detect(
+    struct mtr_ctl *ctl,
+    int *argc,
+    char ***argv);
+extern void display_open(
+    struct mtr_ctl *ctl);
+extern void display_close(
+    struct mtr_ctl *ctl);
+extern void display_redraw(
+    struct mtr_ctl *ctl);
+extern void display_rawxmit(
+    struct mtr_ctl *ctl,
+    int hostnum,
+    int seq);
+extern void display_rawping(
+    struct mtr_ctl *ctl,
+    int hostnum,
+    int msec,
+    int seq);
+extern void display_rawhost(
+    struct mtr_ctl *ctl,
+    int hostnum,
+    ip_t * ip_addr);
+extern int display_keyaction(
+    struct mtr_ctl *ctl);
+extern void display_loop(
+    struct mtr_ctl *ctl);
+extern void display_clear(
+    struct mtr_ctl *ctl);
index df0e8c3bb768e53d4a9565725063c7f4ad1412dc..7d5ce1a8166a7d852f4ef27174d2f799a51f0b89 100644 (file)
--- a/ui/dns.c
+++ b/ui/dns.c
@@ -25,9 +25,9 @@
 #include "config.h"
 
 #ifdef HAVE_ERROR_H
-# include <error.h>
+#include <error.h>
 #else
-# include "portability/error.h"
+#include "portability/error.h"
 #endif
 #include <errno.h>
 #include <unistd.h>
 #include "utils.h"
 
 struct dns_results {
-  ip_t ip; 
-  char *name;
-  struct dns_results *next;
+    ip_t ip;
+    char *name;
+    struct dns_results *next;
 };
 
 static struct dns_results *results;
 
-char *strlongip(struct mtr_ctl *ctl, ip_t * ip)
+char *strlongip(
+    struct mtr_ctl *ctl,
+    ip_t * ip)
 {
 #ifdef ENABLE_IPV6
-  static char addrstr[INET6_ADDRSTRLEN];
+    static char addrstr[INET6_ADDRSTRLEN];
 
-  return (char *) inet_ntop( ctl->af, ip, addrstr, sizeof addrstr );
+    return (char *) inet_ntop(ctl->af, ip, addrstr, sizeof addrstr);
 #else
-  return inet_ntoa( *ip );
+    return inet_ntoa(*ip);
 #endif
 }
 
 
 #ifdef ENABLE_IPV6
-# define UNUSED_IF_NO_IPV6 /* empty */
+#define UNUSED_IF_NO_IPV6       /* empty */
 #else
-# define UNUSED_IF_NO_IPV6 ATTRIBUTE_UNUSED
+#define UNUSED_IF_NO_IPV6 ATTRIBUTE_UNUSED
 #endif
 
 static int todns[2], fromdns[2];
 static FILE *fromdnsfp;
 
-static int longipstr( char *s, ip_t *dst, int family UNUSED_IF_NO_IPV6)
+static int longipstr(
+    char *s,
+    ip_t * dst,
+    int family UNUSED_IF_NO_IPV6)
 {
 #ifdef ENABLE_IPV6
-  return inet_pton( family, s, dst );
+    return inet_pton(family, s, dst);
 #else
-  return inet_aton( s, dst );
+    return inet_aton(s, dst);
 #endif
 }
 
 
-struct hostent * dns_forward(const char *name)
+struct hostent *dns_forward(
+    const char *name)
 {
-  struct hostent *host;
+    struct hostent *host;
 
-  if ((host = gethostbyname(name)))
-    return host;
-  else
-    return NULL;
+    if ((host = gethostbyname(name)))
+        return host;
+    else
+        return NULL;
 }
 
 
-static struct dns_results *findip (struct mtr_ctl *ctl, ip_t *ip)
+static struct dns_results *findip(
+    struct mtr_ctl *ctl,
+    ip_t * ip)
 {
-  struct dns_results *t;
-  
-  for (t=results;t;t=t->next) {
-    if (addrcmp ( (void *)ip, (void*) &t->ip, ctl->af) == 0)
-      return t;
-  }
-
-  return NULL;
+    struct dns_results *t;
+
+    for (t = results; t; t = t->next) {
+        if (addrcmp((void *) ip, (void *) &t->ip, ctl->af) == 0)
+            return t;
+    }
+
+    return NULL;
 }
 
-static void set_sockaddr_ip (struct mtr_ctl *ctl, struct sockaddr_storage *sa, ip_t *ip)
+static void set_sockaddr_ip(
+    struct mtr_ctl *ctl,
+    struct sockaddr_storage *sa,
+    ip_t * ip)
 {
-  struct sockaddr_in *sa_in;
-  struct sockaddr_in6 *sa_in6;
-
-  memset (sa, 0, sizeof (struct sockaddr_storage));
-  switch (ctl->af) {
-  case AF_INET:
-    sa_in = (struct sockaddr_in *) sa;
-    sa_in->sin_family = ctl->af;
-    addrcpy ((void *) &sa_in->sin_addr, (void*) ip, ctl->af);
-    break;
-  case AF_INET6:
-    sa_in6 = (struct sockaddr_in6 *) sa;
-    sa_in6->sin6_family = ctl->af;
-    addrcpy ((void *) &sa_in6->sin6_addr,  (void*)ip, ctl->af);
-    break;
-  }
+    struct sockaddr_in *sa_in;
+    struct sockaddr_in6 *sa_in6;
+
+    memset(sa, 0, sizeof(struct sockaddr_storage));
+    switch (ctl->af) {
+    case AF_INET:
+        sa_in = (struct sockaddr_in *) sa;
+        sa_in->sin_family = ctl->af;
+        addrcpy((void *) &sa_in->sin_addr, (void *) ip, ctl->af);
+        break;
+    case AF_INET6:
+        sa_in6 = (struct sockaddr_in6 *) sa;
+        sa_in6->sin6_family = ctl->af;
+        addrcpy((void *) &sa_in6->sin6_addr, (void *) ip, ctl->af);
+        break;
+    }
 }
 
-void dns_open(struct mtr_ctl *ctl)
+void dns_open(
+    struct mtr_ctl *ctl)
 {
-  int pid; 
-  if (pipe (todns) < 0) {
-    error(EXIT_FAILURE, errno, "can't make a pipe for DNS process");
-  }
-
-  if (pipe (fromdns) < 0) {
-    error(EXIT_FAILURE, errno, "can't make a pipe for DNS process");
-  }
-  fflush (stdout);
-  pid = fork ();
-  if (pid < 0) {
-    error(EXIT_FAILURE, errno, "can't fork for DNS process");
-  }
-  if (pid == 0) {
-    char buf[2048];
-    int i;
-    FILE *infp;
-
-    /* Automatically reap children. */
-    if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
-      error(EXIT_FAILURE, errno, "signal");
+    int pid;
+
+    if (pipe(todns) < 0) {
+        error(EXIT_FAILURE, errno, "can't make a pipe for DNS process");
     }
 
-    /* Close all unneccessary FDs.
-       for debugging and error reporting, keep std-in/out/err. */
-    for (i=3;i<fromdns[1];i++) {
-       if (i == todns[0]) continue;
-       if (i == fromdns[1]) continue;
-       close (i);
+    if (pipe(fromdns) < 0) {
+        error(EXIT_FAILURE, errno, "can't make a pipe for DNS process");
     }
-    infp = fdopen (todns[0],"r"); 
-
-    while (fgets (buf, sizeof (buf), infp)) {
-      ip_t host; 
-      struct sockaddr_storage sa;
-      socklen_t salen;
-      char hostname [NI_MAXHOST];
-      char result [INET6_ADDRSTRLEN + NI_MAXHOST + 2];
-
-      if (!fork ()) {
-        int rv;
-
-        buf[strlen(buf)-1] = 0; /* chomp newline. */
-
-        longipstr (buf, &host, ctl->af);
-        set_sockaddr_ip (ctl, &sa, &host);
-        salen = (ctl->af == AF_INET)?sizeof(struct sockaddr_in):
-                                sizeof(struct sockaddr_in6);
-
-        rv = getnameinfo  ((struct sockaddr *) &sa, salen, 
-                              hostname, sizeof (hostname), NULL, 0, 0);
-        if (rv == 0) {
-          snprintf (
-            result, sizeof(result),
-            "%s %s\n", strlongip (ctl, &host), hostname);
-
-          rv = write (fromdns[1], result, strlen (result));
-          if (rv < 0)
-            error (0, errno, "write DNS lookup result");
+    fflush(stdout);
+    pid = fork();
+    if (pid < 0) {
+        error(EXIT_FAILURE, errno, "can't fork for DNS process");
+    }
+    if (pid == 0) {
+        char buf[2048];
+        int i;
+        FILE *infp;
+
+        /* Automatically reap children. */
+        if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
+            error(EXIT_FAILURE, errno, "signal");
         }
 
+        /* Close all unneccessary FDs.
+           for debugging and error reporting, keep std-in/out/err. */
+        for (i = 3; i < fromdns[1]; i++) {
+            if (i == todns[0])
+                continue;
+            if (i == fromdns[1])
+                continue;
+            close(i);
+        }
+        infp = fdopen(todns[0], "r");
+
+        while (fgets(buf, sizeof(buf), infp)) {
+            ip_t host;
+            struct sockaddr_storage sa;
+            socklen_t salen;
+            char hostname[NI_MAXHOST];
+            char result[INET6_ADDRSTRLEN + NI_MAXHOST + 2];
+
+            if (!fork()) {
+                int rv;
+
+                buf[strlen(buf) - 1] = 0;       /* chomp newline. */
+
+                longipstr(buf, &host, ctl->af);
+                set_sockaddr_ip(ctl, &sa, &host);
+                salen = (ctl->af == AF_INET) ? sizeof(struct sockaddr_in) :
+                    sizeof(struct sockaddr_in6);
+
+                rv = getnameinfo((struct sockaddr *) &sa, salen,
+                                 hostname, sizeof(hostname), NULL, 0, 0);
+                if (rv == 0) {
+                    snprintf(result, sizeof(result),
+                             "%s %s\n", strlongip(ctl, &host), hostname);
+
+                    rv = write(fromdns[1], result, strlen(result));
+                    if (rv < 0)
+                        error(0, errno, "write DNS lookup result");
+                }
+
+                exit(EXIT_SUCCESS);
+            }
+        }
         exit(EXIT_SUCCESS);
-      }
+    } else {
+        int flags;
+
+        /* the parent. */
+        close(todns[0]);        /* close the pipe ends we don't need. */
+        close(fromdns[1]);
+        fromdnsfp = fdopen(fromdns[0], "r");
+        flags = fcntl(fromdns[0], F_GETFL, 0);
+        flags |= O_NONBLOCK;
+        fcntl(fromdns[0], F_SETFL, flags);
     }
-    exit(EXIT_SUCCESS);
-  } else {
-     int flags;
-
-     /* the parent. */
-     close (todns[0]); /* close the pipe ends we don't need. */
-     close (fromdns[1]);
-     fromdnsfp = fdopen (fromdns[0],"r"); 
-     flags = fcntl(fromdns[0], F_GETFL, 0);
-     flags |= O_NONBLOCK;
-     fcntl(fromdns[0], F_SETFL, flags);
-  }
 }
 
-int dns_waitfd (void)
+int dns_waitfd(
+    void)
 {
-  return fromdns[0];
+    return fromdns[0];
 }
 
 
-void dns_ack(struct mtr_ctl *ctl)
+void dns_ack(
+    struct mtr_ctl *ctl)
 {
-  char buf[2048], host[NI_MAXHOST], name[NI_MAXHOST];  
-  ip_t hostip; 
-  struct dns_results *r;
-
-  while ( fgets (buf, sizeof (buf),  fromdnsfp )) {
-    sscanf (buf, "%s %s", host, name);
-
-    longipstr (host, &hostip, ctl->af);
-    r = findip (ctl, &hostip);
-    if (r)  
-      r->name = xstrdup (name);
-    else 
-      error (0, 0, "dns_ack: Couldn't find host %s", host);
-  }
+    char buf[2048], host[NI_MAXHOST], name[NI_MAXHOST];
+    ip_t hostip;
+    struct dns_results *r;
+
+    while (fgets(buf, sizeof(buf), fromdnsfp)) {
+        sscanf(buf, "%s %s", host, name);
+
+        longipstr(host, &hostip, ctl->af);
+        r = findip(ctl, &hostip);
+        if (r)
+            r->name = xstrdup(name);
+        else
+            error(0, 0, "dns_ack: Couldn't find host %s", host);
+    }
 }
 
 
 
 #ifdef ENABLE_IPV6
 
-int dns_waitfd6 (void)
+int dns_waitfd6(
+    void)
 {
-  return  -1;
+    return -1;
 }
 
-void dns_ack6(void)
+void dns_ack6(
+    void)
 {
-  return;
+    return;
 }
 
 #endif
 
 
-char *dns_lookup2(struct mtr_ctl *ctl, ip_t * ip)
+char *dns_lookup2(
+    struct mtr_ctl *ctl,
+    ip_t * ip)
 {
-  struct dns_results *r;
-  char buf[INET6_ADDRSTRLEN + 1];
-  int rv;
-   
-  r = findip (ctl, ip);
-  if (r) {
-     /* we've got a result. */
-     if (r->name) 
-        return r->name;
-     else
-        return strlongip (ctl, ip);
-  } else {
-     r = xmalloc (sizeof (struct dns_results));
-     memcpy (&r->ip, ip, sizeof (r->ip));
-     r->name = NULL;
-     r->next = results;
-     results = r;
-     snprintf (buf, sizeof(buf), "%s\n", strlongip (ctl, ip));
-     rv = write  (todns[1], buf, strlen (buf));
-     if (rv < 0)
-       error (0, errno, "couldn't write to resolver process");
-  }
-  return strlongip (ctl, ip);
+    struct dns_results *r;
+    char buf[INET6_ADDRSTRLEN + 1];
+    int rv;
+
+    r = findip(ctl, ip);
+    if (r) {
+        /* we've got a result. */
+        if (r->name)
+            return r->name;
+        else
+            return strlongip(ctl, ip);
+    } else {
+        r = xmalloc(sizeof(struct dns_results));
+        memcpy(&r->ip, ip, sizeof(r->ip));
+        r->name = NULL;
+        r->next = results;
+        results = r;
+        snprintf(buf, sizeof(buf), "%s\n", strlongip(ctl, ip));
+        rv = write(todns[1], buf, strlen(buf));
+        if (rv < 0)
+            error(0, errno, "couldn't write to resolver process");
+    }
+    return strlongip(ctl, ip);
 }
 
 
-char *dns_lookup(struct mtr_ctl *ctl, ip_t * ip)
+char *dns_lookup(
+    struct mtr_ctl *ctl,
+    ip_t * ip)
 {
-  char *t;
+    char *t;
 
-  if (!ctl->dns || !ctl->use_dns)
-    return NULL;
-  t = dns_lookup2(ctl, ip);
-  return t;
+    if (!ctl->dns || !ctl->use_dns)
+        return NULL;
+    t = dns_lookup2(ctl, ip);
+    return t;
 }
 
 /* XXX check if necessary/exported. */
 
-/* Resolve an IP address to a hostname. */ 
-struct hostent *addr2host( const char *addr, int family ) {
-  int len = 0;
-  switch ( family ) {
-  case AF_INET:
-    len = sizeof( struct in_addr );
-    break;
+/* Resolve an IP address to a hostname. */
+struct hostent *addr2host(
+    const char *addr,
+    int family)
+{
+    int len = 0;
+    switch (family) {
+    case AF_INET:
+        len = sizeof(struct in_addr);
+        break;
 #ifdef ENABLE_IPV6
-  case AF_INET6:
-    len = sizeof( struct in6_addr );
-    break;
+    case AF_INET6:
+        len = sizeof(struct in6_addr);
+        break;
 #endif
-  }
-  return gethostbyaddr( addr, len, family );
+    }
+    return gethostbyaddr(addr, len, family);
 }
-
-
-
index f141fb427262246933f04dde723c37ee3934b704..f38c84688cba6eda790e77d968c1933ba5827dd6 100644 (file)
--- a/ui/dns.h
+++ b/ui/dns.h
 
 /*  Prototypes for dns.c  */
 
-extern void dns_open(struct mtr_ctl *ctl);
-extern int dns_waitfd(void);
-extern void dns_ack(struct mtr_ctl *ctl);
+extern void dns_open(
+    struct mtr_ctl *ctl);
+extern int dns_waitfd(
+    void);
+extern void dns_ack(
+    struct mtr_ctl *ctl);
 #ifdef ENABLE_IPV6
-extern int dns_waitfd6(void);
-extern void dns_ack6(void);
+extern int dns_waitfd6(
+    void);
+extern void dns_ack6(
+    void);
 #endif
 
-extern char *dns_lookup(struct mtr_ctl *ctl, ip_t * address);
-extern char *dns_lookup2(struct mtr_ctl *ctl, ip_t * address);
-extern struct hostent * dns_forward(const char *name);
-extern char *strlongip(struct mtr_ctl *ctl, ip_t * ip);
-
-extern void addr2ip6arpa( ip_t * ip, char * buf );
-extern struct hostent *addr2host( const char *addr, int type );
+extern char *dns_lookup(
+    struct mtr_ctl *ctl,
+    ip_t * address);
+extern char *dns_lookup2(
+    struct mtr_ctl *ctl,
+    ip_t * address);
+extern struct hostent *dns_forward(
+    const char *name);
+extern char *strlongip(
+    struct mtr_ctl *ctl,
+    ip_t * ip);
+
+extern void addr2ip6arpa(
+    ip_t * ip,
+    char *buf);
+extern struct hostent *addr2host(
+    const char *addr,
+    int type);
index c84ef369173dc8edd65433099e64ecb3b4952693..b05e8695ab7eebb104ae096c02ee043e7dc5b820 100644 (file)
--- a/ui/gtk.c
+++ b/ui/gtk.c
 #include <sys/types.h>
 
 #ifdef HAVE_GTK
-# include <string.h>
-# include <sys/types.h>
-# include <gtk/gtk.h>
-
-# include "mtr.h"
-# include "net.h"
-# include "dns.h"
-# include "asn.h"
-# include "mtr-gtk.h"
-# include "utils.h"
-
-# include "img/mtr_icon.xpm"
+#include <string.h>
+#include <sys/types.h>
+#include <gtk/gtk.h>
+
+#include "mtr.h"
+#include "net.h"
+#include "dns.h"
+#include "asn.h"
+#include "mtr-gtk.h"
+#include "utils.h"
+
+#include "img/mtr_icon.xpm"
 #endif
 
-static gint gtk_ping(gpointer data);
-static gint Copy_activate(GtkWidget *widget, gpointer data);
-static gint NewDestination_activate(GtkWidget *widget, gpointer data);
-static gboolean ReportTreeView_clicked(GtkWidget *Tree, GdkEventButton *event, gpointer data);
-static gchar* getSelectedHost(GtkTreePath *path);
+static gint gtk_ping(
+    gpointer data);
+static gint Copy_activate(
+    GtkWidget * widget,
+    gpointer data);
+static gint NewDestination_activate(
+    GtkWidget * widget,
+    gpointer data);
+static gboolean ReportTreeView_clicked(
+    GtkWidget * Tree,
+    GdkEventButton * event,
+    gpointer data);
+static gchar *getSelectedHost(
+    GtkTreePath * path);
 
 static int ping_timeout_timer;
 static GtkWidget *Pause_Button;
 static GtkWidget *Entry;
 static GtkWidget *main_window;
 
-static void gtk_add_ping_timeout (struct mtr_ctl *ctl)
+static void gtk_add_ping_timeout(
+    struct mtr_ctl *ctl)
 {
-  int dt;
-
-  if(gtk_toggle_button_get_active((GtkToggleButton *)Pause_Button)){
-    return;
-  }
-  dt = calc_deltatime (ctl->WaitTime);
-  gtk_redraw(ctl);
-  ping_timeout_timer = g_timeout_add(dt / 1000, gtk_ping, ctl);
+    int dt;
+
+    if (gtk_toggle_button_get_active((GtkToggleButton *) Pause_Button)) {
+        return;
+    }
+    dt = calc_deltatime(ctl->WaitTime);
+    gtk_redraw(ctl);
+    ping_timeout_timer = g_timeout_add(dt / 1000, gtk_ping, ctl);
 }
 
 
-static void gtk_do_init(int *argc, char ***argv)
+static void gtk_do_init(
+    int *argc,
+    char ***argv)
 {
-  static int done = 0;
+    static int done = 0;
 
-  if(!done) {
-    gtk_init(argc, argv);
+    if (!done) {
+        gtk_init(argc, argv);
 
-    done = 1;
-  }
+        done = 1;
+    }
 }
 
 
-int gtk_detect(ATTRIBUTE_UNUSED int *argc, ATTRIBUTE_UNUSED char ***argv)
+int gtk_detect(
+    ATTRIBUTE_UNUSED int *argc,
+    ATTRIBUTE_UNUSED char ***argv)
 {
-  if(getenv("DISPLAY") != NULL) {
-    /* If we do this here, gtk_init exits on an error. This happens
-       BEFORE the user has had a chance to tell us not to use the 
-       display... */
-    return TRUE;
-  } else {
-    return FALSE;
-  }
+    if (getenv("DISPLAY") != NULL) {
+        /* If we do this here, gtk_init exits on an error. This happens
+           BEFORE the user has had a chance to tell us not to use the 
+           display... */
+        return TRUE;
+    } else {
+        return FALSE;
+    }
 }
 
 
-static gint Window_destroy(ATTRIBUTE_UNUSED GtkWidget *Window,
-                          ATTRIBUTE_UNUSED gpointer data)
+static gint Window_destroy(
+    ATTRIBUTE_UNUSED GtkWidget * Window,
+    ATTRIBUTE_UNUSED gpointer data)
 {
-  gtk_main_quit();
+    gtk_main_quit();
 
-  return FALSE;
+    return FALSE;
 }
 
 
-static gint Restart_clicked(ATTRIBUTE_UNUSED GtkWidget *Button, gpointer data)
+static gint Restart_clicked(
+    ATTRIBUTE_UNUSED GtkWidget * Button,
+    gpointer data)
 {
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
 
-  net_reset(ctl);
-  gtk_redraw(ctl);
+    net_reset(ctl);
+    gtk_redraw(ctl);
 
-  return FALSE;
+    return FALSE;
 }
 
 
-static gint Pause_clicked(ATTRIBUTE_UNUSED GtkWidget *Button, gpointer data)
+static gint Pause_clicked(
+    ATTRIBUTE_UNUSED GtkWidget * Button,
+    gpointer data)
 {
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
 
-  static int paused = 0;
+    static int paused = 0;
 
-  if (paused) {
-    gtk_add_ping_timeout (ctl);
-  } else {
-    g_source_remove (ping_timeout_timer);
-  }
-  paused = ! paused;
-  gtk_redraw(ctl);
+    if (paused) {
+        gtk_add_ping_timeout(ctl);
+    } else {
+        g_source_remove(ping_timeout_timer);
+    }
+    paused = !paused;
+    gtk_redraw(ctl);
 
-  return FALSE;
+    return FALSE;
 }
 
-static gint About_clicked(ATTRIBUTE_UNUSED GtkWidget *Button,
-                         ATTRIBUTE_UNUSED gpointer data)
+static gint About_clicked(
+    ATTRIBUTE_UNUSED GtkWidget * Button,
+    ATTRIBUTE_UNUSED gpointer data)
 {
-  static const gchar *authors[] = {
+    static const gchar *authors[] = {
         "Matt Kimball <matt.kimball@gmail.com>",
         "Roger Wolff <R.E.Wolff@BitWizard.nl>",
         "Bohdan Vlasyuk <bohdan@cec.vstu.vinnica.ua>",
@@ -174,24 +194,24 @@ static gint About_clicked(ATTRIBUTE_UNUSED GtkWidget *Button,
         "Thomas Klausner <wiz@NetBSD.org>",
         NULL
     };
-  
-  gtk_show_about_dialog(GTK_WINDOW(main_window)
-    , "version", PACKAGE_VERSION
-    , "copyright", "Copyright \xc2\xa9 1997,1998  Matt Kimball"
-    , "website", "http://www.bitwizard.nl/mtr/"
-    , "authors", authors
-    , "comments", "The 'traceroute' and 'ping' programs in a single network diagnostic tool."
-    , "license",
-"This program is free software; you can redistribute it and/or modify\n"
-"it under the terms of the GNU General Public License version 2 as\n"
-"published by the Free Software Foundation.\n"
-"\n"
-"This program is distributed in the hope that it will be useful,\n"
-"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-"GNU General Public License for more details."
-  , NULL);
-  return TRUE;
+
+    gtk_show_about_dialog(GTK_WINDOW(main_window)
+                          , "version", PACKAGE_VERSION, "copyright",
+                          "Copyright \xc2\xa9 1997,1998  Matt Kimball",
+                          "website", "http://www.bitwizard.nl/mtr/",
+                          "authors", authors, "comments",
+                          "The 'traceroute' and 'ping' programs in a single network diagnostic tool.",
+                          "license",
+                          "This program is free software; you can redistribute it and/or modify\n"
+                          "it under the terms of the GNU General Public License version 2 as\n"
+                          "published by the Free Software Foundation.\n"
+                          "\n"
+                          "This program is distributed in the hope that it will be useful,\n"
+                          "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+                          "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+                          "GNU General Public License for more details.",
+                          NULL);
+    return TRUE;
 }
 
 /*
@@ -203,92 +223,98 @@ static gint About_clicked(ATTRIBUTE_UNUSED GtkWidget *Button,
  * What's the problem with this? (-> "I don't think so)
  */
 
-static gint WaitTime_changed(ATTRIBUTE_UNUSED GtkAdjustment *Adj,
-                            GtkWidget *data)
+static gint WaitTime_changed(
+    ATTRIBUTE_UNUSED GtkAdjustment * Adj,
+    GtkWidget * data)
 {
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
-  GtkWidget *Button = (GtkWidget *)ctl->gtk_data;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
+    GtkWidget *Button = (GtkWidget *) ctl->gtk_data;
 
-  ctl->WaitTime = gtk_spin_button_get_value(GTK_SPIN_BUTTON(Button));
-  g_source_remove (ping_timeout_timer);
-  gtk_add_ping_timeout (ctl);
-  gtk_redraw(ctl);
+    ctl->WaitTime = gtk_spin_button_get_value(GTK_SPIN_BUTTON(Button));
+    g_source_remove(ping_timeout_timer);
+    gtk_add_ping_timeout(ctl);
+    gtk_redraw(ctl);
 
-  return FALSE;
+    return FALSE;
 }
 
 
-static gint Host_activate(GtkWidget *entry, gpointer data)
+static gint Host_activate(
+    GtkWidget * entry,
+    gpointer data)
 {
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
-  struct hostent * addr;
-
-  addr = dns_forward(gtk_entry_get_text(GTK_ENTRY(entry)));
-  if(addr) {
-    net_reopen(ctl, addr);
-    /* If we are "Paused" at this point it is usually because someone
-       entered a non-existing host. Therefore do the go-ahead... */
-    gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( Pause_Button ) , 0);
-  } else {
-    int pos = strlen(gtk_entry_get_text( GTK_ENTRY(entry)));
-    gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( Pause_Button ) , 1);
-    gtk_editable_insert_text( GTK_EDITABLE(entry), ": not found", -1, &pos);
-  }
-
-  return FALSE;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
+    struct hostent *addr;
+
+    addr = dns_forward(gtk_entry_get_text(GTK_ENTRY(entry)));
+    if (addr) {
+        net_reopen(ctl, addr);
+        /* If we are "Paused" at this point it is usually because someone
+           entered a non-existing host. Therefore do the go-ahead... */
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(Pause_Button), 0);
+    } else {
+        int pos = strlen(gtk_entry_get_text(GTK_ENTRY(entry)));
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(Pause_Button), 1);
+        gtk_editable_insert_text(GTK_EDITABLE(entry), ": not found", -1,
+                                 &pos);
+    }
+
+    return FALSE;
 }
 
 
 
-static void Toolbar_fill(struct mtr_ctl *ctl, GtkWidget *Toolbar)
+static void Toolbar_fill(
+    struct mtr_ctl *ctl,
+    GtkWidget * Toolbar)
 {
-  GtkWidget *Button;
-  GtkWidget *Label;
-  GtkAdjustment *Adjustment;
-
-  Button = gtk_button_new_from_stock(GTK_STOCK_QUIT);
-  gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
-  g_signal_connect(GTK_OBJECT(Button), "clicked",
-                    GTK_SIGNAL_FUNC(Window_destroy), NULL);
-
-  Button = gtk_button_new_from_stock(GTK_STOCK_ABOUT);
-  gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
-  g_signal_connect(GTK_OBJECT(Button), "clicked",
-                    GTK_SIGNAL_FUNC(About_clicked), NULL);
-
-  Button = gtk_button_new_with_mnemonic("_Restart");
-  gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
-  g_signal_connect(GTK_OBJECT(Button), "clicked",
-                    GTK_SIGNAL_FUNC(Restart_clicked), ctl);
-
-  Pause_Button = gtk_toggle_button_new_with_mnemonic("_Pause");
-  gtk_box_pack_end(GTK_BOX(Toolbar), Pause_Button, FALSE, FALSE, 0);
-  g_signal_connect(GTK_OBJECT(Pause_Button), "clicked",
-                    GTK_SIGNAL_FUNC(Pause_clicked), ctl);
-
-  /* allow root only to set zero delay */
-  Adjustment = (GtkAdjustment *)gtk_adjustment_new(ctl->WaitTime,
-                                                  getuid()==0 ? 0.01:1.00,
-                                                 999.99,
-                                                  1.0, 10.0,
-                                                  0.0);
-  Button = gtk_spin_button_new(Adjustment, 0.5, 2);
-  gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(Button), TRUE);
-  gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
-  ctl->gtk_data = Button;
-  g_signal_connect(GTK_OBJECT(Adjustment), "value_changed",
-                    GTK_SIGNAL_FUNC(WaitTime_changed), ctl);
-  Label = gtk_label_new_with_mnemonic("_Hostname:");
-  gtk_box_pack_start(GTK_BOX(Toolbar), Label, FALSE, FALSE, 0);
-
-  Entry = gtk_entry_new();
-  gtk_entry_set_text(GTK_ENTRY(Entry), ctl->Hostname);
-  g_signal_connect(GTK_OBJECT(Entry), "activate",
-                    GTK_SIGNAL_FUNC(Host_activate), ctl);
-  gtk_box_pack_start(GTK_BOX(Toolbar), Entry, TRUE, TRUE, 0);
-  
-  gtk_label_set_mnemonic_widget(GTK_LABEL(Label), Entry);
+    GtkWidget *Button;
+    GtkWidget *Label;
+    GtkAdjustment *Adjustment;
+
+    Button = gtk_button_new_from_stock(GTK_STOCK_QUIT);
+    gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
+    g_signal_connect(GTK_OBJECT(Button), "clicked",
+                     GTK_SIGNAL_FUNC(Window_destroy), NULL);
+
+    Button = gtk_button_new_from_stock(GTK_STOCK_ABOUT);
+    gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
+    g_signal_connect(GTK_OBJECT(Button), "clicked",
+                     GTK_SIGNAL_FUNC(About_clicked), NULL);
+
+    Button = gtk_button_new_with_mnemonic("_Restart");
+    gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
+    g_signal_connect(GTK_OBJECT(Button), "clicked",
+                     GTK_SIGNAL_FUNC(Restart_clicked), ctl);
+
+    Pause_Button = gtk_toggle_button_new_with_mnemonic("_Pause");
+    gtk_box_pack_end(GTK_BOX(Toolbar), Pause_Button, FALSE, FALSE, 0);
+    g_signal_connect(GTK_OBJECT(Pause_Button), "clicked",
+                     GTK_SIGNAL_FUNC(Pause_clicked), ctl);
+
+    /* allow root only to set zero delay */
+    Adjustment = (GtkAdjustment *) gtk_adjustment_new(ctl->WaitTime,
+                                                      getuid() ==
+                                                      0 ? 0.01 : 1.00,
+                                                      999.99, 1.0, 10.0,
+                                                      0.0);
+    Button = gtk_spin_button_new(Adjustment, 0.5, 2);
+    gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(Button), TRUE);
+    gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
+    ctl->gtk_data = Button;
+    g_signal_connect(GTK_OBJECT(Adjustment), "value_changed",
+                     GTK_SIGNAL_FUNC(WaitTime_changed), ctl);
+
+    Label = gtk_label_new_with_mnemonic("_Hostname:");
+    gtk_box_pack_start(GTK_BOX(Toolbar), Label, FALSE, FALSE, 0);
+
+    Entry = gtk_entry_new();
+    gtk_entry_set_text(GTK_ENTRY(Entry), ctl->Hostname);
+    g_signal_connect(GTK_OBJECT(Entry), "activate",
+                     GTK_SIGNAL_FUNC(Host_activate), ctl);
+    gtk_box_pack_start(GTK_BOX(Toolbar), Entry, TRUE, TRUE, 0);
+
+    gtk_label_set_mnemonic_widget(GTK_LABEL(Label), Entry);
 }
 
 static GtkWidget *ReportTreeView;
@@ -296,19 +322,19 @@ static GtkListStore *ReportStore;
 
 enum {
 #ifdef HAVE_IPINFO
-  COL_ASN,
+    COL_ASN,
 #endif
-  COL_HOSTNAME,
-  COL_LOSS,
-  COL_RCV,
-  COL_SNT,
-  COL_LAST,
-  COL_BEST,
-  COL_AVG,
-  COL_WORST,
-  COL_STDEV,
-  COL_COLOR,
-  N_COLS
+    COL_HOSTNAME,
+    COL_LOSS,
+    COL_RCV,
+    COL_SNT,
+    COL_LAST,
+    COL_BEST,
+    COL_AVG,
+    COL_WORST,
+    COL_STDEV,
+    COL_COLOR,
+    N_COLS
 };
 
 /* Trick to cast a pointer to integer.  We are mis-using a pointer as a
@@ -318,441 +344,478 @@ enum {
    microseconds earlier, so it is ok.  Nothing to worry about.  */
 #define POINTER_TO_INT(p) ((int)(long)(p))
 
-static void  float_formatter(GtkTreeViewColumn *tree_column ATTRIBUTE_UNUSED,
-  GtkCellRenderer   *cell, 
-  GtkTreeModel      *tree_model,
-  GtkTreeIter       *iter, 
-  gpointer           data)
+static void float_formatter(
+    GtkTreeViewColumn * tree_column ATTRIBUTE_UNUSED,
+    GtkCellRenderer * cell,
+    GtkTreeModel * tree_model,
+    GtkTreeIter * iter,
+    gpointer data)
 {
-  gfloat f;
-  gchar text[64];
-  gtk_tree_model_get(tree_model, iter, POINTER_TO_INT(data), &f, -1);
-  sprintf(text, "%.2f", f);
-  g_object_set(cell, "text", text, NULL);
+    gfloat f;
+    gchar text[64];
+    gtk_tree_model_get(tree_model, iter, POINTER_TO_INT(data), &f, -1);
+    sprintf(text, "%.2f", f);
+    g_object_set(cell, "text", text, NULL);
 }
 
-static void  percent_formatter(GtkTreeViewColumn *tree_column ATTRIBUTE_UNUSED,
-  GtkCellRenderer   *cell, 
-  GtkTreeModel      *tree_model,
-  GtkTreeIter       *iter, 
-  gpointer           data)
+static void percent_formatter(
+    GtkTreeViewColumn * tree_column ATTRIBUTE_UNUSED,
+    GtkCellRenderer * cell,
+    GtkTreeModel * tree_model,
+    GtkTreeIter * iter,
+    gpointer data)
 {
-  gfloat f;
-  gchar text[64];
-  gtk_tree_model_get(tree_model, iter, POINTER_TO_INT(data), &f, -1);
-  sprintf(text, "%.1f%%", f);
-  g_object_set(cell, "text", text, NULL);
+    gfloat f;
+    gchar text[64];
+    gtk_tree_model_get(tree_model, iter, POINTER_TO_INT(data), &f, -1);
+    sprintf(text, "%.1f%%", f);
+    g_object_set(cell, "text", text, NULL);
 }
 
-static void TreeViewCreate(struct mtr_ctl *ctl)
+static void TreeViewCreate(
+    struct mtr_ctl *ctl)
 {
-  GtkCellRenderer *renderer;
-  GtkTreeViewColumn *column;
+    GtkCellRenderer *renderer;
+    GtkTreeViewColumn *column;
 
-  ReportStore = gtk_list_store_new(N_COLS,
+    ReportStore = gtk_list_store_new(N_COLS,
 #ifdef HAVE_IPINFO
-    G_TYPE_STRING,
+                                     G_TYPE_STRING,
 #endif
-    G_TYPE_STRING,
-    G_TYPE_FLOAT,
-    G_TYPE_INT,
-    G_TYPE_INT,
-    G_TYPE_INT,
-    G_TYPE_INT,
-    G_TYPE_INT,
-    G_TYPE_INT,
-    G_TYPE_FLOAT,
-    G_TYPE_STRING
-    );
-    
-  ReportTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ReportStore));
-  
-  g_signal_connect(GTK_OBJECT(ReportTreeView), "button_press_event", 
-                   G_CALLBACK(ReportTreeView_clicked), ctl);
+                                     G_TYPE_STRING,
+                                     G_TYPE_FLOAT,
+                                     G_TYPE_INT,
+                                     G_TYPE_INT,
+                                     G_TYPE_INT,
+                                     G_TYPE_INT,
+                                     G_TYPE_INT,
+                                     G_TYPE_INT,
+                                     G_TYPE_FLOAT, G_TYPE_STRING);
+
+    ReportTreeView =
+        gtk_tree_view_new_with_model(GTK_TREE_MODEL(ReportStore));
+
+    g_signal_connect(GTK_OBJECT(ReportTreeView), "button_press_event",
+                     G_CALLBACK(ReportTreeView_clicked), ctl);
 
 #ifdef HAVE_IPINFO
-  if (is_printii(ctl)) {
-    renderer = gtk_cell_renderer_text_new ();
-    column = gtk_tree_view_column_new_with_attributes ("ASN",
-      renderer,
-      "text", COL_ASN,
-      "foreground", COL_COLOR,
-      NULL);
-    gtk_tree_view_column_set_resizable(column, TRUE);
-    gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
-  }
+    if (is_printii(ctl)) {
+        renderer = gtk_cell_renderer_text_new();
+        column = gtk_tree_view_column_new_with_attributes("ASN",
+                                                          renderer,
+                                                          "text", COL_ASN,
+                                                          "foreground",
+                                                          COL_COLOR, NULL);
+        gtk_tree_view_column_set_resizable(column, TRUE);
+        gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
+    }
 #endif
 
-  renderer = gtk_cell_renderer_text_new ();
-  column = gtk_tree_view_column_new_with_attributes ("Hostname",
-    renderer,
-    "text", COL_HOSTNAME,
-    "foreground", COL_COLOR,
-    NULL);
-  gtk_tree_view_column_set_expand(column, TRUE);
-  gtk_tree_view_column_set_resizable(column, TRUE);
-  gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
-
-  renderer = gtk_cell_renderer_text_new ();
-  g_object_set (G_OBJECT(renderer), "xalign", 1.0, NULL);
-  column = gtk_tree_view_column_new_with_attributes ("Loss",
-    renderer,
-    "text", COL_LOSS,
-    "foreground", COL_COLOR,
-    NULL);
-  gtk_tree_view_column_set_resizable(column, TRUE);
-  gtk_tree_view_column_set_cell_data_func(column, renderer, percent_formatter, (void*)COL_LOSS, NULL);
-  gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
-
-  renderer = gtk_cell_renderer_text_new ();
-  g_object_set (G_OBJECT(renderer), "xalign", 1.0, NULL);
-  column = gtk_tree_view_column_new_with_attributes ("Snt",
-    renderer,
-    "text", COL_SNT,
-    "foreground", COL_COLOR,
-    NULL);
-  gtk_tree_view_column_set_resizable(column, TRUE);
-  gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
-
-  renderer = gtk_cell_renderer_text_new ();
-  g_object_set (G_OBJECT(renderer), "xalign", 1.0, NULL);
-  column = gtk_tree_view_column_new_with_attributes ("Last",
-    renderer,
-    "text", COL_LAST,
-    "foreground", COL_COLOR,
-    NULL);
-  gtk_tree_view_column_set_resizable(column, TRUE);
-  gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
-
-  renderer = gtk_cell_renderer_text_new ();
-  g_object_set (G_OBJECT(renderer), "xalign", 1.0, NULL);
-  column = gtk_tree_view_column_new_with_attributes ("Avg",
-    renderer,
-    "text", COL_AVG,
-    "foreground", COL_COLOR,
-    NULL);
-  gtk_tree_view_column_set_resizable(column, TRUE);
-  gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
-  
-  renderer = gtk_cell_renderer_text_new ();
-  g_object_set (G_OBJECT(renderer), "xalign", 1.0, NULL);
-  column = gtk_tree_view_column_new_with_attributes ("Best",
-    renderer,
-    "text", COL_BEST,
-    "foreground", COL_COLOR,
-    NULL);
-  gtk_tree_view_column_set_resizable(column, TRUE);
-  gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
-
-    renderer = gtk_cell_renderer_text_new ();
-  g_object_set (G_OBJECT(renderer), "xalign", 1.0, NULL);
-  column = gtk_tree_view_column_new_with_attributes ("Worst",
-    renderer,
-    "text", COL_WORST,
-    "foreground", COL_COLOR,
-    NULL);
-  gtk_tree_view_column_set_resizable(column, TRUE);
-  gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
-
-  renderer = gtk_cell_renderer_text_new ();
-  g_object_set (G_OBJECT(renderer), "xalign", 1.0, NULL);
-  column = gtk_tree_view_column_new_with_attributes ("StDev",
-    renderer,
-    "text", COL_STDEV,
-    "foreground", COL_COLOR,
-    NULL);
-  gtk_tree_view_column_set_resizable(column, TRUE);
-  gtk_tree_view_column_set_cell_data_func(column, renderer, float_formatter, (void*)COL_STDEV, NULL);
-  gtk_tree_view_append_column (GTK_TREE_VIEW(ReportTreeView), column);
+    renderer = gtk_cell_renderer_text_new();
+    column = gtk_tree_view_column_new_with_attributes("Hostname",
+                                                      renderer,
+                                                      "text", COL_HOSTNAME,
+                                                      "foreground",
+                                                      COL_COLOR, NULL);
+    gtk_tree_view_column_set_expand(column, TRUE);
+    gtk_tree_view_column_set_resizable(column, TRUE);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
+    column = gtk_tree_view_column_new_with_attributes("Loss",
+                                                      renderer,
+                                                      "text", COL_LOSS,
+                                                      "foreground",
+                                                      COL_COLOR, NULL);
+    gtk_tree_view_column_set_resizable(column, TRUE);
+    gtk_tree_view_column_set_cell_data_func(column, renderer,
+                                            percent_formatter,
+                                            (void *) COL_LOSS, NULL);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
+    column = gtk_tree_view_column_new_with_attributes("Snt",
+                                                      renderer,
+                                                      "text", COL_SNT,
+                                                      "foreground",
+                                                      COL_COLOR, NULL);
+    gtk_tree_view_column_set_resizable(column, TRUE);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
+    column = gtk_tree_view_column_new_with_attributes("Last",
+                                                      renderer,
+                                                      "text", COL_LAST,
+                                                      "foreground",
+                                                      COL_COLOR, NULL);
+    gtk_tree_view_column_set_resizable(column, TRUE);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
+    column = gtk_tree_view_column_new_with_attributes("Avg",
+                                                      renderer,
+                                                      "text", COL_AVG,
+                                                      "foreground",
+                                                      COL_COLOR, NULL);
+    gtk_tree_view_column_set_resizable(column, TRUE);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
+    column = gtk_tree_view_column_new_with_attributes("Best",
+                                                      renderer,
+                                                      "text", COL_BEST,
+                                                      "foreground",
+                                                      COL_COLOR, NULL);
+    gtk_tree_view_column_set_resizable(column, TRUE);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
+    column = gtk_tree_view_column_new_with_attributes("Worst",
+                                                      renderer,
+                                                      "text", COL_WORST,
+                                                      "foreground",
+                                                      COL_COLOR, NULL);
+    gtk_tree_view_column_set_resizable(column, TRUE);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
+    column = gtk_tree_view_column_new_with_attributes("StDev",
+                                                      renderer,
+                                                      "text", COL_STDEV,
+                                                      "foreground",
+                                                      COL_COLOR, NULL);
+    gtk_tree_view_column_set_resizable(column, TRUE);
+    gtk_tree_view_column_set_cell_data_func(column, renderer,
+                                            float_formatter,
+                                            (void *) COL_STDEV, NULL);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(ReportTreeView), column);
 
 }
 
-static void update_tree_row(struct mtr_ctl *ctl, int row, GtkTreeIter *iter)
+static void update_tree_row(
+    struct mtr_ctl *ctl,
+    int row,
+    GtkTreeIter * iter)
 {
-  ip_t *addr;
-  char str[256]="???", *name=str;
-
-  addr = net_addr(row);
-  if (addrcmp( (void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
-    if ((name = dns_lookup(ctl, addr))) {
-      if (ctl->show_ips) {
-        snprintf(str, sizeof(str), "%s (%s)", name, strlongip(ctl, addr));
-        name = str;
-      }
-    } else name = strlongip(ctl, addr);
-  }
-
-  gtk_list_store_set(ReportStore, iter,
-    COL_HOSTNAME, name,
-    COL_LOSS, (float)(net_loss(row)/1000.0),
-
-    COL_RCV, net_returned(row),
-    COL_SNT, net_xmit(row),
-
-    COL_LAST, net_last(row)/1000,
-    COL_BEST, net_best(row)/1000,
-    COL_AVG, net_avg(row)/1000,
-    COL_WORST, net_worst(row)/1000,
-    COL_STDEV, (float)(net_stdev(row)/1000.0),
-    
-    COL_COLOR, net_up(row) ? NULL : "red",
-
-    -1);
+    ip_t *addr;
+    char str[256] = "???", *name = str;
+
+    addr = net_addr(row);
+    if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
+        if ((name = dns_lookup(ctl, addr))) {
+            if (ctl->show_ips) {
+                snprintf(str, sizeof(str), "%s (%s)", name,
+                         strlongip(ctl, addr));
+                name = str;
+            }
+        } else
+            name = strlongip(ctl, addr);
+    }
+
+    gtk_list_store_set(ReportStore, iter,
+                       COL_HOSTNAME, name,
+                       COL_LOSS, (float) (net_loss(row) / 1000.0),
+                       COL_RCV, net_returned(row),
+                       COL_SNT, net_xmit(row),
+                       COL_LAST, net_last(row) / 1000,
+                       COL_BEST, net_best(row) / 1000,
+                       COL_AVG, net_avg(row) / 1000,
+                       COL_WORST, net_worst(row) / 1000,
+                       COL_STDEV, (float) (net_stdev(row) / 1000.0),
+                       COL_COLOR, net_up(row) ? NULL : "red", -1);
 #ifdef HAVE_IPINFO
-  if (is_printii(ctl))
-    gtk_list_store_set(ReportStore, iter, COL_ASN, fmt_ipinfo(ctl, addr), -1);
+    if (is_printii(ctl))
+        gtk_list_store_set(ReportStore, iter, COL_ASN,
+                           fmt_ipinfo(ctl, addr), -1);
 #endif
 }
 
-void gtk_redraw(struct mtr_ctl *ctl)
+void gtk_redraw(
+    struct mtr_ctl *ctl)
 {
-  int max = net_max(ctl);
-  
-  GtkTreeIter iter;
-  int row = net_min(ctl);
-  gboolean valid;
-
-  valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ReportStore), &iter);
-
-  while(valid) {
-    if(row < max) {
-      update_tree_row(ctl, row++, &iter);
-      valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(ReportStore), &iter);
-    } else {
-      valid = gtk_list_store_remove(ReportStore, &iter);
+    int max = net_max(ctl);
+
+    GtkTreeIter iter;
+    int row = net_min(ctl);
+    gboolean valid;
+
+    valid =
+        gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ReportStore), &iter);
+
+    while (valid) {
+        if (row < max) {
+            update_tree_row(ctl, row++, &iter);
+            valid =
+                gtk_tree_model_iter_next(GTK_TREE_MODEL(ReportStore),
+                                         &iter);
+        } else {
+            valid = gtk_list_store_remove(ReportStore, &iter);
+        }
+    }
+    while (row < max) {
+        gtk_list_store_append(ReportStore, &iter);
+        update_tree_row(ctl, row++, &iter);
     }
-  }
-  while(row < max) {
-    gtk_list_store_append(ReportStore, &iter);
-    update_tree_row(ctl, row++, &iter);
-  }
 }
 
 
-static void Window_fill(struct mtr_ctl *ctl, GtkWidget *Window)
+static void Window_fill(
+    struct mtr_ctl *ctl,
+    GtkWidget * Window)
 {
-  GtkWidget *VBox;
-  GtkWidget *Toolbar;
-  GtkWidget *scroll;
-
-  gtk_window_set_title(GTK_WINDOW(Window), "My traceroute");
-  gtk_window_set_default_size(GTK_WINDOW(Window), 650, 400); 
-  gtk_container_set_border_width(GTK_CONTAINER(Window), 10);
-  VBox = gtk_vbox_new(FALSE, 10);
-
-  Toolbar = gtk_hbox_new(FALSE, 10);
-  Toolbar_fill(ctl, Toolbar);
-  gtk_box_pack_start(GTK_BOX(VBox), Toolbar, FALSE, FALSE, 0);
-  
-  TreeViewCreate(ctl);
-  scroll = gtk_scrolled_window_new(NULL, NULL);
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN);
-  gtk_container_add(GTK_CONTAINER(scroll), ReportTreeView);
-  gtk_box_pack_start(GTK_BOX(VBox), scroll, TRUE, TRUE, 0);
-
-  gtk_container_add(GTK_CONTAINER(Window), VBox);
+    GtkWidget *VBox;
+    GtkWidget *Toolbar;
+    GtkWidget *scroll;
+
+    gtk_window_set_title(GTK_WINDOW(Window), "My traceroute");
+    gtk_window_set_default_size(GTK_WINDOW(Window), 650, 400);
+    gtk_container_set_border_width(GTK_CONTAINER(Window), 10);
+    VBox = gtk_vbox_new(FALSE, 10);
+
+    Toolbar = gtk_hbox_new(FALSE, 10);
+    Toolbar_fill(ctl, Toolbar);
+    gtk_box_pack_start(GTK_BOX(VBox), Toolbar, FALSE, FALSE, 0);
+
+    TreeViewCreate(ctl);
+    scroll = gtk_scrolled_window_new(NULL, NULL);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
+                                   GTK_POLICY_AUTOMATIC,
+                                   GTK_POLICY_AUTOMATIC);
+    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll),
+                                        GTK_SHADOW_IN);
+    gtk_container_add(GTK_CONTAINER(scroll), ReportTreeView);
+    gtk_box_pack_start(GTK_BOX(VBox), scroll, TRUE, TRUE, 0);
+
+    gtk_container_add(GTK_CONTAINER(Window), VBox);
 }
 
 
-void gtk_open(struct mtr_ctl *ctl)
+void gtk_open(
+    struct mtr_ctl *ctl)
 {
-  GdkPixbuf *icon;
-  int argc = 1;
-  char *args[2];
-  char **argv;
+    GdkPixbuf *icon;
+    int argc = 1;
+    char *args[2];
+    char **argv;
 
-  argv = args;
-  argv[0] = xstrdup("");
-  argv[1] = NULL;
-  gtk_do_init(&argc, &argv);
-  free(argv[0]);
+    argv = args;
+    argv[0] = xstrdup("");
+    argv[1] = NULL;
+    gtk_do_init(&argc, &argv);
+    free(argv[0]);
 
-  icon = gdk_pixbuf_new_from_xpm_data((const char**)mtr_icon);
-  gtk_window_set_default_icon(icon);
+    icon = gdk_pixbuf_new_from_xpm_data((const char **) mtr_icon);
+    gtk_window_set_default_icon(icon);
 
-  main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-  
-  g_set_application_name("My traceroute");
+    main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
-  Window_fill(ctl, main_window);
+    g_set_application_name("My traceroute");
 
-  g_signal_connect(GTK_OBJECT(main_window), "delete_event",
+    Window_fill(ctl, main_window);
+
+    g_signal_connect(GTK_OBJECT(main_window), "delete_event",
+                     GTK_SIGNAL_FUNC(Window_destroy), NULL);
+    g_signal_connect(GTK_OBJECT(main_window), "destroy",
                      GTK_SIGNAL_FUNC(Window_destroy), NULL);
-  g_signal_connect(GTK_OBJECT(main_window), "destroy",
-                    GTK_SIGNAL_FUNC(Window_destroy), NULL);
 
-  gtk_widget_show_all(main_window);
+    gtk_widget_show_all(main_window);
 }
 
 
-void gtk_close(void)
+void gtk_close(
+    void)
 {
 }
 
 
-int gtk_keyaction(void)
+int gtk_keyaction(
+    void)
 {
-  return 0;
+    return 0;
 }
 
 
-static gint gtk_ping(gpointer data)
+static gint gtk_ping(
+    gpointer data)
 {
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
-
-  gtk_redraw(ctl);
-  net_send_batch(ctl);
-  net_harvest_fds(ctl);
-  g_source_remove (ping_timeout_timer);
-  gtk_add_ping_timeout (ctl);
-  return TRUE;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
+
+    gtk_redraw(ctl);
+    net_send_batch(ctl);
+    net_harvest_fds(ctl);
+    g_source_remove(ping_timeout_timer);
+    gtk_add_ping_timeout(ctl);
+    return TRUE;
 }
 
 
-static gboolean gtk_net_data(ATTRIBUTE_UNUSED GIOChannel *channel,
-                            ATTRIBUTE_UNUSED GIOCondition cond, gpointer data)
+static gboolean gtk_net_data(
+    ATTRIBUTE_UNUSED GIOChannel * channel,
+    ATTRIBUTE_UNUSED GIOCondition cond,
+    gpointer data)
 {
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
 
-  net_process_return(ctl);
-  return TRUE;
+    net_process_return(ctl);
+    return TRUE;
 }
 
 
-static gboolean gtk_dns_data(ATTRIBUTE_UNUSED GIOChannel *channel,
-                            ATTRIBUTE_UNUSED GIOCondition cond, gpointer data)
+static gboolean gtk_dns_data(
+    ATTRIBUTE_UNUSED GIOChannel * channel,
+    ATTRIBUTE_UNUSED GIOCondition cond,
+    gpointer data)
 {
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
 
-  dns_ack(ctl);
-  gtk_redraw(ctl);
-  return TRUE;
+    dns_ack(ctl);
+    gtk_redraw(ctl);
+    return TRUE;
 }
+
 #ifdef ENABLE_IPV6
-static gboolean gtk_dns_data6(ATTRIBUTE_UNUSED GIOChannel *channel,
-                             ATTRIBUTE_UNUSED GIOCondition cond, gpointer data)
+static gboolean gtk_dns_data6(
+    ATTRIBUTE_UNUSED GIOChannel * channel,
+    ATTRIBUTE_UNUSED GIOCondition cond,
+    gpointer data)
 {
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
 
-  dns_ack6();
-  gtk_redraw(ctl);
-  return TRUE;
+    dns_ack6();
+    gtk_redraw(ctl);
+    return TRUE;
 }
 #endif
 
 
-void gtk_loop(struct mtr_ctl *ctl)
+void gtk_loop(
+    struct mtr_ctl *ctl)
 {
-  GIOChannel *net_iochannel, *dns_iochannel;
+    GIOChannel *net_iochannel, *dns_iochannel;
 
-  gtk_add_ping_timeout (ctl);
-  
-  net_iochannel = g_io_channel_unix_new(net_waitfd());
-  g_io_add_watch(net_iochannel, G_IO_IN, gtk_net_data, ctl);
+    gtk_add_ping_timeout(ctl);
+
+    net_iochannel = g_io_channel_unix_new(net_waitfd());
+    g_io_add_watch(net_iochannel, G_IO_IN, gtk_net_data, ctl);
 #ifdef ENABLE_IPV6
-  if (dns_waitfd6() > 0) {
-    dns_iochannel = g_io_channel_unix_new(dns_waitfd6());
-    g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data6, ctl);
-  }
+    if (dns_waitfd6() > 0) {
+        dns_iochannel = g_io_channel_unix_new(dns_waitfd6());
+        g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data6, ctl);
+    }
 #endif
-  dns_iochannel = g_io_channel_unix_new(dns_waitfd());
-  g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data, ctl);
+    dns_iochannel = g_io_channel_unix_new(dns_waitfd());
+    g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data, ctl);
 
-  gtk_main();
+    gtk_main();
 }
 
-static gboolean NewDestination_activate(GtkWidget *widget ATTRIBUTE_UNUSED,
-                                       gpointer data)
+static gboolean NewDestination_activate(
+    GtkWidget * widget ATTRIBUTE_UNUSED,
+    gpointer data)
 {
-  gchar *hostname;
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
-  GtkTreePath *path = (GtkTreePath *)ctl->gtk_data;
-       
-  hostname = getSelectedHost(path);
-  if (hostname) {
-    ctl->gtk_data = hostname;
-    gtk_entry_set_text (GTK_ENTRY(Entry), hostname);
-    Host_activate(Entry, ctl);
-    g_free(hostname);
-  }
-  return TRUE;
+    gchar *hostname;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
+    GtkTreePath *path = (GtkTreePath *) ctl->gtk_data;
+
+    hostname = getSelectedHost(path);
+    if (hostname) {
+        ctl->gtk_data = hostname;
+        gtk_entry_set_text(GTK_ENTRY(Entry), hostname);
+        Host_activate(Entry, ctl);
+        g_free(hostname);
+    }
+    return TRUE;
 }
 
 
-static gboolean Copy_activate(GtkWidget *widget ATTRIBUTE_UNUSED, gpointer data)
+static gboolean Copy_activate(
+    GtkWidget * widget ATTRIBUTE_UNUSED,
+    gpointer data)
 {
-  gchar *hostname;
-  GtkTreePath *path = (GtkTreePath*)data;
-       
-  hostname = getSelectedHost(path);
-  if (hostname != NULL) {
-    GtkClipboard *clipboard;
+    gchar *hostname;
+    GtkTreePath *path = (GtkTreePath *) data;
 
-    clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
-    gtk_clipboard_set_text(clipboard, hostname, -1);
+    hostname = getSelectedHost(path);
+    if (hostname != NULL) {
+        GtkClipboard *clipboard;
 
-    clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
-    gtk_clipboard_set_text(clipboard, hostname, -1);
+        clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
+        gtk_clipboard_set_text(clipboard, hostname, -1);
 
-    g_free(hostname);
-  }
+        clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+        gtk_clipboard_set_text(clipboard, hostname, -1);
 
-  return TRUE;
+        g_free(hostname);
+    }
+
+    return TRUE;
 }
 
-static gchar *getSelectedHost(GtkTreePath *path)
+static gchar *getSelectedHost(
+    GtkTreePath * path)
 {
-  GtkTreeIter iter;
-  gchar *name = NULL;
-
-  if (gtk_tree_model_get_iter(GTK_TREE_MODEL(ReportStore), &iter, path)) {
-    gtk_tree_model_get (GTK_TREE_MODEL(ReportStore), &iter, COL_HOSTNAME, &name, -1);
-  }
-  gtk_tree_path_free(path);
-  return name;
+    GtkTreeIter iter;
+    gchar *name = NULL;
+
+    if (gtk_tree_model_get_iter(GTK_TREE_MODEL(ReportStore), &iter, path)) {
+        gtk_tree_model_get(GTK_TREE_MODEL(ReportStore), &iter,
+                           COL_HOSTNAME, &name, -1);
+    }
+    gtk_tree_path_free(path);
+    return name;
 }
 
 
-static gboolean ReportTreeView_clicked(GtkWidget *Tree ATTRIBUTE_UNUSED,
-                                      GdkEventButton *event, gpointer data)
+static gboolean ReportTreeView_clicked(
+    GtkWidget * Tree ATTRIBUTE_UNUSED,
+    GdkEventButton * event,
+    gpointer data)
 {
-  GtkWidget* popup_menu; 
-  GtkWidget* copy_item; 
-  GtkWidget* newdestination_item;
-  GtkTreePath *path;
-  struct mtr_ctl *ctl = (struct mtr_ctl *)data;
+    GtkWidget *popup_menu;
+    GtkWidget *copy_item;
+    GtkWidget *newdestination_item;
+    GtkTreePath *path;
+    struct mtr_ctl *ctl = (struct mtr_ctl *) data;
 
-  if (event->type != GDK_BUTTON_PRESS  || event->button != 3)
-    return FALSE;
+    if (event->type != GDK_BUTTON_PRESS || event->button != 3)
+        return FALSE;
 
-  if(!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ReportTreeView),
-      event->x, event->y, &path, NULL, NULL, NULL))
-    return FALSE;
-  
-  gtk_tree_view_set_cursor(GTK_TREE_VIEW(ReportTreeView), path, NULL, FALSE);
+    if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ReportTreeView),
+                                       event->x, event->y, &path, NULL,
+                                       NULL, NULL))
+        return FALSE;
+
+    gtk_tree_view_set_cursor(GTK_TREE_VIEW(ReportTreeView), path, NULL,
+                             FALSE);
 
-  /* Single right click: prepare and show the popup menu */
-  popup_menu = gtk_menu_new ();
+    /* Single right click: prepare and show the popup menu */
+    popup_menu = gtk_menu_new();
 
-  copy_item = gtk_menu_item_new_with_label ("Copy to clipboard");
-  newdestination_item = gtk_menu_item_new_with_label ("Set as new destination"); 
+    copy_item = gtk_menu_item_new_with_label("Copy to clipboard");
+    newdestination_item =
+        gtk_menu_item_new_with_label("Set as new destination");
 
-  gtk_menu_append (GTK_MENU (popup_menu), copy_item); 
-  gtk_menu_append (GTK_MENU (popup_menu), newdestination_item); 
+    gtk_menu_append(GTK_MENU(popup_menu), copy_item);
+    gtk_menu_append(GTK_MENU(popup_menu), newdestination_item);
 
-  g_signal_connect(GTK_OBJECT(copy_item),"activate",
-                   GTK_SIGNAL_FUNC(Copy_activate), path);
+    g_signal_connect(GTK_OBJECT(copy_item), "activate",
+                     GTK_SIGNAL_FUNC(Copy_activate), path);
 
-  ctl->gtk_data = path;
-  g_signal_connect(GTK_OBJECT(newdestination_item),"activate",
-                   GTK_SIGNAL_FUNC(NewDestination_activate), ctl);
-              
-  gtk_widget_show (copy_item); 
-  gtk_widget_show (newdestination_item); 
+    ctl->gtk_data = path;
+    g_signal_connect(GTK_OBJECT(newdestination_item), "activate",
+                     GTK_SIGNAL_FUNC(NewDestination_activate), ctl);
 
-  gtk_menu_popup (GTK_MENU(popup_menu), NULL, NULL, NULL, NULL,
+    gtk_widget_show(copy_item);
+    gtk_widget_show(newdestination_item);
+
+    gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL,
                    0, event->time);
-  return TRUE;
+    return TRUE;
 }
-
index 54edcfffd7ee12524edaa5607b87876a99345c0f..71298cfd0e96bf14c4d60cd53af7ffec56352cfc 100644 (file)
 */
 
 /*  Prototypes for curses.c  */
-extern void mtr_curses_open(struct mtr_ctl *ctl);
-extern void mtr_curses_close(void);
-extern void mtr_curses_redraw(struct mtr_ctl *ctl);
-extern int mtr_curses_keyaction(struct mtr_ctl *ctl);
-extern void mtr_curses_clear(struct mtr_ctl *ctl);
+extern void mtr_curses_open(
+    struct mtr_ctl *ctl);
+extern void mtr_curses_close(
+    void);
+extern void mtr_curses_redraw(
+    struct mtr_ctl *ctl);
+extern int mtr_curses_keyaction(
+    struct mtr_ctl *ctl);
+extern void mtr_curses_clear(
+    struct mtr_ctl *ctl);
index 6713a3ab24dedf23d95705699a6f7d8a5c15fa55..88fa3a18e592ef0117b3248bf9509c204b67829e 100644 (file)
 */
 
 /*  Prototypes for gtk.c  */
-extern int gtk_detect(int *argc, char ***argv);
-extern void gtk_open(struct mtr_ctl *ctl);
-extern void gtk_close(void);
-extern void gtk_redraw(struct mtr_ctl *ctl);
-extern int gtk_keyaction(void);
-extern void gtk_loop(struct mtr_ctl *ctl);
+extern int gtk_detect(
+    int *argc,
+    char ***argv);
+extern void gtk_open(
+    struct mtr_ctl *ctl);
+extern void gtk_close(
+    void);
+extern void gtk_redraw(
+    struct mtr_ctl *ctl);
+extern int gtk_keyaction(
+    void);
+extern void gtk_loop(
+    struct mtr_ctl *ctl);
index da1e32dc084f5b3173a0aaafce3384a64e650143..70ae5c4786ece6ea2d27e0f88fd260d6d9eafb92 100644 (file)
--- a/ui/mtr.c
+++ b/ui/mtr.c
 #include <string.h>
 #include <strings.h>
 #ifdef HAVE_ERROR_H
-# include <error.h>
+#include <error.h>
 #else
-# include "portability/error.h"
+#include "portability/error.h"
 #endif
 #ifdef HAVE_VALUES_H
-# include <values.h>
+#include <values.h>
 #endif
 #ifdef HAVE_SYS_LIMITS_H
-# include <sys/limits.h>
+#include <sys/limits.h>
 #endif
 
 #include <netdb.h>
 #include "utils.h"
 
 #ifdef HAVE_GETOPT
-# include <getopt.h>
+#include <getopt.h>
 #else
-# include "portability/getopt.h"
+#include "portability/getopt.h"
 #endif
 
 #ifdef ENABLE_IPV6
-# define DEFAULT_AF AF_UNSPEC
+#define DEFAULT_AF AF_UNSPEC
 #else
-# define DEFAULT_AF AF_INET
+#define DEFAULT_AF AF_INET
 #endif
 
 
 const struct fields data_fields[MAXFLD] = {
-  /* key, Remark, Header, Format, Width, CallBackFunc */
-  {' ', "<sp>: Space between fields", " ",  " ",        1, &net_drop  },
-  {'L', "L: Loss Ratio",          "Loss%",  " %4.1f%%", 6, &net_loss  },
-  {'D', "D: Dropped Packets",     "Drop",   " %4d",     5, &net_drop  },
-  {'R', "R: Received Packets",    "Rcv",    " %5d",     6, &net_returned},
-  {'S', "S: Sent Packets",        "Snt",    " %5d",     6, &net_xmit  },
-  {'N', "N: Newest RTT(ms)",      "Last",   " %5.1f",   6, &net_last  },
-  {'B', "B: Min/Best RTT(ms)",    "Best",   " %5.1f",   6, &net_best  },
-  {'A', "A: Average RTT(ms)",     "Avg",    " %5.1f",   6, &net_avg   },
-  {'W', "W: Max/Worst RTT(ms)",   "Wrst",   " %5.1f",   6, &net_worst },
-  {'V', "V: Standard Deviation",  "StDev",  " %5.1f",   6, &net_stdev },
-  {'G', "G: Geometric Mean",      "Gmean",  " %5.1f",   6, &net_gmean },
-  {'J', "J: Current Jitter",      "Jttr",   " %4.1f",   5, &net_jitter},
-  {'M', "M: Jitter Mean/Avg.",    "Javg",   " %4.1f",   5, &net_javg  },
-  {'X', "X: Worst Jitter",        "Jmax",   " %4.1f",   5, &net_jworst},
-  {'I', "I: Interarrival Jitter", "Jint",   " %4.1f",   5, &net_jinta },
-  {'\0', NULL, NULL, NULL, 0, NULL}
+    /* key, Remark, Header, Format, Width, CallBackFunc */
+    {' ', "<sp>: Space between fields", " ", " ", 1, &net_drop},
+    {'L', "L: Loss Ratio", "Loss%", " %4.1f%%", 6, &net_loss},
+    {'D', "D: Dropped Packets", "Drop", " %4d", 5, &net_drop},
+    {'R', "R: Received Packets", "Rcv", " %5d", 6, &net_returned},
+    {'S', "S: Sent Packets", "Snt", " %5d", 6, &net_xmit},
+    {'N', "N: Newest RTT(ms)", "Last", " %5.1f", 6, &net_last},
+    {'B', "B: Min/Best RTT(ms)", "Best", " %5.1f", 6, &net_best},
+    {'A', "A: Average RTT(ms)", "Avg", " %5.1f", 6, &net_avg},
+    {'W', "W: Max/Worst RTT(ms)", "Wrst", " %5.1f", 6, &net_worst},
+    {'V', "V: Standard Deviation", "StDev", " %5.1f", 6, &net_stdev},
+    {'G', "G: Geometric Mean", "Gmean", " %5.1f", 6, &net_gmean},
+    {'J', "J: Current Jitter", "Jttr", " %4.1f", 5, &net_jitter},
+    {'M', "M: Jitter Mean/Avg.", "Javg", " %4.1f", 5, &net_javg},
+    {'X', "X: Worst Jitter", "Jmax", " %4.1f", 5, &net_jworst},
+    {'I', "I: Interarrival Jitter", "Jint", " %4.1f", 5, &net_jinta},
+    {'\0', NULL, NULL, NULL, 0, NULL}
 };
 
 typedef struct names {
-  char         *name;
-  struct names *next;
+    char *name;
+    struct names *next;
 } names_t;
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
-  fputs("\nUsage:\n", out);
-  fputs(" mtr [options] hostname\n", out);
-  fputs("\n", out);
-  fputs(" -F, --filename FILE        read hostname(s) from a file\n", out);
-  fputs(" -4                         use IPv4 only\n", out);
+    fputs("\nUsage:\n", out);
+    fputs(" mtr [options] hostname\n", out);
+    fputs("\n", out);
+    fputs(" -F, --filename FILE        read hostname(s) from a file\n",
+          out);
+    fputs(" -4                         use IPv4 only\n", out);
 #ifdef ENABLE_IPV6
-  fputs(" -6                         use IPv6 only\n", out);
+    fputs(" -6                         use IPv6 only\n", out);
 #endif
-  fputs(" -u, --udp                  use UDP instead of ICMP echo\n", out);
-  fputs(" -T, --tcp                  use TCP instead of ICMP echo\n", out);
-  fputs(" -a, --address ADDRESS      bind the outgoing socket to ADDRESS\n", out);
-  fputs(" -f, --first-ttl NUMBER     set what TTL to start\n", out);
-  fputs(" -m, --max-ttl NUMBER       maximum number of hops\n", out);
-  fputs(" -U, --max-unknown NUMBER   maximum unknown host\n", out);
-  fputs(" -P, --port PORT            target port number for TCP, SCTP, or UDP\n", out);
-  fputs(" -L, --localport LOCALPORT  source port number for UDP\n", out);
-  fputs(" -s, --psize PACKETSIZE     set the packet size used for probing\n", out);
-  fputs(" -B, --bitpattern NUMBER    set bit pattern to use in payload\n", out);
-  fputs(" -i, --interval SECONDS     ICMP echo request interval\n", out);
-  fputs(" -G, --gracetime SECONDS    number of seconds to wait for responses\n", out);
-  fputs(" -Q, --tos NUMBER           type of service field in IP header\n", out);
-  fputs(" -e, --mpls                 display information from ICMP extensions\n", out);
-  fputs(" -Z, --timeout SECONDS      seconds to keep probe sockets open\n", out);
+    fputs(" -u, --udp                  use UDP instead of ICMP echo\n",
+          out);
+    fputs(" -T, --tcp                  use TCP instead of ICMP echo\n",
+          out);
+    fputs
+        (" -a, --address ADDRESS      bind the outgoing socket to ADDRESS\n",
+         out);
+    fputs(" -f, --first-ttl NUMBER     set what TTL to start\n", out);
+    fputs(" -m, --max-ttl NUMBER       maximum number of hops\n", out);
+    fputs(" -U, --max-unknown NUMBER   maximum unknown host\n", out);
+    fputs
+        (" -P, --port PORT            target port number for TCP, SCTP, or UDP\n",
+         out);
+    fputs(" -L, --localport LOCALPORT  source port number for UDP\n", out);
+    fputs
+        (" -s, --psize PACKETSIZE     set the packet size used for probing\n",
+         out);
+    fputs
+        (" -B, --bitpattern NUMBER    set bit pattern to use in payload\n",
+         out);
+    fputs(" -i, --interval SECONDS     ICMP echo request interval\n", out);
+    fputs
+        (" -G, --gracetime SECONDS    number of seconds to wait for responses\n",
+         out);
+    fputs
+        (" -Q, --tos NUMBER           type of service field in IP header\n",
+         out);
+    fputs
+        (" -e, --mpls                 display information from ICMP extensions\n",
+         out);
+    fputs
+        (" -Z, --timeout SECONDS      seconds to keep probe sockets open\n",
+         out);
 #ifdef SO_MARK
-  fputs(" -M, --mark MARK            mark each sent packet\n", out);
+    fputs(" -M, --mark MARK            mark each sent packet\n", out);
 #endif
-  fputs(" -r, --report               output using report mode\n", out);
-  fputs(" -w, --report-wide          output wide report\n", out);
-  fputs(" -c, --report-cycles COUNT  set the number of pings sent\n", out);
-  fputs(" -j, --json                 output json\n", out);
-  fputs(" -x, --xml                  output xml\n", out);
-  fputs(" -C, --csv                  output comma separated values\n", out);
-  fputs(" -l, --raw                  output raw format\n", out);
-  fputs(" -p, --split                split output\n", out);
+    fputs(" -r, --report               output using report mode\n", out);
+    fputs(" -w, --report-wide          output wide report\n", out);
+    fputs(" -c, --report-cycles COUNT  set the number of pings sent\n",
+          out);
+    fputs(" -j, --json                 output json\n", out);
+    fputs(" -x, --xml                  output xml\n", out);
+    fputs(" -C, --csv                  output comma separated values\n",
+          out);
+    fputs(" -l, --raw                  output raw format\n", out);
+    fputs(" -p, --split                split output\n", out);
 #ifdef HAVE_CURSES
-  fputs(" -t, --curses               use curses terminal interface\n", out);
+    fputs(" -t, --curses               use curses terminal interface\n",
+          out);
 #endif
-  fputs("     --displaymode MODE     select initial display mode\n", out);
+    fputs("     --displaymode MODE     select initial display mode\n",
+          out);
 #ifdef HAVE_GTK
-  fputs(" -g, --gtk                  use GTK+ xwindow interface\n", out);
+    fputs(" -g, --gtk                  use GTK+ xwindow interface\n", out);
 #endif
-  fputs(" -n, --no-dns               do not resove host names\n", out);
-  fputs(" -b, --show-ips             show IP numbers and host names\n", out);
-  fputs(" -o, --order FIELDS         select output fields\n", out);
+    fputs(" -n, --no-dns               do not resove host names\n", out);
+    fputs(" -b, --show-ips             show IP numbers and host names\n",
+          out);
+    fputs(" -o, --order FIELDS         select output fields\n", out);
 #ifdef HAVE_IPINFO
-  fputs(" -y, --ipinfo NUMBER        select IP information in output\n", out);
-  fputs(" -z, --aslookup             display AS number\n", out);
+    fputs(" -y, --ipinfo NUMBER        select IP information in output\n",
+          out);
+    fputs(" -z, --aslookup             display AS number\n", out);
 #endif
-  fputs(" -h, --help                 display this help and exit\n", out);
-  fputs(" -v, --version              output version information and exit\n", out);
-  fputs("\n", out);
-  fputs("See the 'man 8 mtr' for details.\n", out);
-  exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+    fputs(" -h, --help                 display this help and exit\n", out);
+    fputs
+        (" -v, --version              output version information and exit\n",
+         out);
+    fputs("\n", out);
+    fputs("See the 'man 8 mtr' for details.\n", out);
+    exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 
-static void
-append_to_names(names_t **names_head, const char *item) {
-  names_t** name_tail = names_head;
+static void append_to_names(
+    names_t ** names_head,
+    const char *item)
+{
+    names_t **name_tail = names_head;
 
-  while (*name_tail) {
-    name_tail = &(*name_tail)->next;
-  }
+    while (*name_tail) {
+        name_tail = &(*name_tail)->next;
+    }
 
-  names_t* name = calloc(1, sizeof(names_t));
-  if (name == NULL) {
-    error(EXIT_FAILURE, errno, "memory allocation failure");
-  }
-  name->name = xstrdup(item);
-  name->next = NULL;
+    names_t *name = calloc(1, sizeof(names_t));
+    if (name == NULL) {
+        error(EXIT_FAILURE, errno, "memory allocation failure");
+    }
+    name->name = xstrdup(item);
+    name->next = NULL;
 
-  *name_tail = name;
+    *name_tail = name;
 }
 
-static void
-read_from_file(names_t **names, const char *filename) {
+static void read_from_file(
+    names_t ** names,
+    const char *filename)
+{
 
-  FILE *in;
-  char line[512];
+    FILE *in;
+    char line[512];
 
-  if (! filename || strcmp(filename, "-") == 0) {
-    clearerr(stdin);
-    in = stdin;
-  } else {
-    in = fopen(filename, "r");
-    if (! in) {
-      error(EXIT_FAILURE, errno, "open %s", filename);
+    if (!filename || strcmp(filename, "-") == 0) {
+        clearerr(stdin);
+        in = stdin;
+    } else {
+        in = fopen(filename, "r");
+        if (!in) {
+            error(EXIT_FAILURE, errno, "open %s", filename);
+        }
     }
-  }
 
-  while (fgets(line, sizeof(line), in)) {
-    char* name = trim(line, '\0');
-    append_to_names(names, name);
-  }
+    while (fgets(line, sizeof(line), in)) {
+        char *name = trim(line, '\0');
+        append_to_names(names, name);
+    }
 
-  if (ferror(in)) {
-    error(EXIT_FAILURE, errno, "ferror %s", filename);
-  }
+    if (ferror(in)) {
+        error(EXIT_FAILURE, errno, "ferror %s", filename);
+    }
 
-  if (in != stdin) fclose(in);
+    if (in != stdin)
+        fclose(in);
 }
 
 /*
@@ -206,8 +238,9 @@ read_from_file(names_t **names, const char *filename) {
  * try to append results to a common file.
  */
 
-static void
-lock(FILE *f) {
+static void lock(
+    FILE * f)
+{
     int fd;
     struct stat buf;
     static struct flock lock;
@@ -222,9 +255,9 @@ lock(FILE *f) {
 
     fd = fileno(f);
     if ((fstat(fd, &buf) == 0) && S_ISREG(buf.st_mode)) {
-      if (fcntl(fd, F_SETLKW, &lock) == -1) {
-        error(0, errno, "fcntl (ignored)");
-      }
+        if (fcntl(fd, F_SETLKW, &lock) == -1) {
+            error(0, errno, "fcntl (ignored)");
+        }
     }
 }
 
@@ -233,8 +266,9 @@ lock(FILE *f) {
  * file (which presumably has previously been locked).
  */
 
-static void
-unlock(FILE *f) {
+static void unlock(
+    FILE * f)
+{
     int fd;
     struct stat buf;
     static struct flock lock;
@@ -249,533 +283,571 @@ unlock(FILE *f) {
 
     fd = fileno(f);
     if ((fstat(fd, &buf) == 0) && S_ISREG(buf.st_mode)) {
-      if (fcntl(fd, F_SETLKW, &lock) == -1) {
-        error(0, errno, "fcntl (ignored)");
-      }
+        if (fcntl(fd, F_SETLKW, &lock) == -1) {
+            error(0, errno, "fcntl (ignored)");
+        }
     }
 }
 
 
-static void init_fld_options (struct mtr_ctl *ctl)
+static void init_fld_options(
+    struct mtr_ctl *ctl)
 {
-  int i;
+    int i;
 
-  memset(ctl->fld_index, -1, FLD_INDEX_SZ);
+    memset(ctl->fld_index, -1, FLD_INDEX_SZ);
 
-  for (i=0;data_fields[i].key != 0;i++) {
-    ctl->available_options[i] = data_fields[i].key;
-    ctl->fld_index[data_fields[i].key] = i;
-  }
-  ctl->available_options[i] = 0;
+    for (i = 0; data_fields[i].key != 0; i++) {
+        ctl->available_options[i] = data_fields[i].key;
+        ctl->fld_index[data_fields[i].key] = i;
+    }
+    ctl->available_options[i] = 0;
 }
 
 
-static void parse_arg (struct mtr_ctl *ctl, names_t **names, int argc, char **argv)
+static void parse_arg(
+    struct mtr_ctl *ctl,
+    names_t ** names,
+    int argc,
+    char **argv)
 {
-  int opt;
-  int i;
-  /* IMPORTANT: when adding or modifying an option:
+    int opt;
+    int i;
+    /* IMPORTANT: when adding or modifying an option:
        0/ try to find a somewhat logical order;
        1/ add the long option name in "long_options" below;
        2/ update the man page (use the same order);
        3/ update the help message (see usage() function).
-   */
-  enum {
-    OPT_DISPLAYMODE = CHAR_MAX + 1
-  };
-  static const struct option long_options[] = {
-    /* option name, has argument, NULL, short name */
-    { "help",           0, NULL, 'h' },
-    { "version",        0, NULL, 'v' },
-
-    { "inet",           0, NULL, '4' }, /* IPv4 only */
+     */
+    enum {
+        OPT_DISPLAYMODE = CHAR_MAX + 1
+    };
+    static const struct option long_options[] = {
+        /* option name, has argument, NULL, short name */
+        {"help", 0, NULL, 'h'},
+        {"version", 0, NULL, 'v'},
+
+        {"inet", 0, NULL, '4'}, /* IPv4 only */
 #ifdef ENABLE_IPV6
-    { "inet6",          0, NULL, '6' }, /* IPv6 only */
+        {"inet6", 0, NULL, '6'},        /* IPv6 only */
 #endif
-    { "filename",       1, NULL, 'F' },
+        {"filename", 1, NULL, 'F'},
 
-    { "report",         0, NULL, 'r' },
-    { "report-wide",    0, NULL, 'w' },
-    { "xml",            0, NULL, 'x' },
+        {"report", 0, NULL, 'r'},
+        {"report-wide", 0, NULL, 'w'},
+        {"xml", 0, NULL, 'x'},
 #ifdef HAVE_CURSES
-    { "curses",         0, NULL, 't' },
+        {"curses", 0, NULL, 't'},
 #endif
 #ifdef HAVE_GTK
-    { "gtk",            0, NULL, 'g' },
+        {"gtk", 0, NULL, 'g'},
 #endif
-    { "raw",            0, NULL, 'l' },
-    { "csv",            0, NULL, 'C' },
-    { "json",           0, NULL, 'j' },
-    { "displaymode",    1, NULL, OPT_DISPLAYMODE },
-    { "split",          0, NULL, 'p' }, /* BL */
-                                        /* maybe above should change to -d 'x' */
-
-    { "no-dns",         0, NULL, 'n' },
-    { "show-ips",       0, NULL, 'b' },
-    { "order",          1, NULL, 'o' }, /* fields to display & their order */
+        {"raw", 0, NULL, 'l'},
+        {"csv", 0, NULL, 'C'},
+        {"json", 0, NULL, 'j'},
+        {"displaymode", 1, NULL, OPT_DISPLAYMODE},
+        {"split", 0, NULL, 'p'},        /* BL */
+        /* maybe above should change to -d 'x' */
+
+        {"no-dns", 0, NULL, 'n'},
+        {"show-ips", 0, NULL, 'b'},
+        {"order", 1, NULL, 'o'},        /* fields to display & their order */
 #ifdef HAVE_IPINFO
-    { "ipinfo",         1, NULL, 'y' }, /* IP info lookup */
-    { "aslookup",       0, NULL, 'z' }, /* Do AS lookup (--ipinfo 0) */
+        {"ipinfo", 1, NULL, 'y'},       /* IP info lookup */
+        {"aslookup", 0, NULL, 'z'},     /* Do AS lookup (--ipinfo 0) */
 #endif
 
-    { "interval",       1, NULL, 'i' },
-    { "report-cycles",  1, NULL, 'c' },
-    { "psize",          1, NULL, 's' }, /* overload psize<0, ->rand(min,max) */
-    { "bitpattern",     1, NULL, 'B' }, /* overload B>255, ->rand(0,255) */
-    { "tos",            1, NULL, 'Q' }, /* typeof service (0,255) */
-    { "mpls",           0, NULL, 'e' },
-    { "address",        1, NULL, 'a' },
-    { "first-ttl",      1, NULL, 'f' }, /* -f & -m are borrowed from traceroute */
-    { "max-ttl",        1, NULL, 'm' },
-       { "max-unknown",    1, NULL, 'U' },
-    { "udp",            0, NULL, 'u' }, /* UDP (default is ICMP) */
-    { "tcp",            0, NULL, 'T' }, /* TCP (default is ICMP) */
+        {"interval", 1, NULL, 'i'},
+        {"report-cycles", 1, NULL, 'c'},
+        {"psize", 1, NULL, 's'},        /* overload psize<0, ->rand(min,max) */
+        {"bitpattern", 1, NULL, 'B'},   /* overload B>255, ->rand(0,255) */
+        {"tos", 1, NULL, 'Q'},  /* typeof service (0,255) */
+        {"mpls", 0, NULL, 'e'},
+        {"address", 1, NULL, 'a'},
+        {"first-ttl", 1, NULL, 'f'},    /* -f & -m are borrowed from traceroute */
+        {"max-ttl", 1, NULL, 'm'},
+        {"max-unknown", 1, NULL, 'U'},
+        {"udp", 0, NULL, 'u'},  /* UDP (default is ICMP) */
+        {"tcp", 0, NULL, 'T'},  /* TCP (default is ICMP) */
 #ifdef HAS_SCTP
-    { "sctp",           0, NULL, 'S' }, /* SCTP (default is ICMP) */
+        {"sctp", 0, NULL, 'S'}, /* SCTP (default is ICMP) */
 #endif
-    { "port",           1, NULL, 'P' }, /* target port number for TCP/SCTP/UDP */
-    { "localport",      1, NULL, 'L' }, /* source port number for UDP */
-    { "timeout",        1, NULL, 'Z' }, /* timeout for probe sockets */
-    { "gracetime",      1, NULL, 'G' }, /* gracetime for replies after last probe */
+        {"port", 1, NULL, 'P'}, /* target port number for TCP/SCTP/UDP */
+        {"localport", 1, NULL, 'L'},    /* source port number for UDP */
+        {"timeout", 1, NULL, 'Z'},      /* timeout for probe sockets */
+        {"gracetime", 1, NULL, 'G'},    /* gracetime for replies after last probe */
 #ifdef SO_MARK
-    { "mark",           1, NULL, 'M' }, /* use SO_MARK */
+        {"mark", 1, NULL, 'M'}, /* use SO_MARK */
 #endif
-    { NULL, 0, NULL, 0 }
-  };
-  enum { num_options = sizeof(long_options) / sizeof(struct option) };
-  char short_options[num_options * 2];
-  size_t n, p;
-
-  for (n = p = 0; n < num_options; n++) {
-    if (CHAR_MAX < long_options[n].val) {
-      continue;
-    }
-    short_options[p] = long_options[n].val;
-    p++;
-    if (long_options[n].has_arg == 1) {
-      short_options[p] = ':';
-      p++;
+        {NULL, 0, NULL, 0}
+    };
+    enum { num_options = sizeof(long_options) / sizeof(struct option) };
+    char short_options[num_options * 2];
+    size_t n, p;
+
+    for (n = p = 0; n < num_options; n++) {
+        if (CHAR_MAX < long_options[n].val) {
+            continue;
+        }
+        short_options[p] = long_options[n].val;
+        p++;
+        if (long_options[n].has_arg == 1) {
+            short_options[p] = ':';
+            p++;
+        }
+        /* optional options need two ':', but ignore them now as they are not in use */
     }
-    /* optional options need two ':', but ignore them now as they are not in use */
-  }
-
-  opt = 0;
-  while(1) {
-    opt = getopt_long(argc, argv, short_options, long_options, NULL);
-    if(opt == -1)
-      break;
-
-    switch(opt) {
-    case 'v':
-      printf ("mtr " PACKAGE_VERSION "\n");
-      exit(EXIT_SUCCESS);
-      break;
-    case 'h':
-      usage(stdout);
-      break;
-
-    case 'r':
-      ctl->DisplayMode = DisplayReport;
-      break;
-    case 'w':
-      ctl->reportwide = 1;
-      ctl->DisplayMode = DisplayReport;
-      break;
+
+    opt = 0;
+    while (1) {
+        opt = getopt_long(argc, argv, short_options, long_options, NULL);
+        if (opt == -1)
+            break;
+
+        switch (opt) {
+        case 'v':
+            printf("mtr " PACKAGE_VERSION "\n");
+            exit(EXIT_SUCCESS);
+            break;
+        case 'h':
+            usage(stdout);
+            break;
+
+        case 'r':
+            ctl->DisplayMode = DisplayReport;
+            break;
+        case 'w':
+            ctl->reportwide = 1;
+            ctl->DisplayMode = DisplayReport;
+            break;
 #ifdef HAVE_CURSES
-    case 't':
-      ctl->DisplayMode = DisplayCurses;
-      break;
+        case 't':
+            ctl->DisplayMode = DisplayCurses;
+            break;
 #endif
 #ifdef HAVE_GTK
-    case 'g':
-      ctl->DisplayMode = DisplayGTK;
-      break;
+        case 'g':
+            ctl->DisplayMode = DisplayGTK;
+            break;
 #endif
-    case 'p':                 /* BL */
-      ctl->DisplayMode = DisplaySplit;
-      break;
-    case 'l':
-      ctl->DisplayMode = DisplayRaw;
-      break;
-    case 'C':
-      ctl->DisplayMode = DisplayCSV;
-      break;
-    case 'j':
-      ctl->DisplayMode = DisplayJSON;
-      break;
-    case 'x':
-      ctl->DisplayMode = DisplayXML;
-      break;
-
-    case OPT_DISPLAYMODE:
-      ctl->display_mode = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      if ((DisplayModeMAX - 1) < ctl->display_mode)
-        error(EXIT_FAILURE, 0, "value out of range (%d - %d): %s",
-              DisplayModeDefault, (DisplayModeMAX - 1), optarg);
-      break;
-    case 'c':
-      ctl->MaxPing = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      ctl->ForceMaxPing = 1;
-      break;
-    case 's':
-      ctl->cpacketsize = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      break;
-    case 'a':
-      ctl->InterfaceAddress = optarg;
-      break;
-    case 'e':
-      ctl->enablempls = 1;
-      break;
-    case 'n':
-      ctl->dns = 0;
-      break;
-    case 'i':
-      ctl->WaitTime = strtofloat_or_err(optarg, "invalid argument");
-      if (ctl->WaitTime <= 0.0) {
-        error(EXIT_FAILURE, 0, "wait time must be positive");
-      }
-      if (getuid() != 0 && ctl->WaitTime < 1.0) {
-        error(EXIT_FAILURE, 0, "non-root users cannot request an interval < 1.0 seconds");
-      }
-      break;
-    case 'f':
-      ctl->fstTTL = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      if (ctl->fstTTL > ctl->maxTTL) {
-       ctl->fstTTL = ctl->maxTTL;
-      }
-      if (ctl->fstTTL < 1) {                       /* prevent 0 hop */
-       ctl->fstTTL = 1;
-      }
-      break;
-    case 'F':
-      read_from_file(names, optarg);
-      break;
-    case 'm':
-      ctl->maxTTL = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      if (ctl->maxTTL > (MaxHost - 1)) {
-       ctl->maxTTL = MaxHost - 1;
-      }
-      if (ctl->maxTTL < 1) {                       /* prevent 0 hop */
-       ctl->maxTTL = 1;
-      }
-      if (ctl->fstTTL > ctl->maxTTL) {         /* don't know the pos of -m or -f */
-       ctl->fstTTL = ctl->maxTTL;
-      }
-      break;
-       case 'U':
-                ctl->maxUnknown = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-               if (ctl->maxUnknown < 1) {
-                       ctl->maxUnknown = 1;
-               }
-               break;
-    case 'o':
-      /* Check option before passing it on to fld_active. */
-      if (strlen (optarg) > MAXFLD) {
-       error(EXIT_FAILURE, 0, "Too many fields: %s", optarg);
-      }
-      for (i=0; optarg[i]; i++) {
-        if(!strchr (ctl->available_options, optarg[i])) {
-          error(EXIT_FAILURE, 0, "Unknown field identifier: %c", optarg[i]);
-        }
-      }
-      xstrncpy(ctl->fld_active, optarg, 2 * MAXFLD);
-      break;
-    case 'B':
-      ctl->bitpattern = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      if (ctl->bitpattern > 255)
-       ctl->bitpattern = -1;
-      break;
-    case 'G':
-      ctl->GraceTime = strtofloat_or_err(optarg, "invalid argument");
-      if (ctl->GraceTime <= 0.0) {
-        error(EXIT_FAILURE, 0, "wait time must be positive");
-      }
-      break;
-    case 'Q':
-      ctl->tos = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      if (ctl->tos > 255 || ctl->tos < 0) {
-       /* error message, should do more checking for valid values,
-        * details in rfc2474 */
-       ctl->tos = 0;
-      }
-      break;
-    case 'u':
-      if (ctl->mtrtype != IPPROTO_ICMP) {
-        error(EXIT_FAILURE, 0, "-u , -T and -S are mutually exclusive");
-      }
-      ctl->mtrtype = IPPROTO_UDP;
-      break;
-    case 'T':
-      if (ctl->mtrtype != IPPROTO_ICMP) {
-        error(EXIT_FAILURE, 0, "-u , -T and -S are mutually exclusive");
-      }
-      if (!ctl->remoteport) {
-        ctl->remoteport = 80;
-      }
-      ctl->mtrtype = IPPROTO_TCP;
-      break;
+        case 'p':              /* BL */
+            ctl->DisplayMode = DisplaySplit;
+            break;
+        case 'l':
+            ctl->DisplayMode = DisplayRaw;
+            break;
+        case 'C':
+            ctl->DisplayMode = DisplayCSV;
+            break;
+        case 'j':
+            ctl->DisplayMode = DisplayJSON;
+            break;
+        case 'x':
+            ctl->DisplayMode = DisplayXML;
+            break;
+
+        case OPT_DISPLAYMODE:
+            ctl->display_mode =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if ((DisplayModeMAX - 1) < ctl->display_mode)
+                error(EXIT_FAILURE, 0, "value out of range (%d - %d): %s",
+                      DisplayModeDefault, (DisplayModeMAX - 1), optarg);
+            break;
+        case 'c':
+            ctl->MaxPing =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            ctl->ForceMaxPing = 1;
+            break;
+        case 's':
+            ctl->cpacketsize =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            break;
+        case 'a':
+            ctl->InterfaceAddress = optarg;
+            break;
+        case 'e':
+            ctl->enablempls = 1;
+            break;
+        case 'n':
+            ctl->dns = 0;
+            break;
+        case 'i':
+            ctl->WaitTime = strtofloat_or_err(optarg, "invalid argument");
+            if (ctl->WaitTime <= 0.0) {
+                error(EXIT_FAILURE, 0, "wait time must be positive");
+            }
+            if (getuid() != 0 && ctl->WaitTime < 1.0) {
+                error(EXIT_FAILURE, 0,
+                      "non-root users cannot request an interval < 1.0 seconds");
+            }
+            break;
+        case 'f':
+            ctl->fstTTL =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if (ctl->fstTTL > ctl->maxTTL) {
+                ctl->fstTTL = ctl->maxTTL;
+            }
+            if (ctl->fstTTL < 1) {      /* prevent 0 hop */
+                ctl->fstTTL = 1;
+            }
+            break;
+        case 'F':
+            read_from_file(names, optarg);
+            break;
+        case 'm':
+            ctl->maxTTL =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if (ctl->maxTTL > (MaxHost - 1)) {
+                ctl->maxTTL = MaxHost - 1;
+            }
+            if (ctl->maxTTL < 1) {      /* prevent 0 hop */
+                ctl->maxTTL = 1;
+            }
+            if (ctl->fstTTL > ctl->maxTTL) {    /* don't know the pos of -m or -f */
+                ctl->fstTTL = ctl->maxTTL;
+            }
+            break;
+        case 'U':
+            ctl->maxUnknown =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if (ctl->maxUnknown < 1) {
+                ctl->maxUnknown = 1;
+            }
+            break;
+        case 'o':
+            /* Check option before passing it on to fld_active. */
+            if (strlen(optarg) > MAXFLD) {
+                error(EXIT_FAILURE, 0, "Too many fields: %s", optarg);
+            }
+            for (i = 0; optarg[i]; i++) {
+                if (!strchr(ctl->available_options, optarg[i])) {
+                    error(EXIT_FAILURE, 0, "Unknown field identifier: %c",
+                          optarg[i]);
+                }
+            }
+            xstrncpy(ctl->fld_active, optarg, 2 * MAXFLD);
+            break;
+        case 'B':
+            ctl->bitpattern =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if (ctl->bitpattern > 255)
+                ctl->bitpattern = -1;
+            break;
+        case 'G':
+            ctl->GraceTime = strtofloat_or_err(optarg, "invalid argument");
+            if (ctl->GraceTime <= 0.0) {
+                error(EXIT_FAILURE, 0, "wait time must be positive");
+            }
+            break;
+        case 'Q':
+            ctl->tos =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if (ctl->tos > 255 || ctl->tos < 0) {
+                /* error message, should do more checking for valid values,
+                 * details in rfc2474 */
+                ctl->tos = 0;
+            }
+            break;
+        case 'u':
+            if (ctl->mtrtype != IPPROTO_ICMP) {
+                error(EXIT_FAILURE, 0,
+                      "-u , -T and -S are mutually exclusive");
+            }
+            ctl->mtrtype = IPPROTO_UDP;
+            break;
+        case 'T':
+            if (ctl->mtrtype != IPPROTO_ICMP) {
+                error(EXIT_FAILURE, 0,
+                      "-u , -T and -S are mutually exclusive");
+            }
+            if (!ctl->remoteport) {
+                ctl->remoteport = 80;
+            }
+            ctl->mtrtype = IPPROTO_TCP;
+            break;
 #ifdef HAS_SCTP
-    case 'S':
-      if (ctl->mtrtype != IPPROTO_ICMP) {
-        error(EXIT_FAILURE, 0, "-u , -T and -S are mutually exclusive");
-      }
-      if (!ctl->remoteport) {
-        ctl->remoteport = 80;
-      }
-      ctl->mtrtype = IPPROTO_SCTP;
-      break;
+        case 'S':
+            if (ctl->mtrtype != IPPROTO_ICMP) {
+                error(EXIT_FAILURE, 0,
+                      "-u , -T and -S are mutually exclusive");
+            }
+            if (!ctl->remoteport) {
+                ctl->remoteport = 80;
+            }
+            ctl->mtrtype = IPPROTO_SCTP;
+            break;
 #endif
-    case 'b':
-      ctl->show_ips = 1;
-      break;
-    case 'P':
-      ctl->remoteport = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      if (ctl->remoteport < 1 || MaxPort < ctl->remoteport) {
-        error(EXIT_FAILURE, 0, "Illegal port number: %d", ctl->remoteport);
-      }
-      break;
-    case 'L':
-      ctl->localport = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      if (ctl->localport < MinPort || MaxPort < ctl->localport) {
-        error(EXIT_FAILURE, 0, "Illegal port number: %d", ctl->localport);
-      }
-      break;
-    case 'Z':
-      ctl->probe_timeout = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      ctl->probe_timeout *= 1000000;
-      break;
-    case '4':
-      ctl->af = AF_INET;
-      break;
+        case 'b':
+            ctl->show_ips = 1;
+            break;
+        case 'P':
+            ctl->remoteport =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if (ctl->remoteport < 1 || MaxPort < ctl->remoteport) {
+                error(EXIT_FAILURE, 0, "Illegal port number: %d",
+                      ctl->remoteport);
+            }
+            break;
+        case 'L':
+            ctl->localport =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if (ctl->localport < MinPort || MaxPort < ctl->localport) {
+                error(EXIT_FAILURE, 0, "Illegal port number: %d",
+                      ctl->localport);
+            }
+            break;
+        case 'Z':
+            ctl->probe_timeout =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            ctl->probe_timeout *= 1000000;
+            break;
+        case '4':
+            ctl->af = AF_INET;
+            break;
 #ifdef ENABLE_IPV6
-    case '6':
-      ctl->af = AF_INET6;
-      break;
+        case '6':
+            ctl->af = AF_INET6;
+            break;
 #endif
 #ifdef HAVE_IPINFO
-    case 'y':
-      ctl->ipinfo_no = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
-      if (ctl->ipinfo_no < 0 || 4 < ctl->ipinfo_no) {
-        error(EXIT_FAILURE, 0, "value %d out of range (0 - 4)", ctl->ipinfo_no);
-      }
-      break;
-    case 'z':
-      ctl->ipinfo_no = 0;
-      break;
+        case 'y':
+            ctl->ipinfo_no =
+                strtonum_or_err(optarg, "invalid argument", STRTO_INT);
+            if (ctl->ipinfo_no < 0 || 4 < ctl->ipinfo_no) {
+                error(EXIT_FAILURE, 0, "value %d out of range (0 - 4)",
+                      ctl->ipinfo_no);
+            }
+            break;
+        case 'z':
+            ctl->ipinfo_no = 0;
+            break;
 #endif
 #ifdef SO_MARK
-    case 'M':
-      ctl->mark = strtonum_or_err(optarg, "invalid argument", STRTO_U32INT);
-      break;
+        case 'M':
+            ctl->mark =
+                strtonum_or_err(optarg, "invalid argument", STRTO_U32INT);
+            break;
 #endif
-    default:
-      usage(stderr);
+        default:
+            usage(stderr);
+        }
     }
-  }
 
-  if (ctl->DisplayMode == DisplayReport ||
-      ctl->DisplayMode == DisplayTXT ||
-      ctl->DisplayMode == DisplayJSON ||
-      ctl->DisplayMode == DisplayXML ||
-      ctl->DisplayMode == DisplayRaw ||
-      ctl->DisplayMode == DisplayCSV)
-    ctl->Interactive = 0;
+    if (ctl->DisplayMode == DisplayReport ||
+        ctl->DisplayMode == DisplayTXT ||
+        ctl->DisplayMode == DisplayJSON ||
+        ctl->DisplayMode == DisplayXML ||
+        ctl->DisplayMode == DisplayRaw || ctl->DisplayMode == DisplayCSV)
+        ctl->Interactive = 0;
 
-  if (optind > argc - 1)
-    return;
+    if (optind > argc - 1)
+        return;
 
 }
 
 
-static void parse_mtr_options (struct mtr_ctl *ctl, names_t **names, char *string)
+static void parse_mtr_options(
+    struct mtr_ctl *ctl,
+    names_t ** names,
+    char *string)
 {
-  int argc = 1;
-  char *argv[128], *p;
-
-  if (!string) return;
-  argv[0] = xstrdup(PACKAGE_NAME);
-  argc = 1;
-  p = strtok (string, " \t");
-  while (p != NULL && ((size_t) argc < (sizeof(argv)/sizeof(argv[0])))) {
-    argv[argc++] = p;
-    p = strtok (NULL, " \t");
-  }
-  if (p != NULL) {
-    error(0, 0, "Warning: extra arguments ignored: %s", p);
-  }
-
-  parse_arg (ctl, names, argc, argv);
-  free(argv[0]);
-  optind = 0;
+    int argc = 1;
+    char *argv[128], *p;
+
+    if (!string)
+        return;
+    argv[0] = xstrdup(PACKAGE_NAME);
+    argc = 1;
+    p = strtok(string, " \t");
+    while (p != NULL && ((size_t) argc < (sizeof(argv) / sizeof(argv[0])))) {
+        argv[argc++] = p;
+        p = strtok(NULL, " \t");
+    }
+    if (p != NULL) {
+        error(0, 0, "Warning: extra arguments ignored: %s", p);
+    }
+
+    parse_arg(ctl, names, argc, argv);
+    free(argv[0]);
+    optind = 0;
 }
 
-static void init_rand(void)
+static void init_rand(
+    void)
 {
-  struct timeval tv;
+    struct timeval tv;
 
-  gettimeofday(&tv, NULL);
-  srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
+    gettimeofday(&tv, NULL);
+    srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
 }
 
-int main(int argc, char **argv)
+int main(
+    int argc,
+    char **argv)
 {
-  struct hostent *  host                = NULL;
-  struct addrinfo       hints, *res;
-  int                   gai_error;
-  struct hostent        trhost;
-  char *                alptr[2];
-  struct sockaddr_in *  sa4;
+    struct hostent *host = NULL;
+    struct addrinfo hints, *res;
+    int gai_error;
+    struct hostent trhost;
+    char *alptr[2];
+    struct sockaddr_in *sa4;
 #ifdef ENABLE_IPV6
-  struct sockaddr_in6 * sa6;
+    struct sockaddr_in6 *sa6;
 #endif
-  names_t *names_head = NULL;
-  names_t *names_walk;
-
-  struct mtr_ctl ctl;
-  memset(&ctl, 0, sizeof(ctl));
-  /* initialize non-null values */
-  ctl.Interactive = 1;
-  ctl.MaxPing = 10;
-  ctl.WaitTime = 1.0;
-  ctl.GraceTime = 5.0;
-  ctl.dns = 1;
-  ctl.use_dns = 1;
-  ctl.cpacketsize = 64;
-  ctl.af = DEFAULT_AF;
-  ctl.mtrtype = IPPROTO_ICMP;
-  ctl.fstTTL = 1;
-  ctl.maxTTL = 30;
-  ctl.maxUnknown = 12;
-  ctl.probe_timeout = 10 * 1000000;
-  ctl.ipinfo_no = -1;
-  ctl.ipinfo_max = -1;
-  xstrncpy(ctl.fld_active, "LS NABWV", 2 * MAXFLD);
-
-  /*
-    mtr used to be suid root.  It should not be with this version.
-    We'll check so that we can notify people using installation
-    mechanisms with obsolete assumptions.
-  */
-  if ((geteuid() != getuid()) || (getegid() != getgid())) {
-    error(EXIT_FAILURE, errno, "mtr should not run suid");
-  }
-
-  /* This will check if stdout/stderr writing is successful */
-  atexit(close_stdout);
-
-  /* reset the random seed */
-  init_rand();
-
-  display_detect(&ctl, &argc, &argv);
-  ctl.display_mode = DisplayModeDefault;
-
-  /* The field options are now in a static array all together,
-     but that requires a run-time initialization. */
-  init_fld_options (&ctl);
-
-  parse_mtr_options(&ctl, &names_head, getenv ("MTR_OPTIONS"));
-
-  parse_arg(&ctl, &names_head, argc, argv);
-
-  while (optind < argc) {
-    char* name = argv[optind++];
-    append_to_names(&names_head, name);
-  }
-
-  /* default: localhost. */
-  if (!names_head) append_to_names(&names_head, "localhost");
-
-  names_walk = names_head;
-  while (names_walk != NULL) {
-
-    ctl.Hostname = names_walk->name;
-    if (gethostname(ctl.LocalHostname, sizeof(ctl.LocalHostname))) {
-      xstrncpy(ctl.LocalHostname, "UNKNOWNHOST", sizeof(ctl.LocalHostname));
+    names_t *names_head = NULL;
+    names_t *names_walk;
+
+    struct mtr_ctl ctl;
+    memset(&ctl, 0, sizeof(ctl));
+    /* initialize non-null values */
+    ctl.Interactive = 1;
+    ctl.MaxPing = 10;
+    ctl.WaitTime = 1.0;
+    ctl.GraceTime = 5.0;
+    ctl.dns = 1;
+    ctl.use_dns = 1;
+    ctl.cpacketsize = 64;
+    ctl.af = DEFAULT_AF;
+    ctl.mtrtype = IPPROTO_ICMP;
+    ctl.fstTTL = 1;
+    ctl.maxTTL = 30;
+    ctl.maxUnknown = 12;
+    ctl.probe_timeout = 10 * 1000000;
+    ctl.ipinfo_no = -1;
+    ctl.ipinfo_max = -1;
+    xstrncpy(ctl.fld_active, "LS NABWV", 2 * MAXFLD);
+
+    /*
+       mtr used to be suid root.  It should not be with this version.
+       We'll check so that we can notify people using installation
+       mechanisms with obsolete assumptions.
+     */
+    if ((geteuid() != getuid()) || (getegid() != getgid())) {
+        error(EXIT_FAILURE, errno, "mtr should not run suid");
     }
 
-    /* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */
-    memset( &hints, 0, sizeof hints );
-    hints.ai_family = ctl.af;
-    hints.ai_socktype = SOCK_DGRAM;
-    gai_error = getaddrinfo( ctl.Hostname, NULL, &hints, &res );
-    if ( gai_error ) {
-      if (gai_error == EAI_SYSTEM)
-         error(0, 0, "Failed to resolve host: %s", ctl.Hostname);
-      else
-         error(0, 0, "Failed to resolve host: %s: %s", ctl.Hostname, gai_strerror(gai_error));
-
-      if (ctl.Interactive) exit(EXIT_FAILURE);
-      else {
-        names_walk = names_walk->next;
-        continue;
-      }
+    /* This will check if stdout/stderr writing is successful */
+    atexit(close_stdout);
+
+    /* reset the random seed */
+    init_rand();
+
+    display_detect(&ctl, &argc, &argv);
+    ctl.display_mode = DisplayModeDefault;
+
+    /* The field options are now in a static array all together,
+       but that requires a run-time initialization. */
+    init_fld_options(&ctl);
+
+    parse_mtr_options(&ctl, &names_head, getenv("MTR_OPTIONS"));
+
+    parse_arg(&ctl, &names_head, argc, argv);
+
+    while (optind < argc) {
+        char *name = argv[optind++];
+        append_to_names(&names_head, name);
     }
-    /* Convert the first addrinfo into a hostent. */
-    host = &trhost;
-    memset( host, 0, sizeof trhost );
-    host->h_name = res->ai_canonname;
-    host->h_aliases = NULL;
-    host->h_addrtype = res->ai_family;
-    ctl.af = res->ai_family;
-    host->h_length = res->ai_addrlen;
-    host->h_addr_list = alptr;
-    switch (ctl.af) {
-    case AF_INET:
-      sa4 = (struct sockaddr_in *) res->ai_addr;
-      alptr[0] = (void *) &(sa4->sin_addr);
-      break;
+
+    /* default: localhost. */
+    if (!names_head)
+        append_to_names(&names_head, "localhost");
+
+    names_walk = names_head;
+    while (names_walk != NULL) {
+
+        ctl.Hostname = names_walk->name;
+        if (gethostname(ctl.LocalHostname, sizeof(ctl.LocalHostname))) {
+            xstrncpy(ctl.LocalHostname, "UNKNOWNHOST",
+                     sizeof(ctl.LocalHostname));
+        }
+
+        /* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */
+        memset(&hints, 0, sizeof hints);
+        hints.ai_family = ctl.af;
+        hints.ai_socktype = SOCK_DGRAM;
+        gai_error = getaddrinfo(ctl.Hostname, NULL, &hints, &res);
+        if (gai_error) {
+            if (gai_error == EAI_SYSTEM)
+                error(0, 0, "Failed to resolve host: %s", ctl.Hostname);
+            else
+                error(0, 0, "Failed to resolve host: %s: %s", ctl.Hostname,
+                      gai_strerror(gai_error));
+
+            if (ctl.Interactive)
+                exit(EXIT_FAILURE);
+            else {
+                names_walk = names_walk->next;
+                continue;
+            }
+        }
+        /* Convert the first addrinfo into a hostent. */
+        host = &trhost;
+        memset(host, 0, sizeof trhost);
+        host->h_name = res->ai_canonname;
+        host->h_aliases = NULL;
+        host->h_addrtype = res->ai_family;
+        ctl.af = res->ai_family;
+        host->h_length = res->ai_addrlen;
+        host->h_addr_list = alptr;
+        switch (ctl.af) {
+        case AF_INET:
+            sa4 = (struct sockaddr_in *) res->ai_addr;
+            alptr[0] = (void *) &(sa4->sin_addr);
+            break;
 #ifdef ENABLE_IPV6
-    case AF_INET6:
-      sa6 = (struct sockaddr_in6 *) res->ai_addr;
-      alptr[0] = (void *) &(sa6->sin6_addr);
-      break;
+        case AF_INET6:
+            sa6 = (struct sockaddr_in6 *) res->ai_addr;
+            alptr[0] = (void *) &(sa6->sin6_addr);
+            break;
 #endif
-    default:
-      error(0, 0, "unknown address type");
-      if (ctl.Interactive)
-        exit(EXIT_FAILURE);
-      else {
-        names_walk = names_walk->next;
-        continue;
-      }
-    }
-    alptr[1] = NULL;
-
-    if (net_open(&ctl, host) != 0) {
-      error(0, 0, "Unable to start net module");
-      if (ctl.Interactive)
-        exit(EXIT_FAILURE);
-      else {
-        names_walk = names_walk->next;
-        continue;
-      }
-    }
+        default:
+            error(0, 0, "unknown address type");
+            if (ctl.Interactive)
+                exit(EXIT_FAILURE);
+            else {
+                names_walk = names_walk->next;
+                continue;
+            }
+        }
+        alptr[1] = NULL;
+
+        if (net_open(&ctl, host) != 0) {
+            error(0, 0, "Unable to start net module");
+            if (ctl.Interactive)
+                exit(EXIT_FAILURE);
+            else {
+                names_walk = names_walk->next;
+                continue;
+            }
+        }
 
-    lock(stdout);
-      dns_open(&ctl);
-      display_open(&ctl);
+        lock(stdout);
+        dns_open(&ctl);
+        display_open(&ctl);
 
-      display_loop(&ctl);
+        display_loop(&ctl);
 
-      net_end_transit();
-      display_close(&ctl);
-    unlock(stdout);
+        net_end_transit();
+        display_close(&ctl);
+        unlock(stdout);
 
-    if (ctl.Interactive)
-      break;
-    else
-      names_walk = names_walk->next;
+        if (ctl.Interactive)
+            break;
+        else
+            names_walk = names_walk->next;
 
-  }
+    }
 
-  net_close();
+    net_close();
 
-  while (names_head != NULL) {
-    names_t* item = names_head;
-    free(item->name); item->name = NULL;
-    names_head = item->next;
-    free(item); item = NULL;
-  }
+    while (names_head != NULL) {
+        names_t *item = names_head;
+        free(item->name);
+        item->name = NULL;
+        names_head = item->next;
+        free(item);
+        item = NULL;
+    }
 
-  return 0;
+    return 0;
 }
index 364ed2ab10330d12d652f69a3fc847e2c6be68fe..7ede21d8a49f1e6f31b4b3d35c61028c047a9444 100644 (file)
--- a/ui/mtr.h
+++ b/ui/mtr.h
@@ -43,20 +43,20 @@ typedef int time_t;
 
 /* The __unused__ attribute was added in gcc 3.2.7.  */
 #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define ATTRIBUTE_UNUSED __attribute__((__unused__))
+#define ATTRIBUTE_UNUSED __attribute__((__unused__))
 #else
-# define ATTRIBUTE_UNUSED /* empty */
+#define ATTRIBUTE_UNUSED        /* empty */
 #endif
 
 /* The __const__ attribute was added in gcc 2.95.  */
 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
-# define ATTRIBUTE_CONST __attribute__ ((__const__))
+#define ATTRIBUTE_CONST __attribute__ ((__const__))
 #else
-# define ATTRIBUTE_CONST /* empty */
+#define ATTRIBUTE_CONST         /* empty */
 #endif
 
 /* stuff used by display such as report, curses... */
-#define MAXFLD 20              /* max stats fields to display */
+#define MAXFLD 20               /* max stats fields to display */
 #define FLD_INDEX_SZ 256
 
 /* net related definitions */
@@ -71,7 +71,7 @@ typedef int time_t;
 
 /* Stream Control Transmission Protocol is defined in netinet/in.h */
 #ifdef IPPROTO_SCTP
-# define HAS_SCTP 1
+#define HAS_SCTP 1
 #endif
 
 #ifndef HAVE_SOCKLEN_T
@@ -79,65 +79,63 @@ typedef int socklen_t;
 #endif
 
 struct mtr_ctl {
-  int MaxPing;
-  float WaitTime;
-  float GraceTime;
-  char *Hostname;
-  char *InterfaceAddress;
-  char LocalHostname[128];
-  int ipinfo_no;
-  int ipinfo_max;
-  int cpacketsize;             /* packet size used by ping */
-  int bitpattern;              /* packet bit pattern used by ping */
-  int tos;                     /* type of service set in ping packet*/
+    int MaxPing;
+    float WaitTime;
+    float GraceTime;
+    char *Hostname;
+    char *InterfaceAddress;
+    char LocalHostname[128];
+    int ipinfo_no;
+    int ipinfo_max;
+    int cpacketsize;            /* packet size used by ping */
+    int bitpattern;             /* packet bit pattern used by ping */
+    int tos;                    /* type of service set in ping packet */
 #ifdef SO_MARK
-  uint32_t mark;
+    uint32_t mark;
 #endif
-  ip_t unspec_addr;
-  int af;                      /* address family of remote target */
-  int mtrtype;                 /* type of query packet used */
-  int fstTTL;                  /* initial hub(ttl) to ping byMin */
-  int maxTTL;                  /* last hub to ping byMin*/
-  int maxUnknown;              /* stop ping threshold */
-  int remoteport;              /* target port for TCP tracing */
-  int localport;               /* source port for UDP tracing */
-  int probe_timeout;           /* timeout for probe sockets */
-  unsigned char fld_active[2 * MAXFLD];        /* SO_MARK to set for ping packet*/
-  int display_mode;            /* display mode selector */
-  int fld_index[FLD_INDEX_SZ]; /* default display field (defined by key in net.h) and order */
-  char available_options[MAXFLD];
-  int display_offset;          /* only used in text mode */
-  void *gtk_data;              /* pointer to hold arbitrary gtk data */
-  unsigned int                 /* bit field to hold named booleans */
-    ForceMaxPing:1,
-    use_dns:1,
-    show_ips:1,
-    enablempls:1,
-    dns:1,
-    reportwide:1,
-    Interactive:1,
-    DisplayMode:5;
+    ip_t unspec_addr;
+    int af;                     /* address family of remote target */
+    int mtrtype;                /* type of query packet used */
+    int fstTTL;                 /* initial hub(ttl) to ping byMin */
+    int maxTTL;                 /* last hub to ping byMin */
+    int maxUnknown;             /* stop ping threshold */
+    int remoteport;             /* target port for TCP tracing */
+    int localport;              /* source port for UDP tracing */
+    int probe_timeout;          /* timeout for probe sockets */
+    unsigned char fld_active[2 * MAXFLD];       /* SO_MARK to set for ping packet */
+    int display_mode;           /* display mode selector */
+    int fld_index[FLD_INDEX_SZ];        /* default display field (defined by key in net.h) and order */
+    char available_options[MAXFLD];
+    int display_offset;         /* only used in text mode */
+    void *gtk_data;             /* pointer to hold arbitrary gtk data */
+    unsigned int                /* bit field to hold named booleans */
+     ForceMaxPing:1,
+        use_dns:1,
+        show_ips:1,
+        enablempls:1, dns:1, reportwide:1, Interactive:1, DisplayMode:5;
 };
 
 /* dynamic field drawing */
 struct fields {
-  const unsigned char key;
-  const char *descr;
-  const char *title;
-  const char *format;
-  const int length;
-  int (*net_xxx)(int);
+    const unsigned char key;
+    const char *descr;
+    const char *title;
+    const char *format;
+    const int length;
+    int (
+    *net_xxx) (
+    int);
 };
 /* defined in mtr.c */
 extern const struct fields data_fields[MAXFLD];
 
 /* MPLS label object */
 struct mplslen {
-  unsigned long label[MAXLABELS]; /* label value */
-  uint8_t exp[MAXLABELS];         /* experimental bits */
-  uint8_t ttl[MAXLABELS];         /* MPLS TTL */
-  char s[MAXLABELS];              /* bottom of stack */
-  char labels;                    /* how many labels did we get? */
+    unsigned long label[MAXLABELS];     /* label value */
+    uint8_t exp[MAXLABELS];     /* experimental bits */
+    uint8_t ttl[MAXLABELS];     /* MPLS TTL */
+    char s[MAXLABELS];          /* bottom of stack */
+    char labels;                /* how many labels did we get? */
 };
 
-#endif /* MTR_MTR_H */
+#endif                          /* MTR_MTR_H */
index ec884544c931ffe9c642c8541331518f29a62278..3a7abc8614e1df679eb3e5acf1f32089968efb99 100644 (file)
--- a/ui/net.c
+++ b/ui/net.c
@@ -26,9 +26,9 @@
 #include <unistd.h>
 
 #ifdef HAVE_ERROR_H
-# include <error.h>
+#include <error.h>
 #else
-# include "portability/error.h"
+#include "portability/error.h"
 #endif
 
 #include "mtr.h"
 #define MinSequence 33000
 #define MaxSequence 65536
 
-static int packetsize;         /* packet size used by ping */
+static int packetsize;          /* packet size used by ping */
 
-static void sockaddrtop( struct sockaddr * saddr, char * strptr, size_t len );
+static void sockaddrtop(
+    struct sockaddr *saddr,
+    char *strptr,
+    size_t len);
 
 struct nethost {
-  ip_t addr;
-  ip_t addrs[MAXPATH];  /* for multi paths byMin */
-  int xmit;
-  int returned;
-  int sent;
-  int up;
-  long long ssd; /* sum of squares of differences from the current average */
-  int last;
-  int best;
-  int worst;
-  int avg;      /* average:  addByMin */
-  int gmean;    /* geometric mean: addByMin */
-  int jitter;   /* current jitter, defined as t1-t0 addByMin */
-  int javg;     /* avg jitter */
-  int jworst;   /* max jitter */
-  int jinta;    /* estimated variance,? rfc1889's "Interarrival Jitter" */
-  int transit;
-  int saved[SAVED_PINGS];
-  int saved_seq_offset;
-  struct mplslen mpls;
-  struct mplslen mplss[MAXPATH];
+    ip_t addr;
+    ip_t addrs[MAXPATH];        /* for multi paths byMin */
+    int xmit;
+    int returned;
+    int sent;
+    int up;
+    long long ssd;              /* sum of squares of differences from the current average */
+    int last;
+    int best;
+    int worst;
+    int avg;                    /* average:  addByMin */
+    int gmean;                  /* geometric mean: addByMin */
+    int jitter;                 /* current jitter, defined as t1-t0 addByMin */
+    int javg;                   /* avg jitter */
+    int jworst;                 /* max jitter */
+    int jinta;                  /* estimated variance,? rfc1889's "Interarrival Jitter" */
+    int transit;
+    int saved[SAVED_PINGS];
+    int saved_seq_offset;
+    struct mplslen mpls;
+    struct mplslen mplss[MAXPATH];
 };
 
 
 struct sequence {
-  int index;
-  int transit;
-  int saved_seq;
-  struct timeval time;
+    int index;
+    int transit;
+    int saved_seq;
+    struct timeval time;
 };
 
 
@@ -85,27 +88,33 @@ static struct packet_command_pipe_t packet_command_pipe;
 #ifdef ENABLE_IPV6
 static struct sockaddr_storage sourcesockaddr_struct;
 static struct sockaddr_storage remotesockaddr_struct;
-static struct sockaddr_in6 * ssa6 = (struct sockaddr_in6 *) &sourcesockaddr_struct;
-static struct sockaddr_in6 * rsa6 = (struct sockaddr_in6 *) &remotesockaddr_struct;
+static struct sockaddr_in6 *ssa6 =
+    (struct sockaddr_in6 *) &sourcesockaddr_struct;
+static struct sockaddr_in6 *rsa6 =
+    (struct sockaddr_in6 *) &remotesockaddr_struct;
 #else
 static struct sockaddr_in sourcesockaddr_struct;
 static struct sockaddr_in remotesockaddr_struct;
 #endif
 
-static struct sockaddr * sourcesockaddr = (struct sockaddr *) &sourcesockaddr_struct;
-static struct sockaddr * remotesockaddr = (struct sockaddr *) &remotesockaddr_struct;
-static struct sockaddr_in * ssa4 = (struct sockaddr_in *) &sourcesockaddr_struct;
-static struct sockaddr_in * rsa4 = (struct sockaddr_in *) &remotesockaddr_struct;
+static struct sockaddr *sourcesockaddr =
+    (struct sockaddr *) &sourcesockaddr_struct;
+static struct sockaddr *remotesockaddr =
+    (struct sockaddr *) &remotesockaddr_struct;
+static struct sockaddr_in *ssa4 =
+    (struct sockaddr_in *) &sourcesockaddr_struct;
+static struct sockaddr_in *rsa4 =
+    (struct sockaddr_in *) &remotesockaddr_struct;
 
-static ip_t * sourceaddress;
-static ip_t * remoteaddress;
+static ip_t *sourceaddress;
+static ip_t *remoteaddress;
 
 #ifdef ENABLE_IPV6
 static char localaddr[INET6_ADDRSTRLEN];
 #else
-# ifndef INET_ADDRSTRLEN
-#  define INET_ADDRSTRLEN 16
-# endif
+#ifndef INET_ADDRSTRLEN
+#define INET_ADDRSTRLEN 16
+#endif
 static char localaddr[INET_ADDRSTRLEN];
 #endif
 
@@ -114,411 +123,461 @@ static int numhosts = 10;
 
 /* return the number of microseconds to wait before sending the next
    ping */
-int calc_deltatime (float waittime)
+int calc_deltatime(
+    float waittime)
 {
-  waittime /= numhosts;
-  return 1000000 * waittime;
+    waittime /= numhosts;
+    return 1000000 * waittime;
 }
 
 
-static void save_sequence(struct mtr_ctl *ctl, int index, int seq)
+static void save_sequence(
+    struct mtr_ctl *ctl,
+    int index,
+    int seq)
 {
-  display_rawxmit(ctl, index, seq);
+    display_rawxmit(ctl, index, seq);
+
+    sequence[seq].index = index;
+    sequence[seq].transit = 1;
+    sequence[seq].saved_seq = ++host[index].xmit;
+    memset(&sequence[seq].time, 0, sizeof(sequence[seq].time));
 
-  sequence[seq].index = index;
-  sequence[seq].transit = 1;
-  sequence[seq].saved_seq = ++host[index].xmit;
-  memset(&sequence[seq].time, 0, sizeof(sequence[seq].time));
-  
-  host[index].transit = 1;
+    host[index].transit = 1;
 
-  if ( host[index].sent ) {
-    host[index].up = 0;
-  }
+    if (host[index].sent) {
+        host[index].up = 0;
+    }
 
-  host[index].sent = 1;
-  net_save_xmit(index);
+    host[index].sent = 1;
+    net_save_xmit(index);
 }
 
-static int new_sequence(struct mtr_ctl *ctl, int index)
+static int new_sequence(
+    struct mtr_ctl *ctl,
+    int index)
 {
-  static int next_sequence = MinSequence;
-  int seq;
+    static int next_sequence = MinSequence;
+    int seq;
 
-  seq = next_sequence++;
-  if ( next_sequence >= MaxSequence ) {
-    next_sequence = MinSequence;
-  }
+    seq = next_sequence++;
+    if (next_sequence >= MaxSequence) {
+        next_sequence = MinSequence;
+    }
 
-  save_sequence(ctl, index, seq);
+    save_sequence(ctl, index, seq);
 
-  return seq;
+    return seq;
 }
 
 
 /*  Attempt to find the host at a particular number of hops away  */
-static void net_send_query(struct mtr_ctl *ctl, int index, int packet_size)
+static void net_send_query(
+    struct mtr_ctl *ctl,
+    int index,
+    int packet_size)
 {
-  int seq = new_sequence(ctl, index);
-  int time_to_live = index + 1;
+    int seq = new_sequence(ctl, index);
+    int time_to_live = index + 1;
 
-  send_probe_command(
-    ctl, &packet_command_pipe, remoteaddress, sourceaddress,
-    packetsize, seq, time_to_live);
+    send_probe_command(ctl, &packet_command_pipe, remoteaddress,
+                       sourceaddress, packetsize, seq, time_to_live);
 }
 
 
 /* We got a return on something we sent out.  Record the address and
    time.  */
 static void net_process_ping(
-  struct mtr_ctl *ctl,
-  int seq,
-  struct mplslen *mpls,
-  ip_t *addr,
-  int totusec)
-{
-  int index;
-  int oldavg;   /* usedByMin */
-  int oldjavg;  /* usedByMin */
-  int i;        /* usedByMin */
+    struct mtr_ctl *ctl,
+    int seq,
+    struct mplslen *mpls,
+    ip_t * addr,
+    int totusec)
+{
+    int index;
+    int oldavg;                 /* usedByMin */
+    int oldjavg;                /* usedByMin */
+    int i;                      /* usedByMin */
 #ifdef ENABLE_IPV6
-  char addrcopy[sizeof(struct in6_addr)];
+    char addrcopy[sizeof(struct in6_addr)];
 #else
-  char addrcopy[sizeof(struct in_addr)];
+    char addrcopy[sizeof(struct in_addr)];
 #endif
 
-  addrcpy( (void *) &addrcopy, (char *)addr, ctl->af );
-
-  if ( (seq < 0) || (seq >= MaxSequence) ) {
-    return;
-  }
-
-  if ( !sequence[seq].transit) {
-    return;
-  }
-  sequence[seq].transit = 0;
-
-  index = sequence[seq].index;
-
-  if ( addrcmp( (void *) &(host[index].addr),
-                (void *) &ctl->unspec_addr, ctl->af ) == 0 ) {
-    /* should be out of if as addr can change */
-    addrcpy( (void *) &(host[index].addr), addrcopy, ctl->af );
-    host[index].mpls = *mpls;
-    display_rawhost(ctl, index, (void *) &(host[index].addr));
-
-    /* multi paths */
-    addrcpy( (void *) &(host[index].addrs[0]), addrcopy, ctl->af );
-    host[index].mplss[0] = *mpls;
-  } else {
-    for ( i=0; i<MAXPATH; ) {
-      if ( addrcmp( (void *) &(host[index].addrs[i]), (void *) &addrcopy,
-                    ctl->af ) == 0 ||
-           addrcmp( (void *) &(host[index].addrs[i]),
-                    (void *) &ctl->unspec_addr, ctl->af ) == 0 ) {
-        break;
-      } 
-      i++;
+    addrcpy((void *) &addrcopy, (char *) addr, ctl->af);
+
+    if ((seq < 0) || (seq >= MaxSequence)) {
+        return;
     }
 
-    if ( addrcmp( (void *) &(host[index].addrs[i]), addrcopy, ctl->af ) != 0 && i<MAXPATH ) {
-      addrcpy( (void *) &(host[index].addrs[i]), addrcopy, ctl->af );
-      host[index].mplss[i] = *mpls;
-      display_rawhost(ctl, index, (void *) &(host[index].addrs[i]));
+    if (!sequence[seq].transit) {
+        return;
     }
-  }
+    sequence[seq].transit = 0;
+
+    index = sequence[seq].index;
 
-  host[index].jitter = totusec - host[index].last;
-  if ( host[index].jitter < 0 ) {
-    host[index].jitter = - host[index].jitter;
-  }
+    if (addrcmp((void *) &(host[index].addr),
+                (void *) &ctl->unspec_addr, ctl->af) == 0) {
+        /* should be out of if as addr can change */
+        addrcpy((void *) &(host[index].addr), addrcopy, ctl->af);
+        host[index].mpls = *mpls;
+        display_rawhost(ctl, index, (void *) &(host[index].addr));
 
-  host[index].last = totusec;
+        /* multi paths */
+        addrcpy((void *) &(host[index].addrs[0]), addrcopy, ctl->af);
+        host[index].mplss[0] = *mpls;
+    } else {
+        for (i = 0; i < MAXPATH;) {
+            if (addrcmp
+                ((void *) &(host[index].addrs[i]), (void *) &addrcopy,
+                 ctl->af) == 0
+                || addrcmp((void *) &(host[index].addrs[i]),
+                           (void *) &ctl->unspec_addr, ctl->af) == 0) {
+                break;
+            }
+            i++;
+        }
+
+        if (addrcmp((void *) &(host[index].addrs[i]), addrcopy, ctl->af) !=
+            0 && i < MAXPATH) {
+            addrcpy((void *) &(host[index].addrs[i]), addrcopy, ctl->af);
+            host[index].mplss[i] = *mpls;
+            display_rawhost(ctl, index, (void *) &(host[index].addrs[i]));
+        }
+    }
 
-  if ( host[index].returned < 1 ) {
-    host[index].best = host[index].worst = host[index].gmean = totusec;
-    host[index].avg  = host[index].ssd  = 0;
+    host[index].jitter = totusec - host[index].last;
+    if (host[index].jitter < 0) {
+        host[index].jitter = -host[index].jitter;
+    }
 
-    host[index].jitter = host[index].jworst = host[index].jinta= 0;
-  }
+    host[index].last = totusec;
 
-  if ( totusec < host[index].best ) {
-    host[index].best  = totusec;
-  }
-  if ( totusec > host[index].worst ) {
-    host[index].worst = totusec;
-  }
+    if (host[index].returned < 1) {
+        host[index].best = host[index].worst = host[index].gmean = totusec;
+        host[index].avg = host[index].ssd = 0;
 
-  if ( host[index].jitter > host[index].jworst ) {
-    host[index].jworst = host[index].jitter;
-  }
+        host[index].jitter = host[index].jworst = host[index].jinta = 0;
+    }
 
-  host[index].returned++;
-  oldavg = host[index].avg;
-  host[index].avg += (totusec - oldavg +.0) / host[index].returned;
-  host[index].ssd += (totusec - oldavg +.0) * (totusec - host[index].avg);
+    if (totusec < host[index].best) {
+        host[index].best = totusec;
+    }
+    if (totusec > host[index].worst) {
+        host[index].worst = totusec;
+    }
 
-  oldjavg = host[index].javg;
-  host[index].javg += (host[index].jitter - oldjavg) / host[index].returned;
-  /* below algorithm is from rfc1889, A.8 */
-  host[index].jinta += host[index].jitter - ((host[index].jinta + 8) >> 4);
+    if (host[index].jitter > host[index].jworst) {
+        host[index].jworst = host[index].jitter;
+    }
 
-  if ( host[index].returned > 1 ) {
-    host[index].gmean = pow( (double) host[index].gmean, (host[index].returned-1.0)/host[index].returned )
-                          * pow( (double) totusec, 1.0/host[index].returned );
-  }
+    host[index].returned++;
+    oldavg = host[index].avg;
+    host[index].avg += (totusec - oldavg + .0) / host[index].returned;
+    host[index].ssd +=
+        (totusec - oldavg + .0) * (totusec - host[index].avg);
+
+    oldjavg = host[index].javg;
+    host[index].javg +=
+        (host[index].jitter - oldjavg) / host[index].returned;
+    /* below algorithm is from rfc1889, A.8 */
+    host[index].jinta +=
+        host[index].jitter - ((host[index].jinta + 8) >> 4);
+
+    if (host[index].returned > 1) {
+        host[index].gmean =
+            pow((double) host[index].gmean,
+                (host[index].returned - 1.0) / host[index].returned)
+            * pow((double) totusec, 1.0 / host[index].returned);
+    }
 
-  host[index].sent = 0;
-  host[index].up = 1;
-  host[index].transit = 0;
+    host[index].sent = 0;
+    host[index].up = 1;
+    host[index].transit = 0;
 
-  net_save_return(index, sequence[seq].saved_seq, totusec);
-  display_rawping(ctl, index, totusec, seq);
+    net_save_return(index, sequence[seq].saved_seq, totusec);
+    display_rawping(ctl, index, totusec, seq);
 }
 
 /*
     Invoked when the read pipe from the mtr-packet subprocess is readable.
     If we have received a complete reply, process it.
 */
-void net_process_return(struct mtr_ctl *ctl)
+void net_process_return(
+    struct mtr_ctl *ctl)
 {
-  handle_command_replies(ctl, &packet_command_pipe, net_process_ping);
+    handle_command_replies(ctl, &packet_command_pipe, net_process_ping);
 }
 
 
-ip_t *net_addr(int at)
+ip_t *net_addr(
+    int at)
 {
-  return (ip_t *)&(host[at].addr);
+    return (ip_t *) & (host[at].addr);
 }
 
 
-ip_t *net_addrs(int at, int i)
+ip_t *net_addrs(
+    int at,
+    int i)
 {
-  return (ip_t *)&(host[at].addrs[i]);
+    return (ip_t *) & (host[at].addrs[i]);
 }
 
-void *net_mpls(int at)
+void *net_mpls(
+    int at)
 {
-  return (struct mplslen *)&(host[at].mplss);
+    return (struct mplslen *) &(host[at].mplss);
 }
 
-void *net_mplss(int at, int i)
+void *net_mplss(
+    int at,
+    int i)
 {
-  return (struct mplslen *)&(host[at].mplss[i]);
+    return (struct mplslen *) &(host[at].mplss[i]);
 }
 
-int net_loss(int at)
+int net_loss(
+    int at)
 {
-  if ( (host[at].xmit - host[at].transit) == 0 ) {
-    return 0;
-  }
+    if ((host[at].xmit - host[at].transit) == 0) {
+        return 0;
+    }
 
-  /* times extra 1000 */
-  return 1000*(100 - (100.0 * host[at].returned / (host[at].xmit - host[at].transit)) );
+    /* times extra 1000 */
+    return 1000 * (100 -
+                   (100.0 * host[at].returned /
+                    (host[at].xmit - host[at].transit)));
 }
 
 
-int net_drop(int at)
+int net_drop(
+    int at)
 {
-  return (host[at].xmit - host[at].transit) - host[at].returned;
+    return (host[at].xmit - host[at].transit) - host[at].returned;
 }
 
 
-int net_last(int at)
+int net_last(
+    int at)
 {
-  return (host[at].last);
+    return (host[at].last);
 }
 
 
-int net_best(int at)
+int net_best(
+    int at)
 {
-  return (host[at].best);
+    return (host[at].best);
 }
 
 
-int net_worst(int at)
+int net_worst(
+    int at)
 {
-  return (host[at].worst);
+    return (host[at].worst);
 }
 
 
-int net_avg(int at)
+int net_avg(
+    int at)
 {
-  return (host[at].avg);
+    return (host[at].avg);
 }
 
 
-int net_gmean(int at)
+int net_gmean(
+    int at)
 {
-  return (host[at].gmean);
+    return (host[at].gmean);
 }
 
 
-int net_stdev(int at)
+int net_stdev(
+    int at)
 {
-  if ( host[at].returned > 1 ) {
-    return ( sqrt( host[at].ssd/(host[at].returned -1.0) ) );
-  } else {
-    return( 0 );
-  }
+    if (host[at].returned > 1) {
+        return (sqrt(host[at].ssd / (host[at].returned - 1.0)));
+    } else {
+        return (0);
+    }
 }
 
 
-int net_jitter(int at)
-{ 
-  return (host[at].jitter); 
+int net_jitter(
+    int at)
+{
+    return (host[at].jitter);
 }
 
 
-int net_jworst(int at)
-{ 
-  return (host[at].jworst); 
+int net_jworst(
+    int at)
+{
+    return (host[at].jworst);
 }
 
 
-int net_javg(int at)
-{ 
-  return (host[at].javg); 
+int net_javg(
+    int at)
+{
+    return (host[at].javg);
 }
 
 
-int net_jinta(int at)
-{ 
-  return (host[at].jinta); 
+int net_jinta(
+    int at)
+{
+    return (host[at].jinta);
 }
 
 
-int net_max(struct mtr_ctl *ctl)
+int net_max(
+    struct mtr_ctl *ctl)
 {
-  int at;
-  int max;
+    int at;
+    int max;
 
-  max = 0;
-  for(at = 0; at < ctl->maxTTL-1; at++) {
-    if ( addrcmp( (void *) &(host[at].addr),
-                  (void *) remoteaddress, ctl->af ) == 0 ) {
-      return at + 1;
-    } else if ( addrcmp( (void *) &(host[at].addr),
-                         (void *) &ctl->unspec_addr, ctl->af ) != 0 ) {
-      max = at + 2;
+    max = 0;
+    for (at = 0; at < ctl->maxTTL - 1; at++) {
+        if (addrcmp((void *) &(host[at].addr),
+                    (void *) remoteaddress, ctl->af) == 0) {
+            return at + 1;
+        } else if (addrcmp((void *) &(host[at].addr),
+                           (void *) &ctl->unspec_addr, ctl->af) != 0) {
+            max = at + 2;
+        }
     }
-  }
 
-  return max;
+    return max;
 }
 
 
-int net_min (struct mtr_ctl *ctl)
+int net_min(
+    struct mtr_ctl *ctl)
 {
-  return ( ctl->fstTTL - 1 );
+    return (ctl->fstTTL - 1);
 }
 
 
-int net_returned(int at)
-{ 
-  return host[at].returned;
-}
-
-
-int net_xmit(int at)
-{ 
-  return host[at].xmit;
+int net_returned(
+    int at)
+{
+    return host[at].returned;
 }
 
 
-int net_up(int at)
+int net_xmit(
+    int at)
 {
-   return host[at].up;
+    return host[at].xmit;
 }
 
 
-char * net_localaddr (void)
+int net_up(
+    int at)
 {
-  return localaddr;
+    return host[at].up;
 }
 
 
-void net_end_transit(void)
+char *net_localaddr(
+    void)
 {
-  int at;
-  
-  for(at = 0; at < MaxHost; at++) {
-    host[at].transit = 0;
-  }
+    return localaddr;
 }
 
-int net_send_batch(struct mtr_ctl *ctl)
+
+void net_end_transit(
+    void)
 {
-  int n_unknown=0, i;
+    int at;
 
-  /* randomized packet size and/or bit pattern if packetsize<0 and/or 
-     bitpattern<0.  abs(packetsize) and/or abs(bitpattern) will be used 
-  */
-  if( batch_at < ctl->fstTTL ) {
-    if( ctl->cpacketsize < 0 ) {
-      /* Someone used a formula here that tried to correct for the 
-         "end-error" in "rand()". By "end-error" I mean that if you 
-         have a range for "rand()" that runs to 32768, and the 
-         destination range is 10000, you end up with 4 out of 32768 
-         0-2768's and only 3 out of 32768 for results 2769 .. 9999. 
-         As our detination range (in the example 10000) is much 
-         smaller (reasonable packet sizes), and our rand() range much 
-         larger, this effect is insignificant. Oh! That other formula
-         didn't work. */
-      packetsize = MINPACKET + rand () % (- ctl->cpacketsize - MINPACKET);
-    } else {
-      packetsize = ctl->cpacketsize;
+    for (at = 0; at < MaxHost; at++) {
+        host[at].transit = 0;
     }
-    if ( ctl->bitpattern < 0 ) {
-      ctl->bitpattern = - (int)(256 + 255*(rand()/(RAND_MAX+0.1)));
-    }
-  }
-
-  net_send_query(ctl, batch_at, abs(packetsize));
+}
 
-  for (i=ctl->fstTTL-1;i<batch_at;i++) {
-    if ( addrcmp( (void *) &(host[i].addr), (void *) &ctl->unspec_addr, ctl->af ) == 0 )
-      n_unknown++;
+int net_send_batch(
+    struct mtr_ctl *ctl)
+{
+    int n_unknown = 0, i;
+
+    /* randomized packet size and/or bit pattern if packetsize<0 and/or 
+       bitpattern<0.  abs(packetsize) and/or abs(bitpattern) will be used 
+     */
+    if (batch_at < ctl->fstTTL) {
+        if (ctl->cpacketsize < 0) {
+            /* Someone used a formula here that tried to correct for the 
+               "end-error" in "rand()". By "end-error" I mean that if you 
+               have a range for "rand()" that runs to 32768, and the 
+               destination range is 10000, you end up with 4 out of 32768 
+               0-2768's and only 3 out of 32768 for results 2769 .. 9999. 
+               As our detination range (in the example 10000) is much 
+               smaller (reasonable packet sizes), and our rand() range much 
+               larger, this effect is insignificant. Oh! That other formula
+               didn't work. */
+            packetsize =
+                MINPACKET + rand() % (-ctl->cpacketsize - MINPACKET);
+        } else {
+            packetsize = ctl->cpacketsize;
+        }
+        if (ctl->bitpattern < 0) {
+            ctl->bitpattern =
+                -(int) (256 + 255 * (rand() / (RAND_MAX + 0.1)));
+        }
+    }
 
-    /* The second condition in the next "if" statement was added in mtr-0.56, 
-       but I don't remember why. It makes mtr stop skipping sections of unknown
-       hosts. Removed in 0.65. 
-       If the line proves necessary, it should at least NOT trigger that line
-       when host[i].addr == 0 */
-    if ( ( addrcmp( (void *) &(host[i].addr),
-                    (void *) remoteaddress, ctl->af ) == 0 ))
-      n_unknown = MaxHost; /* Make sure we drop into "we should restart" */
-  }
+    net_send_query(ctl, batch_at, abs(packetsize));
+
+    for (i = ctl->fstTTL - 1; i < batch_at; i++) {
+        if (addrcmp
+            ((void *) &(host[i].addr), (void *) &ctl->unspec_addr,
+             ctl->af) == 0)
+            n_unknown++;
+
+        /* The second condition in the next "if" statement was added in mtr-0.56, 
+           but I don't remember why. It makes mtr stop skipping sections of unknown
+           hosts. Removed in 0.65. 
+           If the line proves necessary, it should at least NOT trigger that line
+           when host[i].addr == 0 */
+        if ((addrcmp((void *) &(host[i].addr),
+                     (void *) remoteaddress, ctl->af) == 0))
+            n_unknown = MaxHost;        /* Make sure we drop into "we should restart" */
+    }
 
-  if ( /* success in reaching target */
-     ( addrcmp( (void *) &(host[batch_at].addr),
-                (void *) remoteaddress, ctl->af ) == 0 ) ||
-      /* fail in consecutive maxUnknown (firewall?) */
-      (n_unknown > ctl->maxUnknown) ||
-      /* or reach limit  */
-      (batch_at >= ctl->maxTTL-1)) {
-    numhosts = batch_at+1;
-    batch_at = ctl->fstTTL - 1;
-    return 1;
-  }
+    if (                        /* success in reaching target */
+           (addrcmp((void *) &(host[batch_at].addr),
+                    (void *) remoteaddress, ctl->af) == 0) ||
+           /* fail in consecutive maxUnknown (firewall?) */
+           (n_unknown > ctl->maxUnknown) ||
+           /* or reach limit  */
+           (batch_at >= ctl->maxTTL - 1)) {
+        numhosts = batch_at + 1;
+        batch_at = ctl->fstTTL - 1;
+        return 1;
+    }
 
-  batch_at++;
-  return 0;
+    batch_at++;
+    return 0;
 }
 
 
 /*  Ensure the interface address a valid address for our use  */
 static void net_validate_interface_address(
-  int address_family, char *interface_address)
+    int address_family,
+    char *interface_address)
 {
-  if ( inet_pton(address_family, interface_address, sourceaddress) != 1) {
-    error(EXIT_FAILURE, errno, "invalid local address");
-  }
+    if (inet_pton(address_family, interface_address, sourceaddress) != 1) {
+        error(EXIT_FAILURE, errno, "invalid local address");
+    }
 
-  if ( inet_ntop(
-       address_family, sourceaddress, localaddr, sizeof(localaddr)) == NULL) {
-    error(EXIT_FAILURE, errno, "invalid local address");
-  }
+    if (inet_ntop
+        (address_family, sourceaddress, localaddr,
+         sizeof(localaddr)) == NULL) {
+        error(EXIT_FAILURE, errno, "invalid local address");
+    }
 }
 
 
@@ -527,266 +586,296 @@ static void net_validate_interface_address(
   host by connecting a UDP socket and checking the address
   the socket is bound to.
 */
-static void net_find_local_address(void)
-{
-  int udp_socket;
-  int addr_length;
-  struct sockaddr_storage remote_sockaddr;
-  struct sockaddr_in *remote4;
-  struct sockaddr_in6 *remote6;
-
-  udp_socket = socket(remotesockaddr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
-  if ( udp_socket == -1 ) {
-    error(EXIT_FAILURE, errno, "udp socket creation failed");
-  }
-
-  /*
-    We need to set the port to a non-zero value for the connect
-    to succeed.
-  */
-  if ( remotesockaddr->sa_family == AF_INET6 ) {
+static void net_find_local_address(
+    void)
+{
+    int udp_socket;
+    int addr_length;
+    struct sockaddr_storage remote_sockaddr;
+    struct sockaddr_in *remote4;
+    struct sockaddr_in6 *remote6;
+
+    udp_socket =
+        socket(remotesockaddr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
+    if (udp_socket == -1) {
+        error(EXIT_FAILURE, errno, "udp socket creation failed");
+    }
+
+    /*
+       We need to set the port to a non-zero value for the connect
+       to succeed.
+     */
+    if (remotesockaddr->sa_family == AF_INET6) {
 #ifdef ENABLE_IPV6
-    addr_length = sizeof(struct sockaddr_in6);
+        addr_length = sizeof(struct sockaddr_in6);
 
-    memcpy(&remote_sockaddr, rsa6, addr_length);
-    remote6 = (struct sockaddr_in6 *)&remote_sockaddr;
-    remote6->sin6_port = htons(1);
+        memcpy(&remote_sockaddr, rsa6, addr_length);
+        remote6 = (struct sockaddr_in6 *) &remote_sockaddr;
+        remote6->sin6_port = htons(1);
 #endif
-  } else {
-    addr_length = sizeof(struct sockaddr_in);
+    } else {
+        addr_length = sizeof(struct sockaddr_in);
 
-    memcpy(&remote_sockaddr, rsa4, addr_length);
-    remote4 = (struct sockaddr_in *)&remote_sockaddr;
-    remote4->sin_port = htons(1);
-  }
+        memcpy(&remote_sockaddr, rsa4, addr_length);
+        remote4 = (struct sockaddr_in *) &remote_sockaddr;
+        remote4->sin_port = htons(1);
+    }
 
-  if ( connect(udp_socket, (struct sockaddr *)&remote_sockaddr, addr_length) ) {
-    error(EXIT_FAILURE, errno, "udp socket connect failed");
-  }
+    if (connect
+        (udp_socket, (struct sockaddr *) &remote_sockaddr, addr_length)) {
+        error(EXIT_FAILURE, errno, "udp socket connect failed");
+    }
 
-  if ( getsockname(udp_socket, sourcesockaddr, &addr_length) ) {
+    if (getsockname(udp_socket, sourcesockaddr, &addr_length)) {
 
-    error(EXIT_FAILURE, errno, "local address determination failed");
-  }
+        error(EXIT_FAILURE, errno, "local address determination failed");
+    }
 
-  sockaddrtop(sourcesockaddr, localaddr, sizeof(localaddr));
+    sockaddrtop(sourcesockaddr, localaddr, sizeof(localaddr));
 
-  close(udp_socket);
+    close(udp_socket);
 }
 
 
-int net_open(struct mtr_ctl *ctl, struct hostent * hostent)
+int net_open(
+    struct mtr_ctl *ctl,
+    struct hostent *hostent)
 {
-  int err;
+    int err;
 
-  /*  Spawn the mtr-packet child process  */
-  err = open_command_pipe(ctl, &packet_command_pipe);
-  if ( err ) {
-    return err;
-  }
+    /*  Spawn the mtr-packet child process  */
+    err = open_command_pipe(ctl, &packet_command_pipe);
+    if (err) {
+        return err;
+    }
 
-  net_reset(ctl);
+    net_reset(ctl);
 
-  remotesockaddr->sa_family = hostent->h_addrtype;
+    remotesockaddr->sa_family = hostent->h_addrtype;
 
-  switch ( hostent->h_addrtype ) {
-  case AF_INET:
-    addrcpy( (void *) &(rsa4->sin_addr), hostent->h_addr, AF_INET );
-    sourceaddress = (ip_t *) &(ssa4->sin_addr);
-    remoteaddress = (ip_t *) &(rsa4->sin_addr);
-    break;
+    switch (hostent->h_addrtype) {
+    case AF_INET:
+        addrcpy((void *) &(rsa4->sin_addr), hostent->h_addr, AF_INET);
+        sourceaddress = (ip_t *) & (ssa4->sin_addr);
+        remoteaddress = (ip_t *) & (rsa4->sin_addr);
+        break;
 #ifdef ENABLE_IPV6
-  case AF_INET6:
-    addrcpy( (void *) &(rsa6->sin6_addr), hostent->h_addr, AF_INET6 );
-    sourceaddress = (ip_t *) &(ssa6->sin6_addr);
-    remoteaddress = (ip_t *) &(rsa6->sin6_addr);
-    break;
+    case AF_INET6:
+        addrcpy((void *) &(rsa6->sin6_addr), hostent->h_addr, AF_INET6);
+        sourceaddress = (ip_t *) & (ssa6->sin6_addr);
+        remoteaddress = (ip_t *) & (rsa6->sin6_addr);
+        break;
 #endif
-  default:
-    error(EXIT_FAILURE, 0, "net_open bad address type");
-  }
+    default:
+        error(EXIT_FAILURE, 0, "net_open bad address type");
+    }
 
-  if ( ctl->InterfaceAddress ) {
-    net_validate_interface_address(ctl->af, ctl->InterfaceAddress);
-  } else {
-    net_find_local_address();
-  }
+    if (ctl->InterfaceAddress) {
+        net_validate_interface_address(ctl->af, ctl->InterfaceAddress);
+    } else {
+        net_find_local_address();
+    }
 
-  return 0;
+    return 0;
 }
 
 
-void net_reopen(struct mtr_ctl *ctl, struct hostent * addr)
+void net_reopen(
+    struct mtr_ctl *ctl,
+    struct hostent *addr)
 {
-  int at;
+    int at;
 
-  for(at = 0; at < MaxHost; at++) {
-    memset(&host[at], 0, sizeof(host[at]));
-  }
+    for (at = 0; at < MaxHost; at++) {
+        memset(&host[at], 0, sizeof(host[at]));
+    }
 
-  remotesockaddr->sa_family = addr->h_addrtype;
-  addrcpy( (void *) remoteaddress, addr->h_addr, addr->h_addrtype );
+    remotesockaddr->sa_family = addr->h_addrtype;
+    addrcpy((void *) remoteaddress, addr->h_addr, addr->h_addrtype);
 
-  switch ( addr->h_addrtype ) {
-  case AF_INET:
-    addrcpy( (void *) &(rsa4->sin_addr), addr->h_addr, AF_INET );
-    break;
+    switch (addr->h_addrtype) {
+    case AF_INET:
+        addrcpy((void *) &(rsa4->sin_addr), addr->h_addr, AF_INET);
+        break;
 #ifdef ENABLE_IPV6
-  case AF_INET6:
-    addrcpy( (void *) &(rsa6->sin6_addr), addr->h_addr, AF_INET6 );
-    break;
+    case AF_INET6:
+        addrcpy((void *) &(rsa6->sin6_addr), addr->h_addr, AF_INET6);
+        break;
 #endif
-  default:
-    error(EXIT_FAILURE, 0, "net_reopen bad address type");
-  }
+    default:
+        error(EXIT_FAILURE, 0, "net_reopen bad address type");
+    }
 
-  net_reset (ctl);
-  net_send_batch(ctl);
+    net_reset(ctl);
+    net_send_batch(ctl);
 }
 
 
-void net_reset(struct mtr_ctl *ctl)
+void net_reset(
+    struct mtr_ctl *ctl)
 {
-  static struct nethost template = {
-    .saved_seq_offset = 2 - SAVED_PINGS
-  };
+    static struct nethost template = {
+        .saved_seq_offset = 2 - SAVED_PINGS
+    };
 
-  int at, i;
+    int at, i;
 
-  batch_at = ctl->fstTTL - 1;  /* above replacedByMin */
-  numhosts = 10;
+    batch_at = ctl->fstTTL - 1; /* above replacedByMin */
+    numhosts = 10;
 
-  for (i = 0; i < SAVED_PINGS; i++)
-    template.saved[i] = -2;
+    for (i = 0; i < SAVED_PINGS; i++)
+        template.saved[i] = -2;
 
-  for (at = 0; at < MaxHost; at++) {
-    memcpy(&(host[at]), &template, sizeof(template));
-  }
+    for (at = 0; at < MaxHost; at++) {
+        memcpy(&(host[at]), &template, sizeof(template));
+    }
 
-  for (at = 0; at < MaxSequence; at++) {
-    sequence[at].transit = 0;
-  }
+    for (at = 0; at < MaxSequence; at++) {
+        sequence[at].transit = 0;
+    }
 
 }
 
 
 /*  Close the pipe to the packet generator process, and kill the process  */
-void net_close(void)
+void net_close(
+    void)
 {
-  close_command_pipe(&packet_command_pipe);
+    close_command_pipe(&packet_command_pipe);
 }
 
 
-int net_waitfd(void)
+int net_waitfd(
+    void)
 {
-  return packet_command_pipe.read_fd;
+    return packet_command_pipe.read_fd;
 }
 
 
-int* net_saved_pings(int at)
+int *net_saved_pings(
+    int at)
 {
-  return host[at].saved;
+    return host[at].saved;
 }
 
 
-static void net_save_increment(void)
+static void net_save_increment(
+    void)
 {
-  int at;
-  for (at = 0; at < MaxHost; at++) {
-    memmove(host[at].saved, host[at].saved+1, (SAVED_PINGS-1)*sizeof(int));
-    host[at].saved[SAVED_PINGS-1] = -2;
-    host[at].saved_seq_offset += 1;
-  }
+    int at;
+    for (at = 0; at < MaxHost; at++) {
+        memmove(host[at].saved, host[at].saved + 1,
+                (SAVED_PINGS - 1) * sizeof(int));
+        host[at].saved[SAVED_PINGS - 1] = -2;
+        host[at].saved_seq_offset += 1;
+    }
 }
 
 
-void net_save_xmit(int at)
+void net_save_xmit(
+    int at)
 {
-  if ( host[at].saved[SAVED_PINGS-1] != -2 )
-    net_save_increment();
-  host[at].saved[SAVED_PINGS-1] = -1;
+    if (host[at].saved[SAVED_PINGS - 1] != -2)
+        net_save_increment();
+    host[at].saved[SAVED_PINGS - 1] = -1;
 }
 
 
-void net_save_return(int at, int seq, int ms)
+void net_save_return(
+    int at,
+    int seq,
+    int ms)
 {
-  int idx;
-  idx = seq - host[at].saved_seq_offset;
-  if ( (idx < 0) || (idx >= SAVED_PINGS) ) {
-    return;
-  }
-  host[at].saved[idx] = ms;
+    int idx;
+    idx = seq - host[at].saved_seq_offset;
+    if ((idx < 0) || (idx >= SAVED_PINGS)) {
+        return;
+    }
+    host[at].saved[idx] = ms;
 }
 
 /* Similar to inet_ntop but uses a sockaddr as it's argument. */
-static void sockaddrtop( struct sockaddr * saddr, char * strptr, size_t len ) {
-  struct sockaddr_in *  sa4;
+static void sockaddrtop(
+    struct sockaddr *saddr,
+    char *strptr,
+    size_t len)
+{
+    struct sockaddr_in *sa4;
 #ifdef ENABLE_IPV6
-  struct sockaddr_in6 * sa6;
+    struct sockaddr_in6 *sa6;
 #endif
 
-  switch ( saddr->sa_family ) {
-  case AF_INET:
-    sa4 = (struct sockaddr_in *) saddr;
-    xstrncpy( strptr, inet_ntoa( sa4->sin_addr ), len - 1 );
-    strptr[ len - 1 ] = '\0';
-    return;
+    switch (saddr->sa_family) {
+    case AF_INET:
+        sa4 = (struct sockaddr_in *) saddr;
+        xstrncpy(strptr, inet_ntoa(sa4->sin_addr), len - 1);
+        strptr[len - 1] = '\0';
+        return;
 #ifdef ENABLE_IPV6
-  case AF_INET6:
-    sa6 = (struct sockaddr_in6 *) saddr;
-    inet_ntop( sa6->sin6_family, &(sa6->sin6_addr), strptr, len );
-    return;
+    case AF_INET6:
+        sa6 = (struct sockaddr_in6 *) saddr;
+        inet_ntop(sa6->sin6_family, &(sa6->sin6_addr), strptr, len);
+        return;
 #endif
-  default:
-    error(0, 0, "sockaddrtop unknown address type");
-    strptr[0] = '\0';
-    return;
-  }
+    default:
+        error(0, 0, "sockaddrtop unknown address type");
+        strptr[0] = '\0';
+        return;
+    }
 }
 
 
 /* Address comparison. */
-int addrcmp( char * a, char * b, int family ) {
-  int rc = -1;
+int addrcmp(
+    char *a,
+    char *b,
+    int family)
+{
+    int rc = -1;
 
-  switch ( family ) {
-  case AF_INET:
-    rc = memcmp( a, b, sizeof (struct in_addr) );
-    break;
+    switch (family) {
+    case AF_INET:
+        rc = memcmp(a, b, sizeof(struct in_addr));
+        break;
 #ifdef ENABLE_IPV6
-  case AF_INET6:
-    rc = memcmp( a, b, sizeof (struct in6_addr) );
-    break;
+    case AF_INET6:
+        rc = memcmp(a, b, sizeof(struct in6_addr));
+        break;
 #endif
-  }
+    }
 
-  return rc;
+    return rc;
 }
 
 /* Address copy. */
-void addrcpy( char * a, char * b, int family ) {
+void addrcpy(
+    char *a,
+    char *b,
+    int family)
+{
 
-  switch ( family ) {
-  case AF_INET:
-    memcpy( a, b, sizeof (struct in_addr) );
-    break;
+    switch (family) {
+    case AF_INET:
+        memcpy(a, b, sizeof(struct in_addr));
+        break;
 #ifdef ENABLE_IPV6
-  case AF_INET6:
-    memcpy( a, b, sizeof (struct in6_addr) );
-    break;
+    case AF_INET6:
+        memcpy(a, b, sizeof(struct in6_addr));
+        break;
 #endif
-  }
+    }
 }
 
 /* for GTK frontend */
-void net_harvest_fds(struct mtr_ctl *ctl)
+void net_harvest_fds(
+    struct mtr_ctl *ctl)
 {
-  fd_set writefd;
-  int maxfd = 0;
-  struct timeval tv;
+    fd_set writefd;
+    int maxfd = 0;
+    struct timeval tv;
 
-  FD_ZERO(&writefd);
-  tv.tv_sec = 0;
-  tv.tv_usec = 0;
-  select(maxfd, NULL, &writefd, NULL, &tv);
+    FD_ZERO(&writefd);
+    tv.tv_sec = 0;
+    tv.tv_usec = 0;
+    select(maxfd, NULL, &writefd, NULL, &tv);
 }
index e78d19c2398b05bf8c67eb83d7dc60a88dc6d5b9..a37b5aa8094156965c71636d9f35ed9c0e1e7eaf 100644 (file)
--- a/ui/net.h
+++ b/ui/net.h
 
 #include "mtr.h"
 
-extern int net_open(struct mtr_ctl *ctl, struct hostent *host);
-extern void net_reopen(struct mtr_ctl *ctl, struct hostent *address);
-extern void net_reset(struct mtr_ctl *ctl);
-extern void net_close(void);
-extern int net_waitfd(void);
-extern void net_process_return(struct mtr_ctl *ctl);
-extern void net_harvest_fds(struct mtr_ctl *ctl);
+extern int net_open(
+    struct mtr_ctl *ctl,
+    struct hostent *host);
+extern void net_reopen(
+    struct mtr_ctl *ctl,
+    struct hostent *address);
+extern void net_reset(
+    struct mtr_ctl *ctl);
+extern void net_close(
+    void);
+extern int net_waitfd(
+    void);
+extern void net_process_return(
+    struct mtr_ctl *ctl);
+extern void net_harvest_fds(
+    struct mtr_ctl *ctl);
 
-extern int net_max(struct mtr_ctl *ctl);
-extern int net_min(struct mtr_ctl *ctl);
-extern int net_last(int at);
-extern ip_t * net_addr(int at);
-extern void * net_mpls(int at);
-extern void * net_mplss(int, int);
-extern int net_loss(int at);
-extern int net_drop(int at);
-extern int net_best(int at);
-extern int net_worst(int at);
-extern int net_avg(int at);
-extern int net_gmean(int at);
-extern int net_stdev(int at);
-extern int net_jitter(int at);
-extern int net_jworst(int at);
-extern int net_javg(int at);
-extern int net_jinta(int at);
-extern ip_t * net_addrs(int at, int i);
-extern char *net_localaddr(void); 
+extern int net_max(
+    struct mtr_ctl *ctl);
+extern int net_min(
+    struct mtr_ctl *ctl);
+extern int net_last(
+    int at);
+extern ip_t *net_addr(
+    int at);
+extern void *net_mpls(
+    int at);
+extern void *net_mplss(
+    int,
+    int);
+extern int net_loss(
+    int at);
+extern int net_drop(
+    int at);
+extern int net_best(
+    int at);
+extern int net_worst(
+    int at);
+extern int net_avg(
+    int at);
+extern int net_gmean(
+    int at);
+extern int net_stdev(
+    int at);
+extern int net_jitter(
+    int at);
+extern int net_jworst(
+    int at);
+extern int net_javg(
+    int at);
+extern int net_jinta(
+    int at);
+extern ip_t *net_addrs(
+    int at,
+    int i);
+extern char *net_localaddr(
+    void);
 
-extern int net_send_batch(struct mtr_ctl *ctl);
-extern void net_end_transit(void);
+extern int net_send_batch(
+    struct mtr_ctl *ctl);
+extern void net_end_transit(
+    void);
 
-extern int calc_deltatime (float WaitTime);
+extern int calc_deltatime(
+    float WaitTime);
 
-extern int net_returned(int at);
-extern int net_xmit(int at);
+extern int net_returned(
+    int at);
+extern int net_xmit(
+    int at);
 
-extern int net_up(int at);
+extern int net_up(
+    int at);
 
-extern int* net_saved_pings(int at);
-extern void net_save_xmit(int at);
-extern void net_save_return(int at, int seq, int ms);
+extern int *net_saved_pings(
+    int at);
+extern void net_save_xmit(
+    int at);
+extern void net_save_return(
+    int at,
+    int seq,
+    int ms);
 
-extern int addrcmp( char * a, char * b, int af );
-extern void addrcpy( char * a, char * b, int af );
+extern int addrcmp(
+    char *a,
+    char *b,
+    int af);
+extern void addrcpy(
+    char *a,
+    char *b,
+    int af);
 
-extern void net_add_fds(fd_set *writefd, int *maxfd);
+extern void net_add_fds(
+    fd_set * writefd,
+    int *maxfd);
index a745cd72a37d89c91aece4c5f41a2ec4d5541612..c13f00ce794df9dfb645308018983b7947d41edd 100644 (file)
--- a/ui/raw.c
+++ b/ui/raw.c
 
 
 /* Log an echo request, or a "ping" */
-void raw_rawxmit (int host, int seq)
+void raw_rawxmit(
+    int host,
+    int seq)
 {
-  printf ("x %d %d\n", host, seq);
-  fflush (stdout);
+    printf("x %d %d\n", host, seq);
+    fflush(stdout);
 }
 
 /* Log an echo reply, or a "pong" */
-void raw_rawping (struct mtr_ctl *ctl, int host, int msec, int seq)
+void raw_rawping(
+    struct mtr_ctl *ctl,
+    int host,
+    int msec,
+    int seq)
 {
-  static int havename[MaxHost];
-  char *name;
+    static int havename[MaxHost];
+    char *name;
 
-  if (ctl->dns && !havename[host]) {
-    name = dns_lookup2(ctl, net_addr(host));
-    if (name) {
-      havename[host]++;
-      printf ("d %d %s\n", host, name);
+    if (ctl->dns && !havename[host]) {
+        name = dns_lookup2(ctl, net_addr(host));
+        if (name) {
+            havename[host]++;
+            printf("d %d %s\n", host, name);
+        }
     }
-  }
-  printf ("p %d %d %d\n", host, msec, seq);
-  fflush (stdout); 
+    printf("p %d %d %d\n", host, msec, seq);
+    fflush(stdout);
 }
 
 
-void raw_rawhost (struct mtr_ctl *ctl, int host, ip_t * ip_addr)
+void raw_rawhost(
+    struct mtr_ctl *ctl,
+    int host,
+    ip_t * ip_addr)
 {
-  printf ("h %d %s\n", host, strlongip(ctl, ip_addr));
-  fflush (stdout); 
+    printf("h %d %s\n", host, strlongip(ctl, ip_addr));
+    fflush(stdout);
 }
index b8a9d358f5dad2689e1e51c394fde43f84788986..c79d8bb85ae4fca811b8505a2abcc41931462377 100644 (file)
--- a/ui/raw.h
+++ b/ui/raw.h
 */
 
 /*  Prototypes for raw.c  */
-extern void raw_rawxmit(int host, int seq);
-extern void raw_rawping(struct mtr_ctl *ctl, int host, int msec, int seq);
-extern void raw_rawhost(struct mtr_ctl *ctl, int host, ip_t * addr);
+extern void raw_rawxmit(
+    int host,
+    int seq);
+extern void raw_rawping(
+    struct mtr_ctl *ctl,
+    int host,
+    int msec,
+    int seq);
+extern void raw_rawhost(
+    struct mtr_ctl *ctl,
+    int host,
+    ip_t * addr);
index 2e8ba2201468e99f3fa40436c10e212e865dfb07..29d7bd6d8d49854c4e25d4d8303b3e99f6eebb98 100644 (file)
 #define MAX_FORMAT_STR 81
 
 
-void report_open(void)
+void report_open(
+    void)
 {
-  const time_t now = time(NULL);
-  const char *t = iso_time (&now);
+    const time_t now = time(NULL);
+    const char *t = iso_time(&now);
 
-  printf ("Start: %s\n", t);
+    printf("Start: %s\n", t);
 }
 
-static size_t snprint_addr(struct mtr_ctl *ctl, char *dst, size_t dst_len, ip_t *addr)
+static size_t snprint_addr(
+    struct mtr_ctl *ctl,
+    char *dst,
+    size_t dst_len,
+    ip_t * addr)
 {
-  if(addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
-    struct hostent *host = ctl->dns ? addr2host((void *) addr, ctl->af) : NULL;
-    if (!host) return snprintf(dst, dst_len, "%s", strlongip(ctl, addr));
-    else if (ctl->dns && ctl->show_ips)
-      return snprintf(dst, dst_len, "%s (%s)", host->h_name, strlongip(ctl, addr));
-    else return snprintf(dst, dst_len, "%s", host->h_name);
-  } else return snprintf(dst, dst_len, "%s", "???");
+    if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
+        struct hostent *host =
+            ctl->dns ? addr2host((void *) addr, ctl->af) : NULL;
+        if (!host)
+            return snprintf(dst, dst_len, "%s", strlongip(ctl, addr));
+        else if (ctl->dns && ctl->show_ips)
+            return snprintf(dst, dst_len, "%s (%s)", host->h_name,
+                            strlongip(ctl, addr));
+        else
+            return snprintf(dst, dst_len, "%s", host->h_name);
+    } else
+        return snprintf(dst, dst_len, "%s", "???");
 }
 
 
 #ifdef HAVE_IPINFO
-static void print_mpls(struct mplslen *mpls) {
-  int k;
-  for (k=0; k < mpls->labels; k++)
-    printf("       [MPLS: Lbl %lu Exp %u S %cu TTL %u]\n", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
+static void print_mpls(
+    struct mplslen *mpls)
+{
+    int k;
+    for (k = 0; k < mpls->labels; k++)
+        printf("       [MPLS: Lbl %lu Exp %u S %cu TTL %u]\n",
+               mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
 }
 #endif
 
-void report_close(struct mtr_ctl *ctl)
+void report_close(
+    struct mtr_ctl *ctl)
 {
-  int i, j, at, max, z, w;
-  struct mplslen *mpls, *mplss;
-  ip_t *addr;
-  ip_t *addr2 = NULL;  
-  char name[MAX_FORMAT_STR];
-  char buf[1024];
-  char fmt[16];
-  size_t len=0;
-  size_t len_hosts = 33;
+    int i, j, at, max, z, w;
+    struct mplslen *mpls, *mplss;
+    ip_t *addr;
+    ip_t *addr2 = NULL;
+    char name[MAX_FORMAT_STR];
+    char buf[1024];
+    char fmt[16];
+    size_t len = 0;
+    size_t len_hosts = 33;
 #ifdef HAVE_IPINFO
-  int len_tmp;
-  const size_t iiwidth_len = get_iiwidth_len();
+    int len_tmp;
+    const size_t iiwidth_len = get_iiwidth_len();
 #endif
 
-  if (ctl->reportwide)
-  {
-    /* get the longest hostname */
-    len_hosts = strlen(ctl->LocalHostname);
-    max = net_max(ctl);
-    at  = net_min(ctl);
-    for (; at < max; at++) {
-      size_t nlen;
-      addr = net_addr(at);
-      if ((nlen = snprint_addr(ctl, name, sizeof(name), addr)))
-        if (len_hosts < nlen)
-          len_hosts = nlen;
+    if (ctl->reportwide) {
+        /* get the longest hostname */
+        len_hosts = strlen(ctl->LocalHostname);
+        max = net_max(ctl);
+        at = net_min(ctl);
+        for (; at < max; at++) {
+            size_t nlen;
+            addr = net_addr(at);
+            if ((nlen = snprint_addr(ctl, name, sizeof(name), addr)))
+                if (len_hosts < nlen)
+                    len_hosts = nlen;
+        }
     }
-  }
-  
 #ifdef HAVE_IPINFO
-  len_tmp = len_hosts;
-  if (ctl->ipinfo_no >= 0 && iiwidth_len) {
-    ctl->ipinfo_no %= iiwidth_len;
-    if (ctl->reportwide) {
-      len_hosts++;    /* space */
-      len_tmp   += get_iiwidth(ctl->ipinfo_no);
-      if (!ctl->ipinfo_no)
-        len_tmp += 2; /* align header: AS */
+    len_tmp = len_hosts;
+    if (ctl->ipinfo_no >= 0 && iiwidth_len) {
+        ctl->ipinfo_no %= iiwidth_len;
+        if (ctl->reportwide) {
+            len_hosts++;        /* space */
+            len_tmp += get_iiwidth(ctl->ipinfo_no);
+            if (!ctl->ipinfo_no)
+                len_tmp += 2;   /* align header: AS */
+        }
     }
-  }
-  snprintf( fmt, sizeof(fmt), "HOST: %%-%ds", len_tmp);
+    snprintf(fmt, sizeof(fmt), "HOST: %%-%ds", len_tmp);
 #else
-  snprintf( fmt, sizeof(fmt), "HOST: %%-%zus", len_hosts);
+    snprintf(fmt, sizeof(fmt), "HOST: %%-%zus", len_hosts);
 #endif
-  snprintf(buf, sizeof(buf), fmt, ctl->LocalHostname);
-  len = ctl->reportwide ? strlen(buf) : len_hosts;
-  for( i=0; i<MAXFLD; i++ ) {
-    j = ctl->fld_index[ctl->fld_active[i]];
-    if (j < 0) continue;
-
-    snprintf( fmt, sizeof(fmt), "%%%ds", data_fields[j].length );
-    snprintf( buf + len, sizeof(buf), fmt, data_fields[j].title );
-    len +=  data_fields[j].length;
-  }
-  printf("%s\n",buf);
-
-  max = net_max(ctl);
-  at  = net_min(ctl);
-  for(; at < max; at++) {
-    addr = net_addr(at);
-    mpls = net_mpls(at);
-    snprint_addr(ctl, name, sizeof(name), addr);
+    snprintf(buf, sizeof(buf), fmt, ctl->LocalHostname);
+    len = ctl->reportwide ? strlen(buf) : len_hosts;
+    for (i = 0; i < MAXFLD; i++) {
+        j = ctl->fld_index[ctl->fld_active[i]];
+        if (j < 0)
+            continue;
+
+        snprintf(fmt, sizeof(fmt), "%%%ds", data_fields[j].length);
+        snprintf(buf + len, sizeof(buf), fmt, data_fields[j].title);
+        len += data_fields[j].length;
+    }
+    printf("%s\n", buf);
+
+    max = net_max(ctl);
+    at = net_min(ctl);
+    for (; at < max; at++) {
+        addr = net_addr(at);
+        mpls = net_mpls(at);
+        snprint_addr(ctl, name, sizeof(name), addr);
 
 #ifdef HAVE_IPINFO
-    if (is_printii(ctl)) {
-      snprintf(fmt, sizeof(fmt), " %%2d. %%s%%-%zus", len_hosts);
-      snprintf(buf, sizeof(buf), fmt, at+1, fmt_ipinfo(ctl, addr), name);
-    } else {
+        if (is_printii(ctl)) {
+            snprintf(fmt, sizeof(fmt), " %%2d. %%s%%-%zus", len_hosts);
+            snprintf(buf, sizeof(buf), fmt, at + 1, fmt_ipinfo(ctl, addr),
+                     name);
+        } else {
 #endif
-    snprintf( fmt, sizeof(fmt), " %%2d.|-- %%-%zus", len_hosts);
-    snprintf(buf, sizeof(buf), fmt, at+1, name);
+            snprintf(fmt, sizeof(fmt), " %%2d.|-- %%-%zus", len_hosts);
+            snprintf(buf, sizeof(buf), fmt, at + 1, name);
 #ifdef HAVE_IPINFO
-    }
+        }
 #endif
-    len = ctl->reportwide ? strlen(buf) : len_hosts;  
-    for( i=0; i<MAXFLD; i++ ) {
-      j = ctl->fld_index[ctl->fld_active [i]];
-      if (j < 0) continue;
-
-      /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
-      if( strchr( data_fields[j].format, 'f' ) ) {
-        snprintf( buf + len, sizeof(buf), data_fields[j].format,
-               data_fields[j].net_xxx(at) /1000.0 );
-      } else {
-        snprintf( buf + len, sizeof(buf), data_fields[j].format,
-               data_fields[j].net_xxx(at) );
-      }
-      len +=  data_fields[j].length;
-    }
-    printf("%s\n",buf);
-
-    /* This feature shows 'loadbalances' on routes */
-
-    /* z is starting at 1 because addrs[0] is the same that addr */
-    for (z = 1; z < MAXPATH ; z++) {
-      int found = 0;
-      addr2 = net_addrs(at, z);
-      mplss = net_mplss(at, z);
-      if ((addrcmp ((void *) &ctl->unspec_addr, (void *) addr2, ctl->af)) == 0)
-        break;
-      for (w = 0; w < z; w++)
-        /* Ok... checking if there are ips repeated on same hop */
-        if ((addrcmp ((void *) addr2, (void *) net_addrs (at,w), ctl->af)) == 0) {
-           found = 1;
-           break;
-        }   
-
-      if (!found) {
-  
+        len = ctl->reportwide ? strlen(buf) : len_hosts;
+        for (i = 0; i < MAXFLD; i++) {
+            j = ctl->fld_index[ctl->fld_active[i]];
+            if (j < 0)
+                continue;
+
+            /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
+            if (strchr(data_fields[j].format, 'f')) {
+                snprintf(buf + len, sizeof(buf), data_fields[j].format,
+                         data_fields[j].net_xxx(at) / 1000.0);
+            } else {
+                snprintf(buf + len, sizeof(buf), data_fields[j].format,
+                         data_fields[j].net_xxx(at));
+            }
+            len += data_fields[j].length;
+        }
+        printf("%s\n", buf);
+
+        /* This feature shows 'loadbalances' on routes */
+
+        /* z is starting at 1 because addrs[0] is the same that addr */
+        for (z = 1; z < MAXPATH; z++) {
+            int found = 0;
+            addr2 = net_addrs(at, z);
+            mplss = net_mplss(at, z);
+            if ((addrcmp
+                 ((void *) &ctl->unspec_addr, (void *) addr2,
+                  ctl->af)) == 0)
+                break;
+            for (w = 0; w < z; w++)
+                /* Ok... checking if there are ips repeated on same hop */
+                if ((addrcmp
+                     ((void *) addr2, (void *) net_addrs(at, w),
+                      ctl->af)) == 0) {
+                    found = 1;
+                    break;
+                }
+
+            if (!found) {
+
+#ifdef HAVE_IPINFO
+                if (is_printii(ctl)) {
+                    if (mpls->labels && z == 1 && ctl->enablempls)
+                        print_mpls(mpls);
+                    snprint_addr(ctl, name, sizeof(name), addr2);
+                    printf("     %s%s\n", fmt_ipinfo(ctl, addr2), name);
+                    if (ctl->enablempls)
+                        print_mpls(mplss);
+                }
+#else
+                int k;
+                if (mpls->labels && z == 1 && ctl->enablempls) {
+                    for (k = 0; k < mpls->labels; k++) {
+                        printf
+                            ("    |  |+-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n",
+                             mpls->label[k], mpls->exp[k], mpls->s[k],
+                             mpls->ttl[k]);
+                    }
+                }
+
+                if (z == 1) {
+                    printf("    |  `|-- %s\n", strlongip(ctl, addr2));
+                    for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
+                        printf
+                            ("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n",
+                             mplss->label[k], mplss->exp[k], mplss->s[k],
+                             mplss->ttl[k]);
+                    }
+                } else {
+                    printf("    |   |-- %s\n", strlongip(ctl, addr2));
+                    for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
+                        printf
+                            ("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n",
+                             mplss->label[k], mplss->exp[k], mplss->s[k],
+                             mplss->ttl[k]);
+                    }
+                }
+#endif
+            }
+        }
+
+        /* No multipath */
 #ifdef HAVE_IPINFO
         if (is_printii(ctl)) {
-          if (mpls->labels && z == 1 && ctl->enablempls)
-            print_mpls(mpls);
-          snprint_addr(ctl, name, sizeof(name), addr2);
-          printf("     %s%s\n", fmt_ipinfo(ctl, addr2), name);
-          if (ctl->enablempls)
-            print_mpls(mplss);
+            if (mpls->labels && z == 1 && ctl->enablempls)
+                print_mpls(mpls);
         }
 #else
-        int k;
         if (mpls->labels && z == 1 && ctl->enablempls) {
-          for (k=0; k < mpls->labels; k++) {
-            printf("    |  |+-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
-          }
-        }
-
-        if (z == 1) {
-          printf ("    |  `|-- %s\n", strlongip(ctl, addr2));
-          for (k=0; k < mplss->labels && ctl->enablempls; k++) {
-            printf("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n", mplss->label[k], mplss->exp[k], mplss->s[k], mplss->ttl[k]);
-          }
-        } else {
-          printf ("    |   |-- %s\n", strlongip(ctl, addr2));
-          for (k=0; k < mplss->labels && ctl->enablempls; k++) {
-            printf("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n", mplss->label[k], mplss->exp[k], mplss->s[k], mplss->ttl[k]);
-          }
+            int k;
+            for (k = 0; k < mpls->labels; k++) {
+                printf("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n",
+                       mpls->label[k], mpls->exp[k], mpls->s[k],
+                       mpls->ttl[k]);
+            }
         }
 #endif
-      }
-    }
-
-    /* No multipath */
-#ifdef HAVE_IPINFO
-    if (is_printii(ctl)) {
-      if (mpls->labels && z == 1 && ctl->enablempls)
-        print_mpls(mpls);
-    }
-#else
-    if(mpls->labels && z == 1 && ctl->enablempls) {
-      int k;
-      for (k=0; k < mpls->labels; k++) {
-        printf("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
-      }
     }
-#endif
-  }
 }
 
 
-void txt_open(void)
+void txt_open(
+    void)
 {
 }
 
 
-void txt_close(struct mtr_ctl *ctl)
+void txt_close(
+    struct mtr_ctl *ctl)
 {
-  report_close(ctl);
+    report_close(ctl);
 }
 
 
-void json_open(void)
+void json_open(
+    void)
 {
 }
 
 
-void json_close(struct mtr_ctl *ctl)
+void json_close(
+    struct mtr_ctl *ctl)
 {
-  int i, j, at, first, max;
-  ip_t *addr;
-  char name[MAX_FORMAT_STR];
-
-  printf("{\n");
-  printf("  \"report\": {\n");
-  printf("    \"mtr\": {\n");
-  printf("      \"src\": \"%s\",\n", ctl->LocalHostname);
-  printf("      \"dst\": \"%s\",\n", ctl->Hostname);
-  printf("      \"tos\": \"0x%X\",\n", ctl->tos);
-  if(ctl->cpacketsize >= 0) {
-    printf("      \"psize\": \"%d\",\n", ctl->cpacketsize);
-  } else {
-    printf("      \"psize\": \"rand(%d-%d)\",\n", MINPACKET, -ctl->cpacketsize);
-  }
-  if (ctl->bitpattern >= 0) {
-    printf("      \"bitpattern\": \"0x%02X\",\n", (unsigned char)(ctl->bitpattern));
-  } else {
-    printf("      \"bitpattern\": \"rand(0x00-FF)\",\n");
-  }
-  printf("      \"tests\": \"%d\"\n", ctl->MaxPing);
-  printf("    },\n");
-
-  printf("    \"hubs\": [");
-
-  max = net_max(ctl);
-  at = first = net_min(ctl);
-  for(; at < max; at++) {
-    addr = net_addr(at);
-    snprint_addr(ctl, name, sizeof(name), addr);
-
-    if(at == first) {
-      printf("{\n");
+    int i, j, at, first, max;
+    ip_t *addr;
+    char name[MAX_FORMAT_STR];
+
+    printf("{\n");
+    printf("  \"report\": {\n");
+    printf("    \"mtr\": {\n");
+    printf("      \"src\": \"%s\",\n", ctl->LocalHostname);
+    printf("      \"dst\": \"%s\",\n", ctl->Hostname);
+    printf("      \"tos\": \"0x%X\",\n", ctl->tos);
+    if (ctl->cpacketsize >= 0) {
+        printf("      \"psize\": \"%d\",\n", ctl->cpacketsize);
+    } else {
+        printf("      \"psize\": \"rand(%d-%d)\",\n", MINPACKET,
+               -ctl->cpacketsize);
+    }
+    if (ctl->bitpattern >= 0) {
+        printf("      \"bitpattern\": \"0x%02X\",\n",
+               (unsigned char) (ctl->bitpattern));
     } else {
-      printf("    {\n");
+        printf("      \"bitpattern\": \"rand(0x00-FF)\",\n");
     }
-    printf("      \"count\": \"%d\",\n", at+1);
-    printf("      \"host\": \"%s\",\n", name);
-    for( i=0; i<MAXFLD; i++ ) {
-      const char *format;
+    printf("      \"tests\": \"%d\"\n", ctl->MaxPing);
+    printf("    },\n");
 
-      j = ctl->fld_index[ctl->fld_active[i]];
+    printf("    \"hubs\": [");
 
-      /* Commas */
-      if(i + 1 == MAXFLD) {
-        printf("\n");
-      } else if (j > 0 && i != 0) {
-        printf(",\n");
-      }
-
-      if (j <= 0) continue; /* Field nr 0, " " shouldn't be printed in this method. */
-
-      /* Format value */
-      format = data_fields[j].format;
-      if( strchr(format, 'f') ) {
-        format = "%.2f";
-      } else {
-        format = "%d";
-      }
-
-      /* Format json line */
-      snprintf(name, sizeof(name), "%s%s", "      \"%s\": ", format);
-
-      /* Output json line */
-      if(strchr(data_fields[j].format, 'f')) {
-        /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
-        printf(name,
-               data_fields[j].title,
-               data_fields[j].net_xxx(at) / 1000.0);
-      } else {
-        printf(name,
-               data_fields[j].title,
-               data_fields[j].net_xxx(at));
-      }
-    }
-    if(at+1 == max) {
-      printf("    }]\n");
-    } else {
-      printf("    },\n");
+    max = net_max(ctl);
+    at = first = net_min(ctl);
+    for (; at < max; at++) {
+        addr = net_addr(at);
+        snprint_addr(ctl, name, sizeof(name), addr);
+
+        if (at == first) {
+            printf("{\n");
+        } else {
+            printf("    {\n");
+        }
+        printf("      \"count\": \"%d\",\n", at + 1);
+        printf("      \"host\": \"%s\",\n", name);
+        for (i = 0; i < MAXFLD; i++) {
+            const char *format;
+
+            j = ctl->fld_index[ctl->fld_active[i]];
+
+            /* Commas */
+            if (i + 1 == MAXFLD) {
+                printf("\n");
+            } else if (j > 0 && i != 0) {
+                printf(",\n");
+            }
+
+            if (j <= 0)
+                continue;       /* Field nr 0, " " shouldn't be printed in this method. */
+
+            /* Format value */
+            format = data_fields[j].format;
+            if (strchr(format, 'f')) {
+                format = "%.2f";
+            } else {
+                format = "%d";
+            }
+
+            /* Format json line */
+            snprintf(name, sizeof(name), "%s%s", "      \"%s\": ", format);
+
+            /* Output json line */
+            if (strchr(data_fields[j].format, 'f')) {
+                /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
+                printf(name,
+                       data_fields[j].title,
+                       data_fields[j].net_xxx(at) / 1000.0);
+            } else {
+                printf(name,
+                       data_fields[j].title, data_fields[j].net_xxx(at));
+            }
+        }
+        if (at + 1 == max) {
+            printf("    }]\n");
+        } else {
+            printf("    },\n");
+        }
     }
-  }
-  printf("  }\n");
-  printf("}\n");
+    printf("  }\n");
+    printf("}\n");
 }
 
 
 
-void xml_open(void)
+void xml_open(
+    void)
 {
 }
 
 
-void xml_close(struct mtr_ctl *ctl)
+void xml_close(
+    struct mtr_ctl *ctl)
 {
-  int i, j, at, max;
-  ip_t *addr;
-  char name[MAX_FORMAT_STR];
-
-  printf("<?xml version=\"1.0\"?>\n");
-  printf("<MTR SRC=\"%s\" DST=\"%s\"", ctl->LocalHostname, ctl->Hostname);
-  printf(" TOS=\"0x%X\"", ctl->tos);
-  if(ctl->cpacketsize >= 0) {
-    printf(" PSIZE=\"%d\"", ctl->cpacketsize);
-  } else {
-    printf(" PSIZE=\"rand(%d-%d)\"",MINPACKET, -ctl->cpacketsize);
-  }
-  if (ctl->bitpattern >= 0) {
-    printf(" BITPATTERN=\"0x%02X\"", (unsigned char)(ctl->bitpattern));
-  } else {
-    printf(" BITPATTERN=\"rand(0x00-FF)\"");
-  }
-  printf(" TESTS=\"%d\">\n", ctl->MaxPing);
-
-  max = net_max(ctl);
-  at  = net_min(ctl);
-  for(; at < max; at++) {
-    addr = net_addr(at);
-    snprint_addr(ctl, name, sizeof(name), addr);
-
-    printf("    <HUB COUNT=\"%d\" HOST=\"%s\">\n", at+1, name);
-    for( i=0; i<MAXFLD; i++ ) {
-      const char *title;
-
-      j = ctl->fld_index[ctl->fld_active[i]];
-      if (j <= 0) continue; /* Field nr 0, " " shouldn't be printed in this method. */
-
-      snprintf(name, sizeof(name), "%s%s%s", "        <%s>", data_fields[j].format, "</%s>\n");
-
-      /* XML doesn't allow "%" in tag names, rename Loss% to just Loss */
-      title = data_fields[j].title;
-      if( strcmp(data_fields[j].title, "Loss%") == 0 ) {
-               title = "Loss";
-      }
-
-      /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
-      if( strchr( data_fields[j].format, 'f' ) ) {
-       printf( name,
-               title,
-               data_fields[j].net_xxx(at) /1000.0,
-               title );
-      } else {
-       printf( name,
-               title,
-               data_fields[j].net_xxx(at),
-               title );
-      }
+    int i, j, at, max;
+    ip_t *addr;
+    char name[MAX_FORMAT_STR];
+
+    printf("<?xml version=\"1.0\"?>\n");
+    printf("<MTR SRC=\"%s\" DST=\"%s\"", ctl->LocalHostname,
+           ctl->Hostname);
+    printf(" TOS=\"0x%X\"", ctl->tos);
+    if (ctl->cpacketsize >= 0) {
+        printf(" PSIZE=\"%d\"", ctl->cpacketsize);
+    } else {
+        printf(" PSIZE=\"rand(%d-%d)\"", MINPACKET, -ctl->cpacketsize);
+    }
+    if (ctl->bitpattern >= 0) {
+        printf(" BITPATTERN=\"0x%02X\"",
+               (unsigned char) (ctl->bitpattern));
+    } else {
+        printf(" BITPATTERN=\"rand(0x00-FF)\"");
     }
-    printf("    </HUB>\n");
-  }
-  printf("</MTR>\n");
+    printf(" TESTS=\"%d\">\n", ctl->MaxPing);
+
+    max = net_max(ctl);
+    at = net_min(ctl);
+    for (; at < max; at++) {
+        addr = net_addr(at);
+        snprint_addr(ctl, name, sizeof(name), addr);
+
+        printf("    <HUB COUNT=\"%d\" HOST=\"%s\">\n", at + 1, name);
+        for (i = 0; i < MAXFLD; i++) {
+            const char *title;
+
+            j = ctl->fld_index[ctl->fld_active[i]];
+            if (j <= 0)
+                continue;       /* Field nr 0, " " shouldn't be printed in this method. */
+
+            snprintf(name, sizeof(name), "%s%s%s", "        <%s>",
+                     data_fields[j].format, "</%s>\n");
+
+            /* XML doesn't allow "%" in tag names, rename Loss% to just Loss */
+            title = data_fields[j].title;
+            if (strcmp(data_fields[j].title, "Loss%") == 0) {
+                title = "Loss";
+            }
+
+            /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
+            if (strchr(data_fields[j].format, 'f')) {
+                printf(name,
+                       title, data_fields[j].net_xxx(at) / 1000.0, title);
+            } else {
+                printf(name, title, data_fields[j].net_xxx(at), title);
+            }
+        }
+        printf("    </HUB>\n");
+    }
+    printf("</MTR>\n");
 }
 
 
-void csv_open(void)
+void csv_open(
+    void)
 {
 }
 
-void csv_close(struct mtr_ctl *ctl, time_t now)
+void csv_close(
+    struct mtr_ctl *ctl,
+    time_t now)
 {
-  int i, j, at, max;
-  ip_t *addr;
-  char name[MAX_FORMAT_STR];
-
-  for( i=0; i<MAXFLD; i++ ) {
-      j = ctl->fld_index[ctl->fld_active[i]];
-      if (j < 0) continue; 
-  }
-
-  max = net_max(ctl);
-  at  = net_min(ctl);
-  for(; at < max; at++) {
-    addr = net_addr(at);
-    snprint_addr(ctl, name, sizeof(name), addr);
-
-    if (at == net_min(ctl)) {
-      printf("Mtr_Version,Start_Time,Status,Host,Hop,Ip,");
-#ifdef HAVE_IPINFO
-      if(!ctl->ipinfo_no) {
-       printf("Asn,");
-      }
-#endif
-      for( i=0; i<MAXFLD; i++ ) {
-       j = ctl->fld_index[ctl->fld_active[i]];
-       if (j < 0) continue;
-       printf("%s,", data_fields[j].title);
-      }
-      printf("\n");
+    int i, j, at, max;
+    ip_t *addr;
+    char name[MAX_FORMAT_STR];
+
+    for (i = 0; i < MAXFLD; i++) {
+        j = ctl->fld_index[ctl->fld_active[i]];
+        if (j < 0)
+            continue;
     }
 
+    max = net_max(ctl);
+    at = net_min(ctl);
+    for (; at < max; at++) {
+        addr = net_addr(at);
+        snprint_addr(ctl, name, sizeof(name), addr);
+
+        if (at == net_min(ctl)) {
+            printf("Mtr_Version,Start_Time,Status,Host,Hop,Ip,");
 #ifdef HAVE_IPINFO
-    if(!ctl->ipinfo_no) {
-      char* fmtinfo = fmt_ipinfo(ctl, addr);
-      fmtinfo = trim(fmtinfo, '\0');
-      printf("MTR.%s,%lld,%s,%s,%d,%s,%s", PACKAGE_VERSION, (long long)now, "OK", ctl->Hostname,
-             at+1, name, fmtinfo);
-    } else
+            if (!ctl->ipinfo_no) {
+                printf("Asn,");
+            }
+#endif
+            for (i = 0; i < MAXFLD; i++) {
+                j = ctl->fld_index[ctl->fld_active[i]];
+                if (j < 0)
+                    continue;
+                printf("%s,", data_fields[j].title);
+            }
+            printf("\n");
+        }
+#ifdef HAVE_IPINFO
+        if (!ctl->ipinfo_no) {
+            char *fmtinfo = fmt_ipinfo(ctl, addr);
+            fmtinfo = trim(fmtinfo, '\0');
+            printf("MTR.%s,%lld,%s,%s,%d,%s,%s", PACKAGE_VERSION,
+                   (long long) now, "OK", ctl->Hostname, at + 1, name,
+                   fmtinfo);
+        } else
 #endif
-      printf("MTR.%s,%lld,%s,%s,%d,%s", PACKAGE_VERSION, (long long)now, "OK", ctl->Hostname,
-             at+1, name);
-
-    for( i=0; i<MAXFLD; i++ ) {
-      j = ctl->fld_index[ctl->fld_active[i]];
-      if (j < 0) continue; 
-
-      /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
-      if( strchr( data_fields[j].format, 'f' ) ) {
-       printf( ",%.2f", (double) (data_fields[j].net_xxx(at) / 1000.0));
-      } else {
-       printf( ",%d",   data_fields[j].net_xxx(at) );
-      }
+            printf("MTR.%s,%lld,%s,%s,%d,%s", PACKAGE_VERSION,
+                   (long long) now, "OK", ctl->Hostname, at + 1, name);
+
+        for (i = 0; i < MAXFLD; i++) {
+            j = ctl->fld_index[ctl->fld_active[i]];
+            if (j < 0)
+                continue;
+
+            /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
+            if (strchr(data_fields[j].format, 'f')) {
+                printf(",%.2f",
+                       (double) (data_fields[j].net_xxx(at) / 1000.0));
+            } else {
+                printf(",%d", data_fields[j].net_xxx(at));
+            }
+        }
+        printf("\n");
     }
-    printf("\n");
-  }
 }
index 3793463a9afbf04814e607645c9e773064e46f33..32b31c5d6cf19580cf5f4fa55ff96b6c95e75310 100644 (file)
 
 /*  Prototypes for report.h  */
 
-extern void report_open(void);
-extern void report_close(struct mtr_ctl *ctl);
-extern void txt_open(void);
-extern void txt_close(struct mtr_ctl *ctl);
-extern void json_open(void);
-extern void json_close(struct mtr_ctl *ctl);
-extern void xml_open(void);
-extern void xml_close(struct mtr_ctl *ctl);
-extern void csv_open(void);
-extern void csv_close(struct mtr_ctl *ctl, time_t now);
+extern void report_open(
+    void);
+extern void report_close(
+    struct mtr_ctl *ctl);
+extern void txt_open(
+    void);
+extern void txt_close(
+    struct mtr_ctl *ctl);
+extern void json_open(
+    void);
+extern void json_close(
+    struct mtr_ctl *ctl);
+extern void xml_open(
+    void);
+extern void xml_close(
+    struct mtr_ctl *ctl);
+extern void csv_open(
+    void);
+extern void csv_close(
+    struct mtr_ctl *ctl,
+    time_t now);
index 6e1431a78d7c2d4366e1a2c92c0db48ccea99440..15047a11e7e09c9752a58d110e94932279e41e15 100644 (file)
@@ -29,9 +29,9 @@
 #include <math.h>
 #include <errno.h>
 #ifdef HAVE_ERROR_H
-# include <error.h>
+#include <error.h>
 #else
-# include "portability/error.h"
+#include "portability/error.h"
 #endif
 
 #include "mtr.h"
 #include "display.h"
 #include "select.h"
 
-void select_loop(struct mtr_ctl *ctl){
-  fd_set readfd;
-  fd_set writefd;
-  int anyset = 0;
-  int maxfd = 0;
-  int dnsfd, netfd;
+void select_loop(
+    struct mtr_ctl *ctl)
+{
+    fd_set readfd;
+    fd_set writefd;
+    int anyset = 0;
+    int maxfd = 0;
+    int dnsfd, netfd;
 #ifdef ENABLE_IPV6
-  int dnsfd6;
+    int dnsfd6;
 #endif
-  int NumPing = 0;
-  int paused = 0;
-  struct timeval lasttime, thistime, selecttime;
-  struct timeval startgrace;
-  int dt;
-  int rv; 
-  int graceperiod = 0;
-  struct timeval intervaltime;
-  static double dnsinterval = 0;
-
-  memset(&startgrace, 0, sizeof(startgrace));
-
-  gettimeofday(&lasttime, NULL);
-
-  while(1) {
-    dt = calc_deltatime (ctl->WaitTime);
-    intervaltime.tv_sec  = dt / 1000000;
-    intervaltime.tv_usec = dt % 1000000;
-
-    FD_ZERO(&readfd);
-    FD_ZERO(&writefd);
-
-    maxfd = 0;
-
-    if(ctl->Interactive) {
-      FD_SET(0, &readfd);
-      maxfd = 1;
-    }
-
+    int NumPing = 0;
+    int paused = 0;
+    struct timeval lasttime, thistime, selecttime;
+    struct timeval startgrace;
+    int dt;
+    int rv;
+    int graceperiod = 0;
+    struct timeval intervaltime;
+    static double dnsinterval = 0;
+
+    memset(&startgrace, 0, sizeof(startgrace));
+
+    gettimeofday(&lasttime, NULL);
+
+    while (1) {
+        dt = calc_deltatime(ctl->WaitTime);
+        intervaltime.tv_sec = dt / 1000000;
+        intervaltime.tv_usec = dt % 1000000;
+
+        FD_ZERO(&readfd);
+        FD_ZERO(&writefd);
+
+        maxfd = 0;
+
+        if (ctl->Interactive) {
+            FD_SET(0, &readfd);
+            maxfd = 1;
+        }
 #ifdef ENABLE_IPV6
-    if (ctl->dns) {
-      dnsfd6 = dns_waitfd6();
-      if (dnsfd6 >= 0) {
-        FD_SET(dnsfd6, &readfd);
-        if(dnsfd6 >= maxfd) maxfd = dnsfd6 + 1;
-      } else {
-        dnsfd6 = 0;
-      }
-    } else
-      dnsfd6 = 0;
+        if (ctl->dns) {
+            dnsfd6 = dns_waitfd6();
+            if (dnsfd6 >= 0) {
+                FD_SET(dnsfd6, &readfd);
+                if (dnsfd6 >= maxfd)
+                    maxfd = dnsfd6 + 1;
+            } else {
+                dnsfd6 = 0;
+            }
+        } else
+            dnsfd6 = 0;
 #endif
-    if (ctl->dns) {
-      dnsfd = dns_waitfd();
-      FD_SET(dnsfd, &readfd);
-      if(dnsfd >= maxfd) maxfd = dnsfd + 1;
-    } else
-      dnsfd = 0;
-
-    netfd = net_waitfd();
-    FD_SET(netfd, &readfd);
-    if(netfd >= maxfd) maxfd = netfd + 1;
-
-    do {
-      if(anyset || paused) {
-       /* Set timeout to 0.1s.
-        * While this is almost instantaneous for human operators,
-        * it's slow enough for computers to go do something else;
-        * this prevents mtr from hogging 100% CPU time on one core.
-        */
-       selecttime.tv_sec = 0;
-       selecttime.tv_usec = paused?100000:0; 
-      
-       rv = select(maxfd, (void *)&readfd, &writefd, NULL, &selecttime);
-
-      } else {
-       if(ctl->Interactive) display_redraw(ctl);
-
-       gettimeofday(&thistime, NULL);
-
-       if(thistime.tv_sec > lasttime.tv_sec + intervaltime.tv_sec ||
-          (thistime.tv_sec == lasttime.tv_sec + intervaltime.tv_sec &&
-           thistime.tv_usec >= lasttime.tv_usec + intervaltime.tv_usec)) {
-         lasttime = thistime;
-
-         if (!graceperiod) {
-           if (NumPing >= ctl->MaxPing && (!ctl->Interactive || ctl->ForceMaxPing)) {
-             graceperiod = 1;
-             startgrace = thistime;
-           }
-
-           /* do not send out batch when we've already initiated grace period */
-           if (!graceperiod && net_send_batch(ctl))
-             NumPing++;
-         }
-       }
-
-       if (graceperiod) {
-         dt = (thistime.tv_usec - startgrace.tv_usec) +
-                   1000000 * (thistime.tv_sec - startgrace.tv_sec);
-         if ((ctl->GraceTime * 1000 * 1000) < dt)
-           return;
-       }
-
-       selecttime.tv_usec = (thistime.tv_usec - lasttime.tv_usec);
-       selecttime.tv_sec = (thistime.tv_sec - lasttime.tv_sec);
-       if (selecttime.tv_usec < 0) {
-         --selecttime.tv_sec;
-         selecttime.tv_usec += 1000000;
-       }
-       selecttime.tv_usec = intervaltime.tv_usec - selecttime.tv_usec;
-       selecttime.tv_sec = intervaltime.tv_sec - selecttime.tv_sec;
-       if (selecttime.tv_usec < 0) {
-         --selecttime.tv_sec;
-         selecttime.tv_usec += 1000000;
-       }
-
-       if (ctl->dns) {
-         if ((selecttime.tv_sec > (time_t)dnsinterval) ||
-             ((selecttime.tv_sec == (time_t)dnsinterval) &&
-              (selecttime.tv_usec > ((time_t)(dnsinterval * 1000000) % 1000000)))) {
-           selecttime.tv_sec = (time_t)dnsinterval;
-           selecttime.tv_usec = (time_t)(dnsinterval * 1000000) % 1000000;
-         }
-       }
-
-       rv = select(maxfd, (void *)&readfd, NULL, NULL, &selecttime);
-      }
-    } while ((rv < 0) && (errno == EINTR));
-
-    if (rv < 0) {
-      error(EXIT_FAILURE, errno, "Select failed");
-    }
-    anyset = 0;
-
-    /*  Have we got new packets back?  */
-    if(FD_ISSET(netfd, &readfd)) {
-      net_process_return(ctl);
-      anyset = 1;
-    }
-
-    if (ctl->dns) {
-      /* Handle any pending resolver events */
-      dnsinterval = ctl->WaitTime;
-    }
-
-    /*  Have we finished a nameservice lookup?  */
+        if (ctl->dns) {
+            dnsfd = dns_waitfd();
+            FD_SET(dnsfd, &readfd);
+            if (dnsfd >= maxfd)
+                maxfd = dnsfd + 1;
+        } else
+            dnsfd = 0;
+
+        netfd = net_waitfd();
+        FD_SET(netfd, &readfd);
+        if (netfd >= maxfd)
+            maxfd = netfd + 1;
+
+        do {
+            if (anyset || paused) {
+                /* Set timeout to 0.1s.
+                 * While this is almost instantaneous for human operators,
+                 * it's slow enough for computers to go do something else;
+                 * this prevents mtr from hogging 100% CPU time on one core.
+                 */
+                selecttime.tv_sec = 0;
+                selecttime.tv_usec = paused ? 100000 : 0;
+
+                rv = select(maxfd, (void *) &readfd, &writefd, NULL,
+                            &selecttime);
+
+            } else {
+                if (ctl->Interactive)
+                    display_redraw(ctl);
+
+                gettimeofday(&thistime, NULL);
+
+                if (thistime.tv_sec > lasttime.tv_sec + intervaltime.tv_sec
+                    || (thistime.tv_sec ==
+                        lasttime.tv_sec + intervaltime.tv_sec
+                        && thistime.tv_usec >=
+                        lasttime.tv_usec + intervaltime.tv_usec)) {
+                    lasttime = thistime;
+
+                    if (!graceperiod) {
+                        if (NumPing >= ctl->MaxPing
+                            && (!ctl->Interactive || ctl->ForceMaxPing)) {
+                            graceperiod = 1;
+                            startgrace = thistime;
+                        }
+
+                        /* do not send out batch when we've already initiated grace period */
+                        if (!graceperiod && net_send_batch(ctl))
+                            NumPing++;
+                    }
+                }
+
+                if (graceperiod) {
+                    dt = (thistime.tv_usec - startgrace.tv_usec) +
+                        1000000 * (thistime.tv_sec - startgrace.tv_sec);
+                    if ((ctl->GraceTime * 1000 * 1000) < dt)
+                        return;
+                }
+
+                selecttime.tv_usec = (thistime.tv_usec - lasttime.tv_usec);
+                selecttime.tv_sec = (thistime.tv_sec - lasttime.tv_sec);
+                if (selecttime.tv_usec < 0) {
+                    --selecttime.tv_sec;
+                    selecttime.tv_usec += 1000000;
+                }
+                selecttime.tv_usec =
+                    intervaltime.tv_usec - selecttime.tv_usec;
+                selecttime.tv_sec =
+                    intervaltime.tv_sec - selecttime.tv_sec;
+                if (selecttime.tv_usec < 0) {
+                    --selecttime.tv_sec;
+                    selecttime.tv_usec += 1000000;
+                }
+
+                if (ctl->dns) {
+                    if ((selecttime.tv_sec > (time_t) dnsinterval) ||
+                        ((selecttime.tv_sec == (time_t) dnsinterval) &&
+                         (selecttime.tv_usec >
+                          ((time_t) (dnsinterval * 1000000) % 1000000)))) {
+                        selecttime.tv_sec = (time_t) dnsinterval;
+                        selecttime.tv_usec =
+                            (time_t) (dnsinterval * 1000000) % 1000000;
+                    }
+                }
+
+                rv = select(maxfd, (void *) &readfd, NULL, NULL,
+                            &selecttime);
+            }
+        } while ((rv < 0) && (errno == EINTR));
+
+        if (rv < 0) {
+            error(EXIT_FAILURE, errno, "Select failed");
+        }
+        anyset = 0;
+
+        /*  Have we got new packets back?  */
+        if (FD_ISSET(netfd, &readfd)) {
+            net_process_return(ctl);
+            anyset = 1;
+        }
+
+        if (ctl->dns) {
+            /* Handle any pending resolver events */
+            dnsinterval = ctl->WaitTime;
+        }
+
+        /*  Have we finished a nameservice lookup?  */
 #ifdef ENABLE_IPV6
-    if(ctl->dns && dnsfd6 && FD_ISSET(dnsfd6, &readfd)) {
-      dns_ack6();
-      anyset = 1;
-    }
+        if (ctl->dns && dnsfd6 && FD_ISSET(dnsfd6, &readfd)) {
+            dns_ack6();
+            anyset = 1;
+        }
 #endif
-    if(ctl->dns && dnsfd && FD_ISSET(dnsfd, &readfd)) {
-      dns_ack(ctl);
-      anyset = 1;
-    }
-
-    /*  Has a key been pressed?  */
-    if(FD_ISSET(0, &readfd)) {
-      switch (display_keyaction(ctl)) {
-      case ActionQuit: 
-       return;
-       break;
-      case ActionReset:
-       net_reset(ctl);
-       break;
-      case ActionDisplay:
-        ctl->display_mode = (ctl->display_mode + 1) % DisplayModeMAX;
-       break;
-      case ActionClear:
-       display_clear(ctl);
-       break;
-      case ActionPause:
-       paused=1;
-       break;
-      case  ActionResume:
-       paused=0;
-       break;
-      case ActionMPLS:
-          ctl->enablempls = !ctl->enablempls;
-          display_clear(ctl);
-       break;
-      case ActionDNS:
-       if (ctl->dns) {
-         ctl->use_dns = !ctl->use_dns;
-         display_clear(ctl);
-       }
-       break;
+        if (ctl->dns && dnsfd && FD_ISSET(dnsfd, &readfd)) {
+            dns_ack(ctl);
+            anyset = 1;
+        }
+
+        /*  Has a key been pressed?  */
+        if (FD_ISSET(0, &readfd)) {
+            switch (display_keyaction(ctl)) {
+            case ActionQuit:
+                return;
+                break;
+            case ActionReset:
+                net_reset(ctl);
+                break;
+            case ActionDisplay:
+                ctl->display_mode =
+                    (ctl->display_mode + 1) % DisplayModeMAX;
+                break;
+            case ActionClear:
+                display_clear(ctl);
+                break;
+            case ActionPause:
+                paused = 1;
+                break;
+            case ActionResume:
+                paused = 0;
+                break;
+            case ActionMPLS:
+                ctl->enablempls = !ctl->enablempls;
+                display_clear(ctl);
+                break;
+            case ActionDNS:
+                if (ctl->dns) {
+                    ctl->use_dns = !ctl->use_dns;
+                    display_clear(ctl);
+                }
+                break;
 #ifdef HAVE_IPINFO
-      case ActionII:
-       ctl->ipinfo_no++;
-       if (ctl->ipinfo_no > ctl->ipinfo_max)
-         ctl->ipinfo_no = 0;
-       break;
-      case ActionAS:
-       ctl->ipinfo_no = ctl->ipinfo_no ? 0 : ctl->ipinfo_max;
-       break;
+            case ActionII:
+                ctl->ipinfo_no++;
+                if (ctl->ipinfo_no > ctl->ipinfo_max)
+                    ctl->ipinfo_no = 0;
+                break;
+            case ActionAS:
+                ctl->ipinfo_no = ctl->ipinfo_no ? 0 : ctl->ipinfo_max;
+                break;
 #endif
 
-      case ActionScrollDown:
-        ctl->display_offset += 5;
-       break;
-      case ActionScrollUp:
-        ctl->display_offset -= 5;
-       if (ctl->display_offset < 0) {
-         ctl->display_offset = 0;
-       }
-       break;
-      }
-      anyset = 1;
+            case ActionScrollDown:
+                ctl->display_offset += 5;
+                break;
+            case ActionScrollUp:
+                ctl->display_offset -= 5;
+                if (ctl->display_offset < 0) {
+                    ctl->display_offset = 0;
+                }
+                break;
+            }
+            anyset = 1;
+        }
     }
-  }
-  return;
+    return;
 }
-
index 1e57079f661bb9b0cb66e070a8eee8a83f7fedb1..08ad44efcb303532a19d8ad7894169111f1de09c 100644 (file)
@@ -16,4 +16,5 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-extern void select_loop(struct mtr_ctl *ctl);
+extern void select_loop(
+    struct mtr_ctl *ctl);
index e75ca9db0fea6cedfbf34e7bda83c7477b04a0bc..08951031963f8e38113cc43f081d29da91daf068 100644 (file)
 #include "utils.h"
 
 #ifdef HAVE_CURSES
-# if defined(HAVE_NCURSES_H)
-#  include <ncurses.h>
-# elif defined(HAVE_NCURSES_CURSES_H)
-#  include <ncurses/curses.h>
-# elif defined(HAVE_CURSES_H)
-#  include <curses.h>
-# else
-#  error No curses header file available
-# endif
+#if defined(HAVE_NCURSES_H)
+#include <ncurses.h>
+#elif defined(HAVE_NCURSES_CURSES_H)
+#include <ncurses/curses.h>
+#elif defined(HAVE_CURSES_H)
+#include <curses.h>
 #else
-# include <sys/time.h>
-# include <sys/types.h>
-# include <unistd.h>
+#error No curses header file available
+#endif
+#else
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
 #endif
 
 
 #define MAX_LINE_SIZE  256
 
 static char Lines[MAX_LINE_COUNT][MAX_LINE_SIZE];
-static int  LineCount;
+static int LineCount;
 
 
 #define DEBUG 0
 
 
-void split_redraw(struct mtr_ctl *ctl)
+void split_redraw(
+    struct mtr_ctl *ctl)
 {
-  int   max;
-  int   at;
-  ip_t *addr;
-  char  newLine[MAX_LINE_SIZE];
-  int   i;
+    int max;
+    int at;
+    ip_t *addr;
+    char newLine[MAX_LINE_SIZE];
+    int i;
 
 #if DEBUG
-  fprintf(stderr, "split_redraw()\n"); 
+    fprintf(stderr, "split_redraw()\n");
 #endif
 
-  /* 
-   * If there is less lines than last time, we delete them
-   * TEST THIS PLEASE
-   */
-  max = net_max(ctl);
-  for (i=LineCount; i>max; i--) {
-    printf("-%d\n", i);
-    LineCount--;
-  }
-
-  /*
-   * For each line, we compute the new one and we compare it to the old one
-   */
-  for(at = 0; at < max; at++) {
-    addr = net_addr(at);
-    if(addrcmp((void*)addr, (void*)&ctl->unspec_addr, ctl->af)) {
-      char str[256], *name;
-      if (!(name = dns_lookup(ctl, addr)))
-        name = strlongip(ctl, addr);
-      if (ctl->show_ips) {
-        snprintf(str, sizeof(str), "%s %s", name, strlongip(ctl, addr));
-        name = str;
-      }
-      /* May be we should test name's length */
-      snprintf(newLine, sizeof(newLine), "%s %d %d %d %d %d %d", name,
-               net_loss(at),
-               net_returned(at), net_xmit(at),
-               net_best(at) /1000, net_avg(at)/1000,
-               net_worst(at)/1000);
-    } else {
-      snprintf(newLine, sizeof(newLine), "???");
+    /* 
+     * If there is less lines than last time, we delete them
+     * TEST THIS PLEASE
+     */
+    max = net_max(ctl);
+    for (i = LineCount; i > max; i--) {
+        printf("-%d\n", i);
+        LineCount--;
     }
 
-    if (strcmp(newLine, Lines[at]) == 0) {
-      /* The same, so do nothing */
+    /*
+     * For each line, we compute the new one and we compare it to the old one
+     */
+    for (at = 0; at < max; at++) {
+        addr = net_addr(at);
+        if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
+            char str[256], *name;
+            if (!(name = dns_lookup(ctl, addr)))
+                name = strlongip(ctl, addr);
+            if (ctl->show_ips) {
+                snprintf(str, sizeof(str), "%s %s", name,
+                         strlongip(ctl, addr));
+                name = str;
+            }
+            /* May be we should test name's length */
+            snprintf(newLine, sizeof(newLine), "%s %d %d %d %d %d %d",
+                     name, net_loss(at), net_returned(at), net_xmit(at),
+                     net_best(at) / 1000, net_avg(at) / 1000,
+                     net_worst(at) / 1000);
+        } else {
+            snprintf(newLine, sizeof(newLine), "???");
+        }
+
+        if (strcmp(newLine, Lines[at]) == 0) {
+            /* The same, so do nothing */
 #if DEBUG
-      printf("SAME LINE\n");
+            printf("SAME LINE\n");
 #endif
-    } else {
-      printf("%d %s\n", at+1, newLine);
-      fflush(stdout);
-      xstrncpy(Lines[at], newLine, MAX_LINE_SIZE);
-      if (LineCount < (at+1)) {
-       LineCount = at+1;
-      }
+        } else {
+            printf("%d %s\n", at + 1, newLine);
+            fflush(stdout);
+            xstrncpy(Lines[at], newLine, MAX_LINE_SIZE);
+            if (LineCount < (at + 1)) {
+                LineCount = at + 1;
+            }
+        }
     }
-  }
 }
 
 
-void split_open(void)
+void split_open(
+    void)
 {
-  int i;
+    int i;
 #if DEBUG
-  printf("split_open()\n");
+    printf("split_open()\n");
 #endif
-  LineCount = -1;
-  for (i=0; i<MAX_LINE_COUNT; i++) {
-    xstrncpy(Lines[i], "???", MAX_LINE_SIZE);
-  }
+    LineCount = -1;
+    for (i = 0; i < MAX_LINE_COUNT; i++) {
+        xstrncpy(Lines[i], "???", MAX_LINE_SIZE);
+    }
 }
 
 
-void split_close(void)
+void split_close(
+    void)
 {
 #if DEBUG
-  printf("split_close()\n");
+    printf("split_close()\n");
 #endif
 }
 
 
-int split_keyaction(void) 
+int split_keyaction(
+    void)
 {
 #ifdef HAVE_CURSES
-  unsigned char c = getch();
+    unsigned char c = getch();
 #else
-  fd_set readfds;
-  struct timeval tv;
-  char c;
-
-  FD_ZERO (&readfds);
-  FD_SET (0, &readfds);
-  tv.tv_sec = 0;
-  tv.tv_usec = 0;
-
-  if (select (1, &readfds, NULL, NULL, &tv) > 0) {
-    read (0, &c, 1);
-  } else 
-    return 0;
+    fd_set readfds;
+    struct timeval tv;
+    char c;
+
+    FD_ZERO(&readfds);
+    FD_SET(0, &readfds);
+    tv.tv_sec = 0;
+    tv.tv_usec = 0;
+
+    if (select(1, &readfds, NULL, NULL, &tv) > 0) {
+        read(0, &c, 1);
+    } else
+        return 0;
 #endif
 
 #if DEBUG
-  printf("split_keyaction()\n");
+    printf("split_keyaction()\n");
 #endif
-  if(tolower(c) == 'q')
-    return ActionQuit;
-  if(c==3)
-    return ActionQuit;
-  if(tolower(c) == 'r')
-    return ActionReset;
-  
-  return 0;
+    if (tolower(c) == 'q')
+        return ActionQuit;
+    if (c == 3)
+        return ActionQuit;
+    if (tolower(c) == 'r')
+        return ActionReset;
+
+    return 0;
 }
index 1f15198993c7484ec48684329932526f8371086e..84b6794e456111c94824ee4d815e0e8ac4cee31d 100644 (file)
 */
 
 /*  Prototypes for split.c  */
-extern void split_open(void);
-extern void split_close(void);
-extern void split_redraw(struct mtr_ctl *ctl);
-extern int split_keyaction(void);
+extern void split_open(
+    void);
+extern void split_close(
+    void);
+extern void split_redraw(
+    struct mtr_ctl *ctl);
+extern int split_keyaction(
+    void);
index d8259a8ecb9183e2afb623a8f3f0f224ee71ddb5..94bf21aae0e3b75122d42729a8a9b712cab9e4cd 100644 (file)
 #include <unistd.h>
 
 #ifdef HAVE_ERROR_H
-# include <error.h>
+#include <error.h>
 #else
-# include "portability/error.h"
+#include "portability/error.h"
 #endif
 
 #ifdef HAVE_STDIO_EXT_H
-# include <stdio_ext.h>
+#include <stdio_ext.h>
 #endif
 
 #include "utils.h"
 
-char *trim(char *str, const char c)
+char *trim(
+    char *str,
+    const char c)
 {
-  char *p = str;
-  size_t len;
+    char *p = str;
+    size_t len;
+
+    /* left trim */
+    while (*p && (isspace((unsigned char) *p) || (c && *p == c)))
+        p++;
+    if (str < p) {
+        len = strlen(str);
+        memmove(str, p, len + 1);
+    }
 
-  /* left trim */
-  while (*p && (isspace((unsigned char)*p) || (c && *p == c)))
-    p++;
-  if (str < p) {
+    /* right trim */
     len = strlen(str);
-    memmove(str, p, len + 1);
-  }
-
-  /* right trim */
-  len = strlen(str);
-  while (len) {
-    len--;
-    if (isspace((unsigned char)str[len]) || (c && str[len] == c)) {
-      continue;
+    while (len) {
+        len--;
+        if (isspace((unsigned char) str[len]) || (c && str[len] == c)) {
+            continue;
+        }
+        len++;
+        break;
     }
-    len++;
-    break;
-  }
-  str[len] = '\0';
-  return str;
+    str[len] = '\0';
+    return str;
 }
 
 /* Parse string, and return positive signed int. */
-int strtonum_or_err(const char *str, const char *errmesg, const int type)
+int strtonum_or_err(
+    const char *str,
+    const char *errmesg,
+    const int type)
 {
-  unsigned long int num;
-  char *end = NULL;
-
-  if (str != NULL && *str != '\0') {
-    errno = 0;
-    num = strtoul(str, &end, 10);
-    if (errno == 0 && str != end && end != NULL && *end == '\0') {
-      switch (type) {
-      case STRTO_INT:
-        if (num < INT_MAX)
-          return num;
-        break;
-      case STRTO_U32INT:
-        if (num < UINT32_MAX)
-          return num;
-        break;
-      }
+    unsigned long int num;
+    char *end = NULL;
+
+    if (str != NULL && *str != '\0') {
+        errno = 0;
+        num = strtoul(str, &end, 10);
+        if (errno == 0 && str != end && end != NULL && *end == '\0') {
+            switch (type) {
+            case STRTO_INT:
+                if (num < INT_MAX)
+                    return num;
+                break;
+            case STRTO_U32INT:
+                if (num < UINT32_MAX)
+                    return num;
+                break;
+            }
+        }
     }
-  }
-  error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
-  return 0;
+    error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
+    return 0;
 }
 
-float strtofloat_or_err(const char *str, const char *errmesg)
+float strtofloat_or_err(
+    const char *str,
+    const char *errmesg)
 {
-  double num;
-  char *end = NULL;
+    double num;
+    char *end = NULL;
 
-  if (str != NULL && *str != '\0') {
-    errno = 0;
-    num = strtod(str, &end);
-    if (errno == 0 && str != end && end != NULL && *end == '\0'
+    if (str != NULL && *str != '\0') {
+        errno = 0;
+        num = strtod(str, &end);
+        if (errno == 0 && str != end && end != NULL && *end == '\0'
 #ifdef FLT_MAX
-        && num < FLT_MAX
+            && num < FLT_MAX
 #endif
-        )
-      return num;
-  }
-  error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
-  return 0;
+            )
+            return num;
+    }
+    error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
+    return 0;
 }
 
-void *xmalloc(const size_t size)
+void *xmalloc(
+    const size_t size)
 {
-  void *ret = malloc(size);
+    void *ret = malloc(size);
 
-  if (!ret && size)
-    error(EXIT_FAILURE, errno, "cannot allocate %zu bytes", size);
-  return ret;
+    if (!ret && size)
+        error(EXIT_FAILURE, errno, "cannot allocate %zu bytes", size);
+    return ret;
 }
 
-char *xstrdup(const char *str)
+char *xstrdup(
+    const char *str)
 {
-  char *ret;
-
-  if (!str)
-    return NULL;
-  ret = strdup(str);
-  if (!ret)
-    error(EXIT_FAILURE, errno, "cannot duplicate string: %s", str);
-  return ret;
+    char *ret;
+
+    if (!str)
+        return NULL;
+    ret = strdup(str);
+    if (!ret)
+        error(EXIT_FAILURE, errno, "cannot duplicate string: %s", str);
+    return ret;
 }
 
 #ifndef HAVE___FPENDING
-static inline int __fpending(FILE *stream __attribute__((__unused__)))
+static inline int __fpending(
+    FILE * stream __attribute__ ((__unused__)))
 {
-  return 0;
+    return 0;
 }
 #endif
-static inline int close_stream(FILE *stream)
+static inline int close_stream(
+    FILE * stream)
 {
-  const int some_pending = (__fpending(stream) != 0);
-  const int prev_fail = (ferror(stream) != 0);
-  const int fclose_fail = (fclose(stream) != 0);
-
-  if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) {
-    if (!fclose_fail && !(errno == EPIPE))
-      errno = 0;
-    return EOF;
-  }
-  return 0;
+    const int some_pending = (__fpending(stream) != 0);
+    const int prev_fail = (ferror(stream) != 0);
+    const int fclose_fail = (fclose(stream) != 0);
+
+    if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) {
+        if (!fclose_fail && !(errno == EPIPE))
+            errno = 0;
+        return EOF;
+    }
+    return 0;
 }
+
 /* Meant to be used atexit(close_stdout); */
-void close_stdout(void)
+void close_stdout(
+    void)
 {
-  if (close_stream(stdout) != 0 && !(errno == EPIPE)) {
-    error(0, errno, "write error");
-    _exit(EXIT_FAILURE);
-  }
-  if (close_stream(stderr) != 0)
-    _exit(EXIT_FAILURE);
+    if (close_stream(stdout) != 0 && !(errno == EPIPE)) {
+        error(0, errno, "write error");
+        _exit(EXIT_FAILURE);
+    }
+    if (close_stream(stderr) != 0)
+        _exit(EXIT_FAILURE);
 }
 
 /* ctime() replacement that will reteturn ISO-8601 timestamp string such as:
  * 2016-08-29T19:25:02+01:00 */
-const char *iso_time(const time_t *t)
+const char *iso_time(
+    const time_t * t)
 {
-  static char s[32];
-  struct tm *tm;
+    static char s[32];
+    struct tm *tm;
 
-  tm = localtime(t);
-  strftime(s, sizeof(s), "%Y-%m-%dT%H:%M:%S%z", tm);
-  return s;
+    tm = localtime(t);
+    strftime(s, sizeof(s), "%Y-%m-%dT%H:%M:%S%z", tm);
+    return s;
 }
index 62ae239545820b6d986d37232ca593cdbc63c5cb..7fc2055886b83582422c349d8bf8ae9c18125332 100644 (file)
 */
 
 enum {
-  STRTO_INT,
-  STRTO_U32INT
+    STRTO_INT,
+    STRTO_U32INT
 };
 
-extern char *trim(char *s, const char c);
-extern int strtonum_or_err(const char *str, const char *errmesg, const int type);
-extern float strtofloat_or_err(const char *str, const char *errmesg);
+extern char *trim(
+    char *s,
+    const char c);
+extern int strtonum_or_err(
+    const char *str,
+    const char *errmesg,
+    const int type);
+extern float strtofloat_or_err(
+    const char *str,
+    const char *errmesg);
 
 /* Like strncpy(3) but ensure null termination. */
-static inline void xstrncpy(char *dest, const char *src, size_t n)
+static inline void xstrncpy(
+    char *dest,
+    const char *src,
+    size_t n)
 {
-  strncpy(dest, src, n - 1);
-  dest[n - 1] = 0;
+    strncpy(dest, src, n - 1);
+    dest[n - 1] = 0;
 }
 
-extern void *xmalloc(const size_t size);
-extern char *xstrdup(const char *str);
+extern void *xmalloc(
+    const size_t size);
+extern char *xstrdup(
+    const char *str);
 
-extern void close_stdout(void);
+extern void close_stdout(
+    void);
 
-extern const char *iso_time(const time_t *t);
+extern const char *iso_time(
+    const time_t * t);