+}
+
+# Print table header.
+print <<END;
+ <table width='100%'>
+ <tr valign="top"">
+ <th align='center'>
+ <a href="?sort_field=5&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=5&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+ </th>
+ <th align='center' colspan="2">
+ <a href="?sort_field=1&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=1&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+
+ <a href="?sort_field=3&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=3&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+ </th>
+ <th align='center' colspan="2">
+ <a href="?sort_field=2&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=2&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+
+ <a href="?sort_field=4&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=4&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+ </th>
+ <th align='center'>
+ <a href="?sort_field=8&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=8&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+
+ <a href="?sort_field=9&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=9&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+ </th>
+ <th align='center'>
+ <a href="?sort_field=6&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=6&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+ </th>
+ <th align='center'>
+ <a href="?sort_field=7&sort_order=d"><img style="width:10px" src="/images/up.gif"></a>
+ <a href="?sort_field=7&sort_order=a"><img style="width:10px" src="/images/down.gif"></a>
+ </th>
+ </tr>
+ <tr valign="top"">
+ <th align='center'>
+ $Lang::tr{'protocol'}
+ </th>
+ <th align='center' colspan="2">
+ $Lang::tr{'source ip and port'}
+ </th>
+ <th align='center' colspan="2">
+ $Lang::tr{'dest ip and port'}
+ </th>
+ <th align='center'>
+ $Lang::tr{'download'} /
+ <br>$Lang::tr{'upload'}
+ </th>
+ <th align='center'>
+ $Lang::tr{'connection'}<br>$Lang::tr{'status'}
+ </th>
+ <th align='center'>
+ $Lang::tr{'expires'}<br>($Lang::tr{'seconds'})
+ </th>
+ </tr>
+END
+
+foreach my $line (@conntrack) {
+ my @conn = split(' ', $line);
+
+ # The first bit is the l3 protocol.
+ my $l3proto = $conn[0];
+
+ # Skip everything that is not IPv4.
+ if ($l3proto ne 'ipv4') {
+ next;
+ }
+
+ # L4 protocol (tcp, udp, ...).
+ my $l4proto = $conn[2];
+
+ # Translate unknown protocols.
+ if ($l4proto eq 'unknown') {
+ my $l4protonum = $conn[3];
+ if ($l4protonum eq '2') {
+ $l4proto = 'IGMP';
+ } elsif ($l4protonum eq '4') {
+ $l4proto = 'IPv4 Encap';
+ } elsif ($l4protonum eq '33') {
+ $l4proto = 'DCCP';
+ } elsif ($l4protonum eq '41') {
+ $l4proto = 'IPv6 Encap';
+ } elsif ($l4protonum eq '50') {
+ $l4proto = 'ESP';
+ } elsif ($l4protonum eq '51') {
+ $l4proto = 'AH';
+ } elsif ($l4protonum eq '132') {
+ $l4proto = 'SCTP';
+ } else {
+ $l4proto = $l4protonum;
+ }
+ } else {
+ $l4proto = uc($l4proto);
+ }
+
+ # Source and destination.
+ my $sip;
+ my $sip_ret;
+ my $dip;
+ my $dip_ret;
+ my $sport;
+ my $sport_ret;
+ my $dport;
+ my $dport_ret;
+ my @packets;
+ my @bytes;
+
+ my $ttl = $conn[4];
+ my $state;
+ if ($l4proto eq 'TCP') {
+ $state = $conn[5];
+ }
+
+ # Kick out everything that is not IPv4.
+ foreach my $item (@conn) {
+ my ($key, $val) = split('=', $item);
+
+ switch ($key) {
+ case "src" {
+ if ($sip == "") {
+ $sip = $val;
+ } else {
+ $dip_ret = $val;
+ }
+ }
+ case "dst" {
+ if ($dip == "") {
+ $dip = $val;
+ } else {
+ $sip_ret = $val;
+ }
+ }
+ case "sport" {
+ if ($sport == "") {
+ $sport = $val;
+ } else {
+ $dport_ret = $val;
+ }
+ }
+ case "dport" {
+ if ($dport == "") {
+ $dport = $val;
+ } else {
+ $sport_ret = $val;
+ }
+ }
+ case "packets" {
+ push(@packets, $val);
+ }
+ case "bytes" {
+ push(@bytes, $val);
+ }
+ }
+ }
+
+ my $sip_colour = ipcolour($sip);
+ my $dip_colour = ipcolour($dip);
+
+ my $sserv = '';
+ if ($sport < 1024) {
+ $sserv = uc(getservbyport($sport, lc($l4proto)));
+ }
+
+ my $dserv = '';
+ if ($dport < 1024) {
+ $dserv = uc(getservbyport($dport, lc($l4proto)));
+ }
+
+ my $bytes_in = format_bytes($bytes[0]);
+ my $bytes_out = format_bytes($bytes[1]);
+
+ # Format TTL
+ $ttl = format_time($ttl);
+
+ my $sip_extra;
+ if ($sip ne $sip_ret) {
+ $sip_extra = "<font color='#FFFFFF'>></font> ";
+ $sip_extra .= "<a href='/cgi-bin/ipinfo.cgi?ip=$sip_ret'>";
+ $sip_extra .= " <font color='#FFFFFF'>$sip_ret</font>";
+ $sip_extra .= "</a>";
+ }
+
+ my $dip_extra;
+ if ($dip ne $dip_ret) {
+ $dip_extra = "<font color='#FFFFFF'>></font> ";
+ $dip_extra .= "<a href='/cgi-bin/ipinfo.cgi?ip=$dip_ret'>";
+ $dip_extra .= " <font color='#FFFFFF'>$dip_ret</font>";
+ $dip_extra .= "</a>";
+ }
+
+
+ my $sport_extra;
+ if ($sport ne $sport_ret) {
+ my $sserv_ret = '';
+ if ($sport_ret < 1024) {
+ $sserv_ret = uc(getservbyport($sport_ret, lc($l4proto)));
+ }
+
+ $sport_extra = "<font color='#FFFFFF'>></font> ";
+ $sport_extra .= "<a href='http://isc.sans.org/port_details.php?port=$sport_ret' target='top' title='$sserv_ret'>";
+ $sport_extra .= " <font color='#FFFFFF'>$sport_ret</font>";
+ $sport_extra .= "</a>";
+ }