├── DMRmonitor ├── hytera.txt ├── hyteramon.c ├── trbomon_v1.c │ ├── interface.h │ ├── netdissect.h │ ├── print-ascii.c │ └── tcpdump.c └── trbomon_v2.c ├── DMRserver ├── dmr-server.pl └── dmrmon-server.c ├── README.hytera ├── README.md ├── README.motorola ├── pcap ├── H1G031440010314400100000002.pcap.gpg ├── H1G121212121313131306969696.pcap.gpg ├── H1P121212121313131306969696.pcap.gpg ├── H1P121212121313131307878787.pcap.gpg ├── H2G031440010314400100000001.pcap.gpg ├── H2G121212121313131307878787.pcap.gpg ├── HyteraMasterReboot.pcap.gpg ├── README └── status.cap.gpg ├── scripts └── DmrMarcRip.php ├── sql └── dmrdb_dump.sql └── web ├── calllog.php ├── lastheard.php ├── netstatus.css ├── netstatus.json ├── netstatus.php └── netstatus.phps /DMRmonitor/hyteramon.c: -------------------------------------------------------------------------------- 1 | /* 2 | dmrmonitor-hytera - monitor hytera repeater and send to server 3 | Copyright (C) 2012 David Kierzokwski (kd8eyf@digitalham.info) 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 | #include 19 | #include 20 | #include 21 | #include "/usr/include/pcap/pcap.h" // NEED TO FIX THIS 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | struct UDP_hdr { 30 | u_short uh_sport; //Source Port 31 | u_short uh_dport; //Destnation Port 32 | u_short uh_ulen; //Datagram Length 33 | u_short uh_sum; //Datagram Checksum 34 | }; 35 | int debug = 0; 36 | char *devname = NULL; 37 | uint16_t SrcID = ((uint16_t)67 << 8) | ((uint16_t)65 << 0); 38 | void usage( int8_t e ); 39 | void processPacket(u_char *arg, const struct pcap_pkthdr* pkthdr, const u_char * packet) 40 | { 41 | struct ip * ip; 42 | struct UDP_hdr * udp; 43 | struct slot{ 44 | int Status; 45 | int CallType; 46 | int SourceID; 47 | int DestinationID; 48 | }; 49 | struct repeater{ 50 | struct ip RepeaterID; 51 | struct slot slot1; 52 | struct slot slot2; 53 | }; 54 | unsigned int IP_header_length; 55 | unsigned int capture_len = pkthdr->len; 56 | int PacketType; 57 | long value; 58 | int i=0, *counter = (int *)arg; 59 | uint32_t DmrID = 0; 60 | uint16_t sync = 0; 61 | uint16_t Timeslot = 0; 62 | time_t Time; 63 | uint32_t DestinationID; 64 | struct tm * tm; 65 | PacketType = 0; 66 | packet += sizeof (struct ether_header); 67 | capture_len -= sizeof(struct ether_header); 68 | ip = (struct ip*) packet; 69 | IP_header_length = ip->ip_hl *4; 70 | packet += IP_header_length; 71 | capture_len -= IP_header_length; 72 | udp = (struct UDP_hdr*) packet; 73 | packet += sizeof (struct UDP_hdr); 74 | capture_len -= sizeof (struct UDP_hdr); 75 | Time = time(NULL); 76 | tm = gmtime (&Time); 77 | printdata(); 78 | if ((capture_len == 72) && (debug != 2)) { 79 | PacketType = *(packet+8); 80 | sync = *(packet+22)<<8|*(packet+23); 81 | printf("PT: %i SYNC: %i\n",PacketType,sync); 82 | if (sync == 4369){ 83 | if (Timeslot == 4369){ Timeslot = 1; }; 84 | if (Timeslot == 8738){ Timeslot = 2; }; 85 | DmrID = *(packet+38)<<16|*(packet+40)<<8|*(packet+42); 86 | DestinationID = *(packet+66)<<16|*(packet+65)<<8|*(packet+64); 87 | RepeaterID = ip->ip_src; 88 | 89 | if PacketType = 2 { //New or Continued Call 90 | repeater 91 | } 92 | if PacketType = 3 { //End Of Call 93 | } 94 | Timeslot = *(packet+16)<<8|*(packet+17); 95 | }; 96 | } 97 | 98 | } 99 | 100 | 101 | int main(int argc, char *argv[] ) 102 | { 103 | char packet_filter[] = "ip and udp"; 104 | struct bpf_program fcode; 105 | u_int netmask; 106 | pcap_t *descr = NULL; 107 | int32_t c; 108 | while ((c = getopt(argc, argv, "opdVhi:")) != EOF) { 109 | switch (c) { 110 | case 'p': 111 | debug = 2; 112 | break; 113 | case 'd': 114 | debug = 1; 115 | break; 116 | case 'V': 117 | version(); 118 | break; 119 | case 'i': 120 | devname = optarg; 121 | break; 122 | case 'h': 123 | usage(-1); 124 | break; 125 | } 126 | } 127 | if (devname == NULL) { 128 | usage(-1); 129 | } 130 | if (debug == 1) { 131 | printf("USING CAPTURE DEVICE: %s\n", devname); 132 | } 133 | 134 | pcap_if_t *alldevsp , *device; 135 | pcap_t *handle; 136 | char errbuf[100] , devs[100][100]; 137 | int count = 1 , n; 138 | handle = pcap_open_live(devname , 65536 , 1 , 0 , errbuf); 139 | if (handle == NULL) { 140 | fprintf(stderr, "Couldn't open device %s : %s\n" , devname , errbuf); 141 | exit(1); 142 | } 143 | pcap_compile(handle, &fcode, packet_filter, 1, netmask); 144 | 145 | if ( pcap_loop(handle, -1, processPacket, (u_char *)&count) == -1) { 146 | fprintf(stderr, "ERROR: %s\n", pcap_geterr(descr) ); 147 | exit(1); 148 | } 149 | return 0; 150 | } 151 | void usage(int8_t e) 152 | { 153 | printf( "Usage: DMRmontiorHytera [OPTION]... \n" 154 | "Listen send DMR data for remote server for processing\n" 155 | "\n" 156 | " -i, --interface Interface to listen on\n" 157 | " -h, --help This Help\n" 158 | " -V, --version Version Information\n" 159 | " -d, --debug Show whats happening in english\n" 160 | " -p, --payload Dump UDP payload data in one line hex (usefull for reverse engineering)\n" 161 | "\n" 162 | "Report cat bugs to kd8eyf@digitalham.info\n"); 163 | exit(e); 164 | } 165 | 166 | int version ( void ) 167 | { 168 | printf ("hytera 0.04\n"); 169 | exit(1); 170 | } 171 | 172 | int printdata () 173 | { 174 | /// if (debug == 0) { 175 | /// printf("%04d-%02d-%02d ",tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); 176 | /// printf("%02d:%02d:%02d ",tm->tm_hour, tm->tm_min, tm->tm_sec); 177 | /// printf("%s %i %i %i %i\n",inet_ntoa(ip->ip_src), PacketType, Timeslot, DmrID, DestinationID); 178 | /// } 179 | /// if (debug == 1) { 180 | /// }g 181 | /// if (debug == 2) { 182 | /// printf("%s",inet_ntoa(ip->ip_src)); 183 | /// printf(":%d -> ",ntohs(udp->uh_sport)); 184 | /// printf("%s", inet_ntoa(ip->ip_dst)); 185 | /// printf(":%d -> ",ntohs(udp->uh_dport)); 186 | /// while (i < capture_len) { 187 | /// printf("%02X", packet[i]); 188 | /// i++; 189 | /// } 190 | /// printf("\n"); 191 | /// } 192 | /// 193 | } 194 | 195 | -------------------------------------------------------------------------------- /DMRmonitor/trbomon_v1.c/interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1988-2002 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that: (1) source code distributions 7 | * retain the above copyright notice and this paragraph in its entirety, (2) 8 | * distributions including binary code include the above copyright notice and 9 | * this paragraph in its entirety in the documentation or other materials 10 | * provided with the distribution, and (3) all advertising materials mentioning 11 | * features or use of this software display the following acknowledgement: 12 | * ``This product includes software developed by the University of California, 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 | * the University nor the names of its contributors may be used to endorse 15 | * or promote products derived from this software without specific prior 16 | * written permission. 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 | * 21 | * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.244.2.14 2005/07/10 14:47:57 hannes Exp $ (LBL) 22 | */ 23 | 24 | #ifndef tcpdump_interface_h 25 | #define tcpdump_interface_h 26 | 27 | #ifdef HAVE_OS_PROTO_H 28 | #include "os-proto.h" 29 | #endif 30 | 31 | #ifndef HAVE___ATTRIBUTE__ 32 | #define __attribute__(x) 33 | #endif 34 | 35 | /* snprintf et al */ 36 | 37 | #include 38 | 39 | #if HAVE_STDINT_H 40 | #include 41 | #endif 42 | 43 | #if !defined(HAVE_SNPRINTF) 44 | int snprintf(char *, size_t, const char *, ...) 45 | __attribute__((format(printf, 3, 4))); 46 | #endif 47 | 48 | #if !defined(HAVE_VSNPRINTF) 49 | int vsnprintf(char *, size_t, const char *, va_list) 50 | __attribute__((format(printf, 3, 0))); 51 | #endif 52 | 53 | #ifndef HAVE_STRLCAT 54 | extern size_t strlcat(char *, const char *, size_t); 55 | #endif 56 | #ifndef HAVE_STRLCPY 57 | extern size_t strlcpy(char *, const char *, size_t); 58 | #endif 59 | 60 | #ifndef HAVE_STRDUP 61 | extern char *strdup(const char *); 62 | #endif 63 | 64 | #ifndef HAVE_STRSEP 65 | extern char *strsep(char **, const char *); 66 | #endif 67 | 68 | #define PT_VAT 1 /* Visual Audio Tool */ 69 | #define PT_WB 2 /* distributed White Board */ 70 | #define PT_RPC 3 /* Remote Procedure Call */ 71 | #define PT_RTP 4 /* Real-Time Applications protocol */ 72 | #define PT_RTCP 5 /* Real-Time Applications control protocol */ 73 | #define PT_SNMP 6 /* Simple Network Management Protocol */ 74 | #define PT_CNFP 7 /* Cisco NetFlow protocol */ 75 | #define PT_TFTP 8 /* trivial file transfer protocol */ 76 | #define PT_AODV 9 /* Ad-hoc On-demand Distance Vector Protocol */ 77 | #define PT_DMR 10 /* DMR Repeater protocol */ 78 | 79 | #ifndef min 80 | #define min(a,b) ((a)>(b)?(b):(a)) 81 | #endif 82 | #ifndef max 83 | #define max(a,b) ((b)>(a)?(b):(a)) 84 | #endif 85 | 86 | /* 87 | * The default snapshot length. This value allows most printers to print 88 | * useful information while keeping the amount of unwanted data down. 89 | */ 90 | #ifndef INET6 91 | #define DEFAULT_SNAPLEN 68 /* ether + IPv4 + TCP + 14 */ 92 | #else 93 | #define DEFAULT_SNAPLEN 96 /* ether + IPv6 + TCP + 22 */ 94 | #endif 95 | 96 | #ifndef BIG_ENDIAN 97 | #define BIG_ENDIAN 4321 98 | #define LITTLE_ENDIAN 1234 99 | #endif 100 | 101 | #define ESRC(ep) ((ep)->ether_shost) 102 | #define EDST(ep) ((ep)->ether_dhost) 103 | 104 | #ifndef NTOHL 105 | #define NTOHL(x) (x) = ntohl(x) 106 | #define NTOHS(x) (x) = ntohs(x) 107 | #define HTONL(x) (x) = htonl(x) 108 | #define HTONS(x) (x) = htons(x) 109 | #endif 110 | #endif 111 | 112 | extern char *program_name; /* used to generate self-identifying messages */ 113 | 114 | extern int32_t thiszone; /* seconds offset from gmt to local time */ 115 | 116 | /* 117 | * True if "l" bytes of "var" were captured. 118 | * 119 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large 120 | * that "snapend - (l)" underflows. 121 | * 122 | * The check is for <= rather than < because "l" might be 0. 123 | */ 124 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ 125 | (const u_char *)&(var) <= snapend - (l)) 126 | 127 | /* True if "var" was captured */ 128 | #define TTEST(var) TTEST2(var, sizeof(var)) 129 | 130 | /* Bail if "l" bytes of "var" were not captured */ 131 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc 132 | 133 | /* Bail if "var" was not captured */ 134 | #define TCHECK(var) TCHECK2(var, sizeof(var)) 135 | 136 | extern void ts_print(const struct timeval *); 137 | extern void relts_print(int); 138 | 139 | extern int fn_print(const u_char *, const u_char *); 140 | extern int fn_printn(const u_char *, u_int, const u_char *); 141 | extern int fn_printzp(const u_char *, u_int, const u_char *); 142 | extern int mask2plen(u_int32_t); 143 | extern const char *tok2strary_internal(const char **, int, const char *, int); 144 | #define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i) 145 | 146 | extern const char *dnaddr_string(u_short); 147 | 148 | extern void error(const char *, ...) 149 | __attribute__((noreturn, format (printf, 1, 2))); 150 | extern void warning(const char *, ...) __attribute__ ((format (printf, 1, 2))); 151 | 152 | extern char *read_infile(char *); 153 | extern char *copy_argv(char **); 154 | 155 | extern void safeputchar(int); 156 | extern void safeputs(const char *); 157 | 158 | extern const char *isonsap_string(const u_char *, register u_int); 159 | extern const char *llcsap_string(u_char); 160 | extern const char *protoid_string(const u_char *); 161 | extern const char *ipxsap_string(u_short); 162 | extern const char *dnname_string(u_short); 163 | extern const char *dnnum_string(u_short); 164 | 165 | /* The printer routines. */ 166 | 167 | #include 168 | 169 | extern int print_unknown_data(const u_char *, const char *,int); 170 | extern void ascii_print(const u_char *, u_int); 171 | extern void hex_and_ascii_print_with_offset(const char *, const u_char *, 172 | u_int, u_int); 173 | extern void hex_and_ascii_print(const char *, const u_char *, u_int); 174 | extern void hex_print_with_offset(const char *, const u_char *, u_int, u_int); 175 | extern void dmr_print(const u_char *, u_int); /*DL5DI*/ 176 | extern void hex_print(const char *, const u_char *, u_int); 177 | extern void telnet_print(const u_char *, u_int); 178 | extern int ether_encap_print(u_short, const u_char *, u_int, u_int, u_short *); 179 | extern int llc_print(const u_char *, u_int, u_int, const u_char *, 180 | const u_char *, u_short *); 181 | extern int snap_print(const u_char *, u_int, u_int, u_short *, u_int); 182 | extern void aarp_print(const u_char *, u_int); 183 | extern void aodv_print(const u_char *, u_int, int); 184 | extern void atalk_print(const u_char *, u_int); 185 | extern void atm_print(u_int, u_int, u_int, const u_char *, u_int, u_int); 186 | extern u_int atm_if_print(const struct pcap_pkthdr *, const u_char *); 187 | extern u_int sunatm_if_print(const struct pcap_pkthdr *, const u_char *); 188 | extern int oam_print(const u_char *, u_int, u_int); 189 | extern void bootp_print(const u_char *, u_int); 190 | extern void bgp_print(const u_char *, int); 191 | extern void beep_print(const u_char *, u_int); 192 | extern void cnfp_print(const u_char *, const u_char *); 193 | extern void decnet_print(const u_char *, u_int, u_int); 194 | extern void default_print(const u_char *, u_int); 195 | extern void dvmrp_print(const u_char *, u_int); 196 | extern void egp_print(const u_char *, u_int); 197 | extern u_int enc_if_print(const struct pcap_pkthdr *, const u_char *); 198 | extern u_int pflog_if_print(const struct pcap_pkthdr *, const u_char *); 199 | extern u_int arcnet_if_print(const struct pcap_pkthdr *, const u_char *); 200 | extern u_int arcnet_linux_if_print(const struct pcap_pkthdr *, const u_char *); 201 | extern void ether_print(const u_char *, u_int, u_int); 202 | extern u_int ether_if_print(const struct pcap_pkthdr *, const u_char *); 203 | extern u_int token_print(const u_char *, u_int, u_int); 204 | extern u_int token_if_print(const struct pcap_pkthdr *, const u_char *); 205 | extern void fddi_print(const u_char *, u_int, u_int); 206 | extern u_int fddi_if_print(const struct pcap_pkthdr *, const u_char *); 207 | extern u_int fr_if_print(const struct pcap_pkthdr *, const u_char *); 208 | extern u_int fr_print(register const u_char *, u_int); 209 | extern u_int ieee802_11_if_print(const struct pcap_pkthdr *, const u_char *); 210 | extern u_int ieee802_11_radio_if_print(const struct pcap_pkthdr *, 211 | const u_char *); 212 | extern u_int ap1394_if_print(const struct pcap_pkthdr *, const u_char *); 213 | extern void gre_print(const u_char *, u_int); 214 | extern void icmp_print(const u_char *, u_int, const u_char *, int); 215 | extern void igmp_print(const u_char *, u_int); 216 | extern void igrp_print(const u_char *, u_int, const u_char *); 217 | extern void ipN_print(const u_char *, u_int); 218 | extern u_int ipfc_if_print(const struct pcap_pkthdr *, const u_char *); 219 | extern void ipx_print(const u_char *, u_int); 220 | extern void isoclns_print(const u_char *, u_int, u_int); 221 | extern void krb_print(const u_char *); 222 | extern u_int llap_print(const u_char *, u_int); 223 | extern u_int ltalk_if_print(const struct pcap_pkthdr *, const u_char *); 224 | extern void msdp_print(const unsigned char *, u_int); 225 | extern void nfsreply_print(const u_char *, u_int, const u_char *); 226 | extern void nfsreq_print(const u_char *, u_int, const u_char *); 227 | extern void ns_print(const u_char *, u_int, int); 228 | extern void ntp_print(const u_char *, u_int); 229 | extern u_int null_if_print(const struct pcap_pkthdr *, const u_char *); 230 | extern void ospf_print(const u_char *, u_int, const u_char *); 231 | extern void pimv1_print(const u_char *, u_int); 232 | extern void cisco_autorp_print(const u_char *, u_int); 233 | extern void rsvp_print(const u_char *, u_int); 234 | extern void ldp_print(const u_char *, u_int); 235 | extern void lmp_print(const u_char *, u_int); 236 | extern void lspping_print(const u_char *, u_int); 237 | extern void eigrp_print(const u_char *, u_int); 238 | extern void mobile_print(const u_char *, u_int); 239 | extern void pim_print(const u_char *, u_int); 240 | extern u_int pppoe_print(const u_char *, u_int); 241 | extern u_int ppp_print(register const u_char *, u_int); 242 | extern u_int ppp_if_print(const struct pcap_pkthdr *, const u_char *); 243 | extern u_int ppp_hdlc_if_print(const struct pcap_pkthdr *, const u_char *); 244 | extern u_int ppp_bsdos_if_print(const struct pcap_pkthdr *, const u_char *); 245 | extern u_int pppoe_if_print(const struct pcap_pkthdr *, const u_char *); 246 | extern u_int prism_if_print(const struct pcap_pkthdr *, const u_char *); 247 | extern void q933_print(const u_char *, u_int); 248 | extern int vjc_print(register const char *, u_short); 249 | extern u_int raw_if_print(const struct pcap_pkthdr *, const u_char *); 250 | extern void rip_print(const u_char *, u_int); 251 | extern u_int sl_if_print(const struct pcap_pkthdr *, const u_char *); 252 | extern void lane_print(const u_char *, u_int, u_int); 253 | extern u_int lane_if_print(const struct pcap_pkthdr *, const u_char *); 254 | extern u_int cip_if_print(const struct pcap_pkthdr *, const u_char *); 255 | extern u_int sl_bsdos_if_print(const struct pcap_pkthdr *, const u_char *); 256 | extern u_int chdlc_if_print(const struct pcap_pkthdr *, const u_char *); 257 | extern u_int juniper_atm1_print(const struct pcap_pkthdr *, const u_char *); 258 | extern u_int juniper_atm2_print(const struct pcap_pkthdr *, const u_char *); 259 | extern u_int juniper_mfr_print(const struct pcap_pkthdr *, register const u_char *); 260 | extern u_int juniper_mlfr_print(const struct pcap_pkthdr *, const u_char *); 261 | extern u_int juniper_mlppp_print(const struct pcap_pkthdr *, const u_char *); 262 | extern u_int juniper_pppoe_print(const struct pcap_pkthdr *, const u_char *); 263 | extern u_int juniper_pppoe_atm_print(const struct pcap_pkthdr *, const u_char *); 264 | extern u_int juniper_ggsn_print(const struct pcap_pkthdr *, const u_char *); 265 | extern u_int juniper_es_print(const struct pcap_pkthdr *, const u_char *); 266 | extern u_int juniper_monitor_print(const struct pcap_pkthdr *, const u_char *); 267 | extern u_int juniper_services_print(const struct pcap_pkthdr *, const u_char *); 268 | extern u_int sll_if_print(const struct pcap_pkthdr *, const u_char *); 269 | extern void snmp_print(const u_char *, u_int); 270 | extern void sunrpcrequest_print(const u_char *, u_int, const u_char *); 271 | extern u_int symantec_if_print(const struct pcap_pkthdr *, const u_char *); 272 | extern void tcp_print(const u_char *, u_int, const u_char *, int); 273 | extern void tftp_print(const u_char *, u_int); 274 | extern void timed_print(const u_char *); 275 | extern void udp_print(const u_char *, u_int, const u_char *, int); 276 | extern void wb_print(const void *, u_int); 277 | extern int ah_print(register const u_char *); 278 | extern int ipcomp_print(register const u_char *, int *); 279 | extern void rx_print(register const u_char *, int, int, int, u_char *); 280 | extern void netbeui_print(u_short, const u_char *, int); 281 | extern void ipx_netbios_print(const u_char *, u_int); 282 | extern void nbt_tcp_print(const u_char *, int); 283 | extern void nbt_udp137_print(const u_char *, int); 284 | extern void nbt_udp138_print(const u_char *, int); 285 | extern char *smb_errstr(int, int); 286 | extern const char *nt_errstr(u_int32_t); 287 | extern void print_data(const unsigned char *, int); 288 | extern void l2tp_print(const u_char *, u_int); 289 | extern void vrrp_print(const u_char *, u_int, int); 290 | extern void slow_print(const u_char *, u_int); 291 | extern void pgm_print(const u_char *, u_int, const u_char *); 292 | extern void cdp_print(const u_char *, u_int, u_int); 293 | extern void stp_print(const u_char *, u_int); 294 | extern void radius_print(const u_char *, u_int); 295 | extern void lwres_print(const u_char *, u_int); 296 | extern void pptp_print(const u_char *); 297 | extern void sctp_print(const u_char *, const u_char *, u_int); 298 | extern void mpls_print(const u_char *, u_int); 299 | extern void mpls_lsp_ping_print(const u_char *, u_int); 300 | extern void zephyr_print(const u_char *, int); 301 | extern void hsrp_print(const u_char *, u_int); 302 | extern void bfd_print(const u_char *, u_int, u_int); 303 | extern void sip_print(const u_char *, u_int); 304 | extern void syslog_print(const u_char *, u_int); 305 | 306 | #ifdef INET6 307 | extern void ip6_print(const u_char *, u_int); 308 | extern void ip6_opt_print(const u_char *, int); 309 | extern int hbhopt_print(const u_char *); 310 | extern int dstopt_print(const u_char *); 311 | extern int frag6_print(const u_char *, const u_char *); 312 | extern int mobility_print(const u_char *, const u_char *); 313 | extern void icmp6_print(const u_char *, u_int, const u_char *, int); 314 | extern void ripng_print(const u_char *, unsigned int); 315 | extern int rt6_print(const u_char *, const u_char *); 316 | extern void ospf6_print(const u_char *, u_int); 317 | extern void dhcp6_print(const u_char *, u_int); 318 | #endif /*INET6*/ 319 | extern u_short in_cksum(const u_short *, register u_int, int); 320 | extern u_int16_t in_cksum_shouldbe(u_int16_t, u_int16_t); 321 | 322 | #ifndef HAVE_BPF_DUMP 323 | struct bpf_program; 324 | 325 | extern void bpf_dump(struct bpf_program *, int); 326 | 327 | #endif 328 | 329 | #include "netdissect.h" 330 | 331 | /* forward compatibility */ 332 | 333 | extern netdissect_options *gndo; 334 | 335 | #define eflag gndo->ndo_eflag 336 | #define fflag gndo->ndo_fflag 337 | #define nflag gndo->ndo_nflag 338 | #define Nflag gndo->ndo_Nflag 339 | #define Oflag gndo->ndo_Oflag 340 | #define pflag gndo->ndo_pflag 341 | #define qflag gndo->ndo_qflag 342 | #define Rflag gndo->ndo_Rflag 343 | #define sflag gndo->ndo_sflag 344 | #define Sflag gndo->ndo_Sflag 345 | #define tflag gndo->ndo_tflag 346 | #define Uflag gndo->ndo_Uflag 347 | #define uflag gndo->ndo_uflag 348 | #define vflag gndo->ndo_vflag 349 | #define xflag gndo->ndo_xflag 350 | #define Xflag gndo->ndo_Xflag 351 | #define Cflag gndo->ndo_Cflag 352 | #define Aflag gndo->ndo_Aflag 353 | #define suppress_default_print gndo->ndo_suppress_default_print 354 | #define packettype gndo->ndo_packettype 355 | #define tcpmd5secret gndo->ndo_tcpmd5secret 356 | #define Wflag gndo->ndo_Wflag 357 | #define WflagChars gndo->ndo_WflagChars 358 | #define Cflag_count gndo->ndo_Cflag_count 359 | #define snaplen gndo->ndo_snaplen 360 | #define snapend gndo->ndo_snapend 361 | 362 | /*DL5DI*/ 363 | /* scroll back buffer size to store last heard information */ 364 | #define MAXSTN 20 365 | #define MAXRPTR 50 366 | -------------------------------------------------------------------------------- /DMRmonitor/trbomon_v1.c/netdissect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1988-1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Copyright (c) 1998-2004 Michael Richardson 6 | * The TCPDUMP project 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that: (1) source code distributions 10 | * retain the above copyright notice and this paragraph in its entirety, (2) 11 | * distributions including binary code include the above copyright notice and 12 | * this paragraph in its entirety in the documentation or other materials 13 | * provided with the distribution, and (3) all advertising materials mentioning 14 | * features or use of this software display the following acknowledgement: 15 | * ``This product includes software developed by the University of California, 16 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 17 | * the University nor the names of its contributors may be used to endorse 18 | * or promote products derived from this software without specific prior 19 | * written permission. 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 23 | * 24 | * @(#) $Header: /tcpdump/master/tcpdump/netdissect.h,v 1.16.2.2 2005/07/07 01:24:32 guy Exp $ (LBL) 25 | */ 26 | 27 | #ifndef netdissect_h 28 | #define netdissect_h 29 | 30 | #ifdef HAVE_OS_PROTO_H 31 | #include "os-proto.h" 32 | #endif 33 | #include 34 | 35 | #ifndef HAVE___ATTRIBUTE__ 36 | #define __attribute__(x) 37 | #endif 38 | 39 | /* snprintf et al */ 40 | 41 | #include 42 | 43 | #if !defined(HAVE_SNPRINTF) 44 | int snprintf (char *str, size_t sz, const char *format, ...) 45 | __attribute__ ((format (printf, 3, 4))); 46 | #endif 47 | 48 | #if !defined(HAVE_VSNPRINTF) 49 | int vsnprintf (char *str, size_t sz, const char *format, va_list ap) 50 | __attribute__((format (printf, 3, 0))); 51 | #endif 52 | 53 | #ifndef HAVE_STRLCAT 54 | extern size_t strlcat (char *, const char *, size_t); 55 | #endif 56 | #ifndef HAVE_STRLCPY 57 | extern size_t strlcpy (char *, const char *, size_t); 58 | #endif 59 | 60 | #ifndef HAVE_STRDUP 61 | extern char *strdup (const char *str); 62 | #endif 63 | 64 | #ifndef HAVE_STRSEP 65 | extern char *strsep(char **, const char *); 66 | #endif 67 | 68 | struct tok { 69 | int v; /* value */ 70 | const char *s; /* string */ 71 | }; 72 | 73 | #define TOKBUFSIZE 128 74 | extern const char *tok2strbuf(const struct tok *, const char *, int, 75 | char *buf, size_t bufsize); 76 | 77 | /* tok2str is deprecated */ 78 | extern const char *tok2str(const struct tok *, const char *, int); 79 | extern char *bittok2str(const struct tok *, const char *, int); 80 | 81 | 82 | typedef struct netdissect_options netdissect_options; 83 | 84 | struct netdissect_options { 85 | int ndo_aflag; /* translate network and broadcast addresses */ 86 | int ndo_eflag; /* print ethernet header */ 87 | int ndo_fflag; /* don't translate "foreign" IP address */ 88 | int ndo_nflag; /* leave addresses as numbers */ 89 | int ndo_Nflag; /* remove domains from printed host names */ 90 | int ndo_qflag; /* quick (shorter) output */ 91 | int ndo_Rflag; /* print sequence # field in AH/ESP*/ 92 | int ndo_sflag; /* use the libsmi to translate OIDs */ 93 | int ndo_Sflag; /* print raw TCP sequence numbers */ 94 | int ndo_tflag; /* print packet arrival time */ 95 | int ndo_Uflag; /* "unbuffered" output of dump files */ 96 | int ndo_uflag; /* Print undecoded NFS handles */ 97 | int ndo_vflag; /* verbose */ 98 | int ndo_xflag; /* print packet in hex */ 99 | int ndo_Xflag; /* print packet in hex/ascii */ 100 | int ndo_Aflag; /* print packet only in ascii observing TAB, 101 | * LF, CR and SPACE as graphical chars 102 | */ 103 | int ndo_Oflag; /* run filter code optimizer */ 104 | int ndo_dlt; /* if != -1, ask libpcap for the DLT it names*/ 105 | int ndo_pflag; /* don't go promiscuous */ 106 | 107 | int ndo_Cflag; /* rotate dump files after this many bytes */ 108 | int ndo_Cflag_count; /* Keep track of which file number we're writing */ 109 | int ndo_Wflag; /* recycle output files after this number of files */ 110 | int ndo_WflagChars; 111 | int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */ 112 | const char *ndo_dltname; 113 | 114 | char *ndo_espsecret; 115 | struct sa_list *ndo_sa_list_head; /* used by print-esp.c */ 116 | struct sa_list *ndo_sa_default; 117 | 118 | char *ndo_tcpmd5secret; /* TCP-MD5 secret key */ 119 | 120 | struct esp_algorithm *ndo_espsecret_xform; /* cache of decoded */ 121 | char *ndo_espsecret_key; 122 | 123 | int ndo_packettype; /* as specified by -T */ 124 | 125 | char *ndo_program_name; /*used to generate self-identifying messages */ 126 | 127 | int32_t ndo_thiszone; /* seconds offset from gmt to local time */ 128 | 129 | int ndo_snaplen; 130 | 131 | /*global pointers to beginning and end of current packet (during printing) */ 132 | const u_char *ndo_packetp; 133 | const u_char *ndo_snapend; 134 | 135 | /* bookkeeping for ^T output */ 136 | int ndo_infodelay; 137 | 138 | /* pointer to void function to output stuff */ 139 | void (*ndo_default_print)(netdissect_options *, 140 | register const u_char *bp, register u_int length); 141 | void (*ndo_info)(netdissect_options *, int verbose); 142 | 143 | int (*ndo_printf)(netdissect_options *, 144 | const char *fmt, ...); 145 | void (*ndo_error)(netdissect_options *, 146 | const char *fmt, ...); 147 | void (*ndo_warning)(netdissect_options *, 148 | const char *fmt, ...); 149 | }; 150 | 151 | #define PT_VAT 1 /* Visual Audio Tool */ 152 | #define PT_WB 2 /* distributed White Board */ 153 | #define PT_RPC 3 /* Remote Procedure Call */ 154 | #define PT_RTP 4 /* Real-Time Applications protocol */ 155 | #define PT_RTCP 5 /* Real-Time Applications control protocol */ 156 | #define PT_SNMP 6 /* Simple Network Management Protocol */ 157 | #define PT_CNFP 7 /* Cisco NetFlow protocol */ 158 | #define PT_DMR 10 /* DMR Repeater protocol */ 159 | 160 | #ifndef min 161 | #define min(a,b) ((a)>(b)?(b):(a)) 162 | #endif 163 | #ifndef max 164 | #define max(a,b) ((b)>(a)?(b):(a)) 165 | #endif 166 | 167 | #ifndef INET6 168 | /* 169 | * The default snapshot length. This value allows most printers to print 170 | * useful information while keeping the amount of unwanted data down. 171 | * In particular, it allows for an ethernet header, tcp/ip header, and 172 | * 14 bytes of data (assuming no ip options). 173 | */ 174 | #define DEFAULT_SNAPLEN 68 175 | #else 176 | #define DEFAULT_SNAPLEN 96 177 | #endif 178 | 179 | #ifndef BIG_ENDIAN 180 | #define BIG_ENDIAN 4321 181 | #define LITTLE_ENDIAN 1234 182 | #endif 183 | 184 | #define ESRC(ep) ((ep)->ether_shost) 185 | #define EDST(ep) ((ep)->ether_dhost) 186 | 187 | #ifndef NTOHL 188 | #define NTOHL(x) (x) = ntohl(x) 189 | #define NTOHS(x) (x) = ntohs(x) 190 | #define HTONL(x) (x) = htonl(x) 191 | #define HTONS(x) (x) = htons(x) 192 | #endif 193 | 194 | /* 195 | * True if "l" bytes of "var" were captured. 196 | * 197 | * The "ndo->ndo_snapend - (l) <= ndo->ndo_snapend" checks to make sure 198 | * "l" isn't so large that "ndo->ndo_snapend - (l)" underflows. 199 | * 200 | * The check is for <= rather than < because "l" might be 0. 201 | */ 202 | #define ND_TTEST2(var, l) (ndo->ndo_snapend - (l) <= ndo->ndo_snapend && \ 203 | (const u_char *)&(var) <= ndo->ndo_snapend - (l)) 204 | 205 | /* True if "var" was captured */ 206 | #define ND_TTEST(var) ND_TTEST2(var, sizeof(var)) 207 | 208 | /* Bail if "l" bytes of "var" were not captured */ 209 | #define ND_TCHECK2(var, l) if (!ND_TTEST2(var, l)) goto trunc 210 | 211 | /* Bail if "var" was not captured */ 212 | #define ND_TCHECK(var) ND_TCHECK2(var, sizeof(var)) 213 | 214 | #define ND_PRINT(STUFF) (*ndo->ndo_printf)STUFF 215 | #define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length) 216 | 217 | #if 0 218 | extern void ts_print(netdissect_options *ipdo, 219 | const struct timeval *); 220 | extern void relts_print(int); 221 | #endif 222 | 223 | extern int fn_print(const u_char *, const u_char *); 224 | extern int fn_printn(const u_char *, u_int, const u_char *); 225 | extern const char *tok2str(const struct tok *, const char *, int); 226 | 227 | extern void wrapup(int); 228 | 229 | #if 0 230 | extern char *read_infile(netdissect_options *, char *); 231 | extern char *copy_argv(netdissect_options *, char **); 232 | #endif 233 | 234 | extern void safeputchar(int); 235 | extern void safeputs(const char *); 236 | 237 | #if 0 238 | extern const char *isonsap_string(netdissect_options *, const u_char *); 239 | extern const char *llcsap_string(netdissect_options *, u_char); 240 | extern const char *protoid_string(netdissect_options *, const u_char *); 241 | extern const char *dnname_string(netdissect_options *, u_short); 242 | extern const char *dnnum_string(netdissect_options *, u_short); 243 | #endif 244 | 245 | /* The printer routines. */ 246 | 247 | #include 248 | 249 | 250 | extern void eap_print(netdissect_options *,const u_char *, u_int); 251 | extern int esp_print(netdissect_options *, 252 | register const u_char *bp, int len, register const u_char *bp2, 253 | int *nhdr, int *padlen); 254 | extern void arp_print(netdissect_options *,const u_char *, u_int, u_int); 255 | extern void isakmp_print(netdissect_options *,const u_char *, 256 | u_int, const u_char *); 257 | extern void isakmp_rfc3948_print(netdissect_options *,const u_char *, 258 | u_int, const u_char *); 259 | extern void ip_print(netdissect_options *,const u_char *, u_int); 260 | extern void ip_print_inner(netdissect_options *ndo, 261 | const u_char *bp, u_int length, u_int nh, 262 | const u_char *bp2); 263 | 264 | /* stuff that has not yet been rototiled */ 265 | #if 0 266 | extern void ascii_print(netdissect_options *,u_int); 267 | extern void hex_and_ascii_print_with_offset(netdissect_options *,const char *, 268 | u_int, u_int); 269 | extern void hex_and_ascii_print(netdissect_options *,const char *, u_int); 270 | extern void hex_print_with_offset(netdissect_options *,const char *, u_int, u_int); 271 | extern void hex_print(netdissect_options *,const char *, u_int); 272 | extern void dmr_print(const char *, u_int); /*DL5DI*/ 273 | extern void telnet_print(netdissect_options *,const u_char *, u_int); 274 | extern int ether_encap_print(netdissect_options *,u_short, const u_char *, 275 | u_int, u_int, u_short *); 276 | extern int llc_print(netdissect_options *, 277 | const u_char *, u_int, u_int, const u_char *, 278 | const u_char *, u_short *); 279 | extern void aarp_print(netdissect_options *,const u_char *, u_int); 280 | extern void atalk_print(netdissect_options *,const u_char *, u_int); 281 | extern void atm_if_print(u_char *,const struct pcap_pkthdr *, const u_char *); 282 | extern void bootp_print(netdissect_options *,const u_char *, 283 | u_int, u_short, u_short); 284 | extern void bgp_print(netdissect_options *,const u_char *, int); 285 | extern void bxxp_print(netdissect_options *,const u_char *, u_int); 286 | extern void chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, 287 | register const u_char *p); 288 | extern void chdlc_print(netdissect_options *ndo, 289 | register const u_char *p, u_int length, u_int caplen); 290 | extern void cisco_autorp_print(netdissect_options *, 291 | const u_char *, u_int); 292 | extern void cnfp_print(netdissect_options *,const u_char *cp, 293 | u_int len, const u_char *bp); 294 | extern void decnet_print(netdissect_options *,const u_char *, 295 | u_int, u_int); 296 | extern void default_print(netdissect_options *,const u_char *, u_int); 297 | extern void dvmrp_print(netdissect_options *,const u_char *, u_int); 298 | extern void egp_print(netdissect_options *,const u_char *, u_int, 299 | const u_char *); 300 | 301 | extern void arcnet_if_print(u_char*,const struct pcap_pkthdr *,const u_char *); 302 | extern void ether_if_print(u_char *,const struct pcap_pkthdr *,const u_char *); 303 | extern void token_if_print(u_char *,const struct pcap_pkthdr *,const u_char *); 304 | extern void fddi_if_print(u_char *,const struct pcap_pkthdr *, const u_char *); 305 | 306 | extern void gre_print(netdissect_options *,const u_char *, u_int); 307 | extern void icmp_print(netdissect_options *,const u_char *, u_int, 308 | const u_char *); 309 | extern void hsrp_print(netdissect_options *ndo, 310 | register const u_char *bp, register u_int len); 311 | extern void ieee802_11_if_print(u_char *,const struct pcap_pkthdr *, const u_char *); 312 | extern void igmp_print(netdissect_options *, 313 | register const u_char *, u_int); 314 | extern void igrp_print(netdissect_options *,const u_char *, u_int, 315 | const u_char *); 316 | extern void ipN_print(netdissect_options *,const u_char *, u_int); 317 | extern void ipx_print(netdissect_options *,const u_char *, u_int); 318 | extern void isoclns_print(netdissect_options *,const u_char *, 319 | u_int, u_int, const u_char *, const u_char *); 320 | extern void krb_print(netdissect_options *,const u_char *, u_int); 321 | extern void llap_print(netdissect_options *,const u_char *, u_int); 322 | extern const char *linkaddr_string(netdissect_options *ndo, 323 | const u_char *ep, const unsigned int len); 324 | extern void ltalk_if_print(netdissect_options *ndo, 325 | u_char *user, const struct pcap_pkthdr *h, 326 | const u_char *p); 327 | extern void mpls_print(netdissect_options *ndo, 328 | const u_char *bp, u_int length); 329 | extern void msdp_print(netdissect_options *ndo, 330 | const unsigned char *sp, u_int length); 331 | extern void nfsreply_print(netdissect_options *,const u_char *, 332 | u_int, const u_char *); 333 | extern void nfsreq_print(netdissect_options *,const u_char *, 334 | u_int, const u_char *); 335 | extern void ns_print(netdissect_options *,const u_char *, u_int); 336 | extern void ntp_print(netdissect_options *,const u_char *, u_int); 337 | extern void null_if_print(u_char *,const struct pcap_pkthdr *, const u_char *); 338 | extern void ospf_print(netdissect_options *,const u_char *, 339 | u_int, const u_char *); 340 | extern void pimv1_print(netdissect_options *,const u_char *, u_int); 341 | extern void mobile_print(netdissect_options *,const u_char *, u_int); 342 | extern void pim_print(netdissect_options *,const u_char *, u_int); 343 | extern void pppoe_if_print(u_char *,const struct pcap_pkthdr *, const u_char *); 344 | extern void pppoe_print(netdissect_options *,const u_char *, u_int); 345 | extern void ppp_print(netdissect_options *, 346 | register const u_char *, u_int); 347 | 348 | extern void ppp_if_print(u_char *,const struct pcap_pkthdr *, const u_char *); 349 | extern void ppp_hdlc_if_print(u_char *, 350 | const struct pcap_pkthdr *, const u_char *); 351 | extern void ppp_bsdos_if_print(u_char *, 352 | const struct pcap_pkthdr *, const u_char *); 353 | 354 | extern int vjc_print(netdissect_options *,register const char *, 355 | register u_int, u_short); 356 | 357 | extern void raw_if_print(u_char *, 358 | const struct pcap_pkthdr *, const u_char *); 359 | 360 | extern void rip_print(netdissect_options *,const u_char *, u_int); 361 | 362 | extern void sctp_print(netdissect_options *ndo, 363 | const u_char *bp, const u_char *bp2, 364 | u_int sctpPacketLength); 365 | 366 | extern void sl_if_print(u_char *,const struct pcap_pkthdr *, const u_char *); 367 | 368 | extern void lane_if_print(u_char *,const struct pcap_pkthdr *,const u_char *); 369 | extern void cip_if_print(u_char *,const struct pcap_pkthdr *,const u_char *); 370 | extern void sl_bsdos_if_print(u_char *, 371 | const struct pcap_pkthdr *, const u_char *); 372 | extern void sll_if_print(u_char *, 373 | const struct pcap_pkthdr *, const u_char *); 374 | 375 | extern void snmp_print(netdissect_options *,const u_char *, u_int); 376 | extern void sunrpcrequest_print(netdissect_options *,const u_char *, 377 | u_int, const u_char *); 378 | extern void tcp_print(netdissect_options *,const u_char *, u_int, 379 | const u_char *, int); 380 | extern void tftp_print(netdissect_options *,const u_char *, u_int); 381 | extern void timed_print(netdissect_options *,const u_char *, u_int); 382 | extern void udp_print(netdissect_options *,const u_char *, u_int, 383 | const u_char *, int); 384 | extern void wb_print(netdissect_options *,const void *, u_int); 385 | extern int ah_print(netdissect_options *,register const u_char *, 386 | register const u_char *); 387 | extern void esp_print_decodesecret(netdissect_options *ndo); 388 | extern int ipcomp_print(netdissect_options *,register const u_char *, 389 | register const u_char *, int *); 390 | extern void rx_print(netdissect_options *,register const u_char *, 391 | int, int, int, u_char *); 392 | extern void netbeui_print(netdissect_options *,u_short, 393 | const u_char *, int); 394 | extern void ipx_netbios_print(netdissect_options *,const u_char *, u_int); 395 | extern void nbt_tcp_print(netdissect_options *,const u_char *, int); 396 | extern void nbt_udp137_print(netdissect_options *, 397 | const u_char *data, int); 398 | extern void nbt_udp138_print(netdissect_options *, 399 | const u_char *data, int); 400 | extern char *smb_errstr(netdissect_options *,int, int); 401 | extern const char *nt_errstr(netdissect_options *, u_int32_t); 402 | extern void print_data(netdissect_options *,const unsigned char *, int); 403 | extern void l2tp_print(netdissect_options *,const u_char *, u_int); 404 | extern void lcp_print(netdissect_options *,const u_char *, u_int); 405 | extern void vrrp_print(netdissect_options *,const u_char *bp, 406 | u_int len, int ttl); 407 | extern void cdp_print(netdissect_options *,const u_char *, 408 | u_int, u_int, const u_char *, const u_char *); 409 | extern void stp_print(netdissect_options *,const u_char *p, u_int length); 410 | extern void radius_print(netdissect_options *,const u_char *, u_int); 411 | extern void lwres_print(netdissect_options *,const u_char *, u_int); 412 | extern void pptp_print(netdissect_options *,const u_char *, u_int); 413 | 414 | #ifdef INET6 415 | extern void ip6_print(netdissect_options *,const u_char *, u_int); 416 | extern void ip6_opt_print(netdissect_options *,const u_char *, int); 417 | extern int hbhopt_print(netdissect_options *,const u_char *); 418 | extern int dstopt_print(netdissect_options *,const u_char *); 419 | extern int frag6_print(netdissect_options *,const u_char *, 420 | const u_char *); 421 | extern void icmp6_print(netdissect_options *,const u_char *, 422 | const u_char *); 423 | extern void ripng_print(netdissect_options *,const u_char *, int); 424 | extern int rt6_print(netdissect_options *,const u_char *, const u_char *); 425 | extern void ospf6_print(netdissect_options *,const u_char *, u_int); 426 | extern void dhcp6_print(netdissect_options *,const u_char *, 427 | u_int, u_int16_t, u_int16_t); 428 | 429 | extern void zephyr_print(netdissect_options * ndo, 430 | const u_char *cp, int length); 431 | 432 | #endif /*INET6*/ 433 | extern u_short in_cksum(const u_short *, 434 | register u_int, int); 435 | 436 | #endif 437 | 438 | #endif /* netdissect_h */ 439 | -------------------------------------------------------------------------------- /DMRmonitor/trbomon_v1.c/print-ascii.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: print-ascii.c,v 1.1 1999/09/30 14:49:12 sjg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Alan Barrett and Simon J. Gerraty. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed by the NetBSD 21 | * Foundation, Inc. and its contributors. 22 | * 4. Neither the name of The NetBSD Foundation nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifdef HAVE_CONFIG_H 40 | #include "config.h" 41 | #endif 42 | 43 | #ifndef lint 44 | static const char rcsid[] _U_ = 45 | "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.16.2.1 2005/07/06 20:54:49 guy Exp $"; 46 | #endif 47 | #include 48 | #include 49 | 50 | #include "interface.h" 51 | 52 | #define ASCII_LINELENGTH 300 53 | #define HEXDUMP_BYTES_PER_LINE 16 54 | #define HEXDUMP_SHORTS_PER_LINE (HEXDUMP_BYTES_PER_LINE / 2) 55 | #define HEXDUMP_HEXSTUFF_PER_SHORT 5 /* 4 hex digits and a space */ 56 | #define HEXDUMP_HEXSTUFF_PER_LINE \ 57 | (HEXDUMP_HEXSTUFF_PER_SHORT * HEXDUMP_SHORTS_PER_LINE) 58 | 59 | void 60 | ascii_print(register const u_char *cp, register u_int length) 61 | { 62 | register int s; 63 | 64 | putchar('\n'); 65 | while (length > 0) { 66 | s = *cp++; 67 | length--; 68 | if (!isgraph(s) && 69 | (s != '\t' && s != ' ' && s != '\n' && s != '\r')) 70 | putchar('.'); 71 | else 72 | putchar(s); 73 | } 74 | } 75 | 76 | void 77 | hex_and_ascii_print_with_offset(register const char *ident, 78 | register const u_char *cp, register u_int length, register u_int oset) 79 | { 80 | register u_int i; 81 | register int s1, s2; 82 | register int nshorts; 83 | char hexstuff[HEXDUMP_SHORTS_PER_LINE*HEXDUMP_HEXSTUFF_PER_SHORT+1], *hsp; 84 | char asciistuff[ASCII_LINELENGTH+1], *asp; 85 | 86 | nshorts = length / sizeof(u_short); 87 | i = 0; 88 | hsp = hexstuff; asp = asciistuff; 89 | while (--nshorts >= 0) { 90 | s1 = *cp++; 91 | s2 = *cp++; 92 | (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff), 93 | " %02x%02x", s1, s2); 94 | hsp += HEXDUMP_HEXSTUFF_PER_SHORT; 95 | *(asp++) = (isgraph(s1) ? s1 : '.'); 96 | *(asp++) = (isgraph(s2) ? s2 : '.'); 97 | i++; 98 | if (i >= HEXDUMP_SHORTS_PER_LINE) { 99 | *hsp = *asp = '\0'; 100 | (void)printf("%s0x%04x: %-*s %s", 101 | ident, oset, HEXDUMP_HEXSTUFF_PER_LINE, 102 | hexstuff, asciistuff); 103 | i = 0; hsp = hexstuff; asp = asciistuff; 104 | oset += HEXDUMP_BYTES_PER_LINE; 105 | } 106 | } 107 | if (length & 1) { 108 | s1 = *cp++; 109 | (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff), 110 | " %02x", s1); 111 | hsp += 3; 112 | *(asp++) = (isgraph(s1) ? s1 : '.'); 113 | ++i; 114 | } 115 | if (i > 0) { 116 | *hsp = *asp = '\0'; 117 | (void)printf("%s0x%04x: %-*s %s", 118 | ident, oset, HEXDUMP_HEXSTUFF_PER_LINE, 119 | hexstuff, asciistuff); 120 | } 121 | } 122 | 123 | void 124 | hex_and_ascii_print(register const char *ident, register const u_char *cp, 125 | register u_int length) 126 | { 127 | hex_and_ascii_print_with_offset(ident, cp, length, 0); 128 | } 129 | 130 | /* 131 | * telnet_print() wants this. It is essentially default_print_unaligned() 132 | */ 133 | void 134 | hex_print_with_offset(register const char *ident, register const u_char *cp, register u_int length, 135 | register u_int oset) 136 | { 137 | register u_int i, s; 138 | register int nshorts; 139 | 140 | nshorts = (u_int) length / sizeof(u_short); 141 | i = 0; 142 | while (--nshorts >= 0) { 143 | if ((i++ % 8) == 0) { 144 | (void)printf("%s0x%04x: ", ident, oset); 145 | oset += HEXDUMP_BYTES_PER_LINE; 146 | } 147 | s = *cp++; 148 | (void)printf(" %02x%02x", s, *cp++); 149 | } 150 | if (length & 1) { 151 | if ((i % 8) == 0) 152 | (void)printf("%s0x%04x: ", ident, oset); 153 | (void)printf(" %02x", *cp); 154 | } 155 | } 156 | 157 | /* 158 | * just for completeness 159 | */ 160 | void 161 | hex_print(register const char *ident, register const u_char *cp, register u_int length) 162 | { 163 | hex_print_with_offset(ident, cp, length, 0); 164 | } 165 | 166 | 167 | /*DL5DI=>*/ 168 | 169 | /* 170 | * prepare DMR header for transmission to DMR-Monitor Server 171 | */ 172 | void 173 | dmr_print(register const u_char *cp, register u_int length) 174 | { 175 | register u_int i, s; 176 | register int nshorts; 177 | 178 | char buffer[10]; 179 | long rid, srcid, destid, value; 180 | int j, port; 181 | time_t Time; 182 | struct tm * tm; 183 | extern int ts; 184 | extern long rptrid[2], rptrid0[2][MAXSTN]; 185 | extern int seqnr[2], seqnr0[2][MAXSTN]; 186 | extern time_t lh[MAXRPTR]; 187 | extern long usrid[MAXRPTR]; 188 | 189 | nshorts = (u_int) length / sizeof(u_short); 190 | i = 0; 191 | 192 | Time = time(NULL); 193 | tm = gmtime (&Time); 194 | sprintf(buffer,"%02x%02x",*(cp+22),*(cp+23)); 195 | port = strtol(buffer,NULL,16); /*DestPort*/ 196 | 197 | cp += 28; 198 | 199 | if((*cp >= 150) && (*cp <= 153) && (length > 33)){ 200 | /* Master keep-alive-request: 96h / 150 */ 201 | /* Master keep-alive-response: 97h / 151 */ 202 | /* Peer keep-alive-request: 98h / 152 */ 203 | /* Peer keep-alive-response: 99h / 153 */ 204 | 205 | sprintf(buffer,"%02x%02x%02x%02x",*(cp+1),*(cp+2),*(cp+3),*(cp+4)); 206 | rid = strtol(buffer,NULL,16); /*RptrID*/ 207 | 208 | for(j = 0; j < MAXRPTR; j++){ 209 | if((usrid[j] == rid) && (time(NULL) < lh[j] + 60)){ 210 | j = MAXRPTR+1; /* rptr was active within last 60 sec, no update required */ 211 | } 212 | } 213 | 214 | if(j <= MAXRPTR){ 215 | for(j = 0; j < (MAXRPTR-1); j++){ 216 | usrid[j] = usrid[j+1]; 217 | lh[j] = lh[j+1]; 218 | } 219 | 220 | usrid[MAXRPTR-1] = rid; 221 | lh[MAXRPTR-1] = time(NULL); 222 | 223 | printf("%04d-%02d-%02d",tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); 224 | printf(" %02d:%02d:%02d",tm->tm_hour, tm->tm_min, tm->tm_sec); 225 | printf(" %d", port); 226 | 227 | /* oct 0-1: */ 228 | (void)printf(" %02x",*cp); /*H: format id, L: A/GI*/ 229 | 230 | /* oct 1-4: repeater-id: */ 231 | (void)printf(" %ld",rid); /*RptrID*/ 232 | 233 | /* oct 5 */ 234 | (void)printf(" %02x\n",*(cp+5)); 235 | } 236 | 237 | } else if((*cp >= 128) && (*cp < 133) && (length > 57)){ /* >80h <85h */ 238 | 239 | /* header of voice frames */ 240 | 241 | /* octed 17 / bit 32: timeslot */ 242 | ts = *(cp+17) && 32; 243 | 244 | /* oct 1-4: repeater-id: */ 245 | sprintf(buffer,"%02x%02x%02x%02x",*(cp+1),*(cp+2),*(cp+3),*(cp+4)); 246 | rptrid[ts] = strtol(buffer,NULL,16); /*RptrID*/ 247 | 248 | /* octed 5: sequence number: */ 249 | sprintf(buffer,"%d",*(cp+5)); /*SeqNr*/ 250 | seqnr[ts]=atoi(buffer); 251 | 252 | /* check fifo buffer of last 20 stations on this timeslot */ 253 | for(j=0; j < MAXSTN; j++){ 254 | if((rptrid[ts] == rptrid0[ts][j]) && (seqnr[ts] == seqnr0[ts][j])) 255 | j = MAXSTN+1; /* found */ 256 | } 257 | 258 | if(j <= MAXSTN){ 259 | /* remove oldest and add new entry at the end of fifo buffer */ 260 | for(j=0; j < (MAXSTN-1); j++){ 261 | rptrid0[ts][j] = rptrid0[ts][j+1]; 262 | seqnr0[ts][j] = seqnr0[ts][j+1]; 263 | } 264 | rptrid0[ts][MAXSTN-1] = rptrid[ts]; 265 | seqnr0[ts][MAXSTN-1] = seqnr[ts]; 266 | 267 | printf("%04d-%02d-%02d",tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); 268 | printf(" %02d:%02d:%02d",tm->tm_hour, tm->tm_min, tm->tm_sec); 269 | printf(" %d", port); 270 | 271 | /* oct 0: */ 272 | (void)printf(" %02x",*cp); /*H: format id, L: A/GI*/ 273 | 274 | /* oct 6-8: source-id: */ 275 | sprintf(buffer,"%02x%02x%02x",*(cp+6),*(cp+7),*(cp+8)); 276 | srcid = strtol(buffer,NULL,16); /*SrcID*/ 277 | 278 | /* oct 9-11: destination-id: */ 279 | sprintf(buffer,"%02x%02x%02x",*(cp+9),*(cp+10),*(cp+11)); 280 | destid = strtol(buffer,NULL,16); /*DstID*/ 281 | 282 | (void)printf(" %ld",rptrid[ts]); /*RptrID*/ 283 | (void)printf(" %d",seqnr[ts]); /*SeqNr*/ 284 | (void)printf(" %ld",srcid); /*SrcID*/ 285 | (void)printf(" %ld",destid); /*DstID*/ 286 | 287 | /* oct 12: */ 288 | (void)printf(" %02x",*(cp+12)); /*prio - voice/data*/ 289 | 290 | /* oct 13-16: ctrl flags: */ 291 | (void)printf(" %02x%02x%02x%02x",*(cp+13),*(cp+14),*(cp+15),*(cp+16)); 292 | 293 | /* oct 17: CallControlInfo */ 294 | (void)printf(" %02x",*(cp+17)); 295 | 296 | /* oct 18: ContribSrcID */ 297 | (void)printf(" %02x",*(cp+18)); 298 | 299 | /* oct 19: PayloadType*/ 300 | (void)printf(" %02x",*(cp+19)); 301 | 302 | /* oct 20-21: sequence number: */ 303 | sprintf(buffer,"%02x%02x",*(cp+20),*(cp+21)); 304 | value = strtol(buffer,NULL,16); /*Sequence number*/ 305 | (void)printf(" %ld",value); 306 | 307 | /* oct 22-25: timestamp: */ 308 | (void)printf(" %02x%02x%02x%02x",*(cp+22),*(cp+23),*(cp+24),*(cp+25)); 309 | 310 | /* oct 26-29: SyncSrcID: */ 311 | sprintf(buffer,"%02x%02x%02x%02x",*(cp+26),*(cp+27),*(cp+28),*(cp+29)); 312 | value = strtol(buffer,NULL,16); 313 | (void)printf(" %ld",value); 314 | 315 | /* oct 30: DataTypeVoiceHeader */ 316 | (void)printf(" %02x",*(cp+30)); 317 | 318 | /* oct 31: RSSI/threshold and parity values */ 319 | (void)printf(" %02x",*(cp+31)); 320 | 321 | /* oct 32-33: */ 322 | sprintf(buffer,"%02x%02x",*(cp+32),*(cp+33)); 323 | value = strtol(buffer,NULL,16); /* length to follow (words) */ 324 | (void)printf(" %ld",value); 325 | 326 | /* oct 34: RSSI status */ 327 | (void)printf(" %02x",*(cp+34)); 328 | 329 | /* oct 35: slot type / Sync */ 330 | (void)printf(" %02x",*(cp+35)); 331 | 332 | /* oct 36-37: */ 333 | sprintf(buffer,"%02x%02x",*(cp+36),*(cp+37)); 334 | value = strtol(buffer,NULL,16); /* data size */ 335 | (void)printf(" %ld",value); 336 | 337 | (void)printf("\r\n"); 338 | } 339 | } 340 | } 341 | 342 | /*<=DL5DI*/ 343 | 344 | 345 | #ifdef MAIN 346 | int 347 | main(int argc, char *argv[]) 348 | { 349 | hex_print("\n\t", "Hello, World!\n", 14); 350 | printf("\n"); 351 | hex_and_ascii_print("\n\t", "Hello, World!\n", 14); 352 | printf("\n"); 353 | ascii_print("Hello, World!\n", 14); 354 | printf("\n"); 355 | #define TMSG "Now is the winter of our discontent...\n" 356 | hex_print_with_offset("\n\t", TMSG, sizeof(TMSG) - 1, 0x100); 357 | printf("\n"); 358 | hex_and_ascii_print_with_offset("\n\t", TMSG, sizeof(TMSG) - 1, 0x100); 359 | printf("\n"); 360 | exit(0); 361 | } 362 | #endif /* MAIN */ 363 | -------------------------------------------------------------------------------- /DMRmonitor/trbomon_v1.c/tcpdump.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that: (1) source code distributions 7 | * retain the above copyright notice and this paragraph in its entirety, (2) 8 | * distributions including binary code include the above copyright notice and 9 | * this paragraph in its entirety in the documentation or other materials 10 | * provided with the distribution, and (3) all advertising materials mentioning 11 | * features or use of this software display the following acknowledgement: 12 | * ``This product includes software developed by the University of California, 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 | * the University nor the names of its contributors may be used to endorse 15 | * or promote products derived from this software without specific prior 16 | * written permission. 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 | * 21 | * Support for splitting captures into multiple files with a maximum 22 | * file size: 23 | * 24 | * Copyright (c) 2001 25 | * Seth Webster 26 | */ 27 | 28 | #ifndef lint 29 | static const char copyright[] _U_ = 30 | "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\ 31 | The Regents of the University of California. All rights reserved.\n"; 32 | static const char rcsid[] _U_ = 33 | "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.253.2.10 2005/07/07 01:24:40 guy Exp $ (LBL)"; 34 | #endif 35 | 36 | /* 37 | * tcpdump - monitor tcp/ip traffic on an ethernet. 38 | * 39 | * First written in 1987 by Van Jacobson, Lawrence Berkeley Laboratory. 40 | * Mercilessly hacked and occasionally improved since then via the 41 | * combined efforts of Van, Steve McCanne and Craig Leres of LBL. 42 | */ 43 | 44 | #ifdef HAVE_CONFIG_H 45 | #include "config.h" 46 | #endif 47 | 48 | #include 49 | 50 | #ifdef WIN32 51 | #include "getopt.h" 52 | #include "w32_fzs.h" 53 | extern int strcasecmp (const char *__s1, const char *__s2); 54 | extern int SIZE_BUF; 55 | #define off_t long 56 | #define uint UINT 57 | #endif /* WIN32 */ 58 | 59 | #ifdef HAVE_SMI_H 60 | #include 61 | #endif 62 | 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #ifndef WIN32 69 | #include 70 | #include 71 | #include 72 | #endif /* WIN32 */ 73 | 74 | #include "netdissect.h" 75 | #include "interface.h" 76 | #include "addrtoname.h" 77 | #include "machdep.h" 78 | #include "setsignal.h" 79 | #include "gmt2local.h" 80 | #include "pcap-missing.h" 81 | #include "time.h" 82 | 83 | /* DL5DI => */ 84 | 85 | int ts; 86 | long rptrid[2], rptrid0[2][MAXSTN]; 87 | int seqnr[2], seqnr0[2][MAXSTN]; 88 | time_t lh[MAXRPTR]; 89 | long usrid[MAXRPTR]; 90 | 91 | /* <= DL5DI */ 92 | 93 | 94 | netdissect_options Gndo; 95 | netdissect_options *gndo = &Gndo; 96 | 97 | /* 98 | * Define the maximum number of files for the -C flag, and how many 99 | * characters can be added to a filename for the -C flag (which 100 | * should be enough to handle MAX_CFLAG - 1). 101 | */ 102 | #define MAX_CFLAG 1000000 103 | #define MAX_CFLAG_CHARS 6 104 | 105 | int dflag; /* print filter code */ 106 | int Lflag; /* list available data link types and exit */ 107 | 108 | static int infodelay; 109 | static int infoprint; 110 | 111 | char *program_name; 112 | 113 | int32_t thiszone; /* seconds offset from gmt to local time */ 114 | 115 | /* Forwards */ 116 | static RETSIGTYPE cleanup(int); 117 | static void usage(void) __attribute__((noreturn)); 118 | static void show_dlts_and_exit(pcap_t *pd) __attribute__((noreturn)); 119 | 120 | static void print_packet(u_char *, const struct pcap_pkthdr *, const u_char *); 121 | static void ndo_default_print(netdissect_options *, const u_char *, u_int); 122 | static void dump_packet_and_trunc(u_char *, const struct pcap_pkthdr *, const u_char *); 123 | static void dump_packet(u_char *, const struct pcap_pkthdr *, const u_char *); 124 | static void droproot(const char *, const char *); 125 | static void ndo_error(netdissect_options *ndo, const char *fmt, ...); 126 | static void ndo_warning(netdissect_options *ndo, const char *fmt, ...); 127 | 128 | #ifdef SIGINFO 129 | RETSIGTYPE requestinfo(int); 130 | #endif 131 | 132 | #if defined(USE_WIN32_MM_TIMER) 133 | #include 134 | static UINT timer_id; 135 | static void CALLBACK verbose_stats_dump(UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR); 136 | #elif defined(HAVE_ALARM) 137 | static void verbose_stats_dump(int sig); 138 | #endif 139 | 140 | static void info(int); 141 | static u_int packets_captured; 142 | 143 | typedef u_int (*if_printer)(const struct pcap_pkthdr *, const u_char *); 144 | 145 | struct printer { 146 | if_printer f; 147 | int type; 148 | }; 149 | 150 | static struct printer printers[] = { 151 | { arcnet_if_print, DLT_ARCNET }, 152 | #ifdef DLT_ARCNET_LINUX 153 | { arcnet_linux_if_print, DLT_ARCNET_LINUX }, 154 | #endif 155 | { ether_if_print, DLT_EN10MB }, 156 | { token_if_print, DLT_IEEE802 }, 157 | #ifdef DLT_LANE8023 158 | { lane_if_print, DLT_LANE8023 }, 159 | #endif 160 | #ifdef DLT_CIP 161 | { cip_if_print, DLT_CIP }, 162 | #endif 163 | #ifdef DLT_ATM_CLIP 164 | { cip_if_print, DLT_ATM_CLIP }, 165 | #endif 166 | { sl_if_print, DLT_SLIP }, 167 | #ifdef DLT_SLIP_BSDOS 168 | { sl_bsdos_if_print, DLT_SLIP_BSDOS }, 169 | #endif 170 | { ppp_if_print, DLT_PPP }, 171 | #ifdef DLT_PPP_WITHDIRECTION 172 | { ppp_if_print, DLT_PPP_WITHDIRECTION }, 173 | #endif 174 | #ifdef DLT_PPP_BSDOS 175 | { ppp_bsdos_if_print, DLT_PPP_BSDOS }, 176 | #endif 177 | { fddi_if_print, DLT_FDDI }, 178 | { null_if_print, DLT_NULL }, 179 | #ifdef DLT_LOOP 180 | { null_if_print, DLT_LOOP }, 181 | #endif 182 | { raw_if_print, DLT_RAW }, 183 | { atm_if_print, DLT_ATM_RFC1483 }, 184 | #ifdef DLT_C_HDLC 185 | { chdlc_if_print, DLT_C_HDLC }, 186 | #endif 187 | #ifdef DLT_HDLC 188 | { chdlc_if_print, DLT_HDLC }, 189 | #endif 190 | #ifdef DLT_PPP_SERIAL 191 | { ppp_hdlc_if_print, DLT_PPP_SERIAL }, 192 | #endif 193 | #ifdef DLT_PPP_ETHER 194 | { pppoe_if_print, DLT_PPP_ETHER }, 195 | #endif 196 | #ifdef DLT_LINUX_SLL 197 | { sll_if_print, DLT_LINUX_SLL }, 198 | #endif 199 | #ifdef DLT_IEEE802_11 200 | { ieee802_11_if_print, DLT_IEEE802_11}, 201 | #endif 202 | #ifdef DLT_LTALK 203 | { ltalk_if_print, DLT_LTALK }, 204 | #endif 205 | #ifdef DLT_PFLOG 206 | { pflog_if_print, DLT_PFLOG }, 207 | #endif 208 | #ifdef DLT_FR 209 | { fr_if_print, DLT_FR }, 210 | #endif 211 | #ifdef DLT_FRELAY 212 | { fr_if_print, DLT_FRELAY }, 213 | #endif 214 | #ifdef DLT_SUNATM 215 | { sunatm_if_print, DLT_SUNATM }, 216 | #endif 217 | #ifdef DLT_IP_OVER_FC 218 | { ipfc_if_print, DLT_IP_OVER_FC }, 219 | #endif 220 | #ifdef DLT_PRISM_HEADER 221 | { prism_if_print, DLT_PRISM_HEADER }, 222 | #endif 223 | #ifdef DLT_IEEE802_11_RADIO 224 | { ieee802_11_radio_if_print, DLT_IEEE802_11_RADIO }, 225 | #endif 226 | #ifdef DLT_ENC 227 | { enc_if_print, DLT_ENC }, 228 | #endif 229 | #ifdef DLT_SYMANTEC_FIREWALL 230 | { symantec_if_print, DLT_SYMANTEC_FIREWALL }, 231 | #endif 232 | #ifdef DLT_APPLE_IP_OVER_IEEE1394 233 | { ap1394_if_print, DLT_APPLE_IP_OVER_IEEE1394 }, 234 | #endif 235 | #ifdef DLT_JUNIPER_ATM1 236 | { juniper_atm1_print, DLT_JUNIPER_ATM1 }, 237 | #endif 238 | #ifdef DLT_JUNIPER_ATM2 239 | { juniper_atm2_print, DLT_JUNIPER_ATM2 }, 240 | #endif 241 | #ifdef DLT_JUNIPER_MFR 242 | { juniper_mfr_print, DLT_JUNIPER_MFR }, 243 | #endif 244 | #ifdef DLT_JUNIPER_MLFR 245 | { juniper_mlfr_print, DLT_JUNIPER_MLFR }, 246 | #endif 247 | #ifdef DLT_JUNIPER_MLPPP 248 | { juniper_mlppp_print, DLT_JUNIPER_MLPPP }, 249 | #endif 250 | #ifdef DLT_JUNIPER_PPPOE 251 | { juniper_pppoe_print, DLT_JUNIPER_PPPOE }, 252 | #endif 253 | #ifdef DLT_JUNIPER_PPPOE_ATM 254 | { juniper_pppoe_atm_print, DLT_JUNIPER_PPPOE_ATM }, 255 | #endif 256 | #ifdef DLT_JUNIPER_GGSN 257 | { juniper_ggsn_print, DLT_JUNIPER_GGSN }, 258 | #endif 259 | #ifdef DLT_JUNIPER_ES 260 | { juniper_es_print, DLT_JUNIPER_ES }, 261 | #endif 262 | #ifdef DLT_JUNIPER_MONITOR 263 | { juniper_monitor_print, DLT_JUNIPER_MONITOR }, 264 | #endif 265 | #ifdef DLT_JUNIPER_SERVICES 266 | { juniper_services_print, DLT_JUNIPER_SERVICES }, 267 | #endif 268 | { NULL, 0 }, 269 | }; 270 | 271 | static if_printer 272 | lookup_printer(int type) 273 | { 274 | struct printer *p; 275 | 276 | for (p = printers; p->f; ++p) 277 | if (type == p->type) 278 | return p->f; 279 | 280 | return NULL; 281 | /* NOTREACHED */ 282 | } 283 | 284 | static pcap_t *pd; 285 | 286 | extern int optind; 287 | extern int opterr; 288 | extern char *optarg; 289 | 290 | struct print_info { 291 | if_printer printer; 292 | }; 293 | 294 | struct dump_info { 295 | char *WFileName; 296 | pcap_t *pd; 297 | pcap_dumper_t *p; 298 | }; 299 | 300 | static void 301 | show_dlts_and_exit(pcap_t *pd) 302 | { 303 | int n_dlts; 304 | int *dlts = 0; 305 | const char *dlt_name; 306 | 307 | n_dlts = pcap_list_datalinks(pd, &dlts); 308 | if (n_dlts < 0) 309 | error("%s", pcap_geterr(pd)); 310 | else if (n_dlts == 0 || !dlts) 311 | error("No data link types."); 312 | 313 | (void) fprintf(stderr, "Data link types (use option -y to set):\n"); 314 | 315 | while (--n_dlts >= 0) { 316 | dlt_name = pcap_datalink_val_to_name(dlts[n_dlts]); 317 | if (dlt_name != NULL) { 318 | (void) fprintf(stderr, " %s (%s)", dlt_name, 319 | pcap_datalink_val_to_description(dlts[n_dlts])); 320 | 321 | /* 322 | * OK, does tcpdump handle that type? 323 | */ 324 | if (lookup_printer(dlts[n_dlts]) == NULL) 325 | (void) fprintf(stderr, " (not supported)"); 326 | putchar('\n'); 327 | } else { 328 | (void) fprintf(stderr, " DLT %d (not supported)\n", 329 | dlts[n_dlts]); 330 | } 331 | } 332 | free(dlts); 333 | exit(0); 334 | } 335 | 336 | /* 337 | * Set up flags that might or might not be supported depending on the 338 | * version of libpcap we're using. 339 | */ 340 | #ifdef WIN32 341 | #define B_FLAG "B:" 342 | #define B_FLAG_USAGE " [ -B size ]" 343 | #else /* WIN32 */ 344 | #define B_FLAG 345 | #define B_FLAG_USAGE 346 | #endif /* WIN32 */ 347 | 348 | #ifdef HAVE_PCAP_FINDALLDEVS 349 | #ifndef HAVE_PCAP_IF_T 350 | #undef HAVE_PCAP_FINDALLDEVS 351 | #endif 352 | #endif 353 | 354 | #ifdef HAVE_PCAP_FINDALLDEVS 355 | #define D_FLAG "D" 356 | #else 357 | #define D_FLAG 358 | #endif 359 | 360 | #ifdef HAVE_PCAP_DUMP_FLUSH 361 | #define U_FLAG "U" 362 | #else 363 | #define U_FLAG 364 | #endif 365 | 366 | #ifndef WIN32 367 | /* Drop root privileges and chroot if necessary */ 368 | static void 369 | droproot(const char *username, const char *chroot_dir) 370 | { 371 | struct passwd *pw = NULL; 372 | 373 | if (chroot_dir && !username) { 374 | fprintf(stderr, "tcpdump: Chroot without dropping root is insecure\n"); 375 | exit(1); 376 | } 377 | 378 | pw = getpwnam(username); 379 | if (pw) { 380 | if (chroot_dir) { 381 | if (chroot(chroot_dir) != 0 || chdir ("/") != 0) { 382 | fprintf(stderr, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n", 383 | chroot_dir, pcap_strerror(errno)); 384 | exit(1); 385 | } 386 | } 387 | if (initgroups(pw->pw_name, pw->pw_gid) != 0 || 388 | setgid(pw->pw_gid) != 0 || setuid(pw->pw_uid) != 0) { 389 | fprintf(stderr, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n", 390 | username, 391 | (unsigned long)pw->pw_uid, 392 | (unsigned long)pw->pw_gid, 393 | pcap_strerror(errno)); 394 | exit(1); 395 | } 396 | } 397 | else { 398 | fprintf(stderr, "tcpdump: Couldn't find user '%.32s'\n", 399 | username); 400 | exit(1); 401 | } 402 | } 403 | #endif /* WIN32 */ 404 | 405 | static int 406 | getWflagChars(int x) 407 | { 408 | int c = 0; 409 | 410 | x -= 1; 411 | while (x > 0) { 412 | c += 1; 413 | x /= 10; 414 | } 415 | 416 | return c; 417 | } 418 | 419 | 420 | static void 421 | MakeFilename(char *buffer, char *orig_name, int cnt, int max_chars) 422 | { 423 | if (cnt == 0 && max_chars == 0) 424 | strcpy(buffer, orig_name); 425 | else 426 | sprintf(buffer, "%s%0*d", orig_name, max_chars, cnt); 427 | } 428 | 429 | static int tcpdump_printf(netdissect_options *ndo _U_, 430 | const char *fmt, ...) 431 | { 432 | 433 | va_list args; 434 | int ret; 435 | 436 | va_start(args, fmt); 437 | ret=vfprintf(stdout, fmt, args); 438 | va_end(args); 439 | 440 | return ret; 441 | } 442 | 443 | int 444 | main(int argc, char **argv) 445 | { 446 | register int cnt, op, i; 447 | bpf_u_int32 localnet, netmask; 448 | register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName, *WFileNameAlt; 449 | pcap_handler callback; 450 | int type; 451 | struct bpf_program fcode; 452 | #ifndef WIN32 453 | RETSIGTYPE (*oldhandler)(int); 454 | #endif 455 | struct print_info printinfo; 456 | struct dump_info dumpinfo; 457 | u_char *pcap_userdata; 458 | char ebuf[PCAP_ERRBUF_SIZE]; 459 | char *username = NULL; 460 | char *chroot_dir = NULL; 461 | #ifdef HAVE_PCAP_FINDALLDEVS 462 | pcap_if_t *devpointer; 463 | int devnum; 464 | #endif 465 | int status; 466 | #ifdef WIN32 467 | u_int UserBufferSize = 1000000; 468 | if(wsockinit() != 0) return 1; 469 | #endif /* WIN32 */ 470 | 471 | gndo->ndo_Oflag=1; 472 | gndo->ndo_Rflag=1; 473 | gndo->ndo_dlt=-1; 474 | gndo->ndo_default_print=ndo_default_print; 475 | gndo->ndo_printf=tcpdump_printf; 476 | gndo->ndo_error=ndo_error; 477 | gndo->ndo_warning=ndo_warning; 478 | gndo->ndo_snaplen = DEFAULT_SNAPLEN; 479 | 480 | cnt = -1; 481 | device = NULL; 482 | infile = NULL; 483 | RFileName = NULL; 484 | WFileName = NULL; 485 | if ((cp = strrchr(argv[0], '/')) != NULL) 486 | program_name = cp + 1; 487 | else 488 | program_name = argv[0]; 489 | 490 | if (abort_on_misalignment(ebuf, sizeof(ebuf)) < 0) 491 | error("%s", ebuf); 492 | 493 | #ifdef LIBSMI 494 | smiInit("tcpdump"); 495 | #endif 496 | 497 | opterr = 0; 498 | while ( 499 | (op = getopt(argc, argv, "aA" B_FLAG "c:C:d" D_FLAG "eE:fF:i:lLm:M:nNOpqr:Rs:StT:u" U_FLAG "vw:W:xXy:YZ:")) != -1) 500 | switch (op) { 501 | 502 | case 'a': 503 | /* compatibility for old -a */ 504 | break; 505 | 506 | case 'A': 507 | ++Aflag; 508 | break; 509 | 510 | #ifdef WIN32 511 | case 'B': 512 | UserBufferSize = atoi(optarg)*1024; 513 | if (UserBufferSize < 0) 514 | error("invalid packet buffer size %s", optarg); 515 | break; 516 | #endif /* WIN32 */ 517 | 518 | case 'c': 519 | cnt = atoi(optarg); 520 | if (cnt <= 0) 521 | error("invalid packet count %s", optarg); 522 | break; 523 | 524 | case 'C': 525 | Cflag = atoi(optarg) * 1000000; 526 | if (Cflag < 0) 527 | error("invalid file size %s", optarg); 528 | break; 529 | 530 | case 'd': 531 | ++dflag; 532 | break; 533 | 534 | #ifdef HAVE_PCAP_FINDALLDEVS 535 | case 'D': 536 | if (pcap_findalldevs(&devpointer, ebuf) < 0) 537 | error("%s", ebuf); 538 | else { 539 | for (i = 0; devpointer != 0; i++) { 540 | printf("%d.%s", i+1, devpointer->name); 541 | if (devpointer->description != NULL) 542 | printf(" (%s)", devpointer->description); 543 | printf("\n"); 544 | devpointer = devpointer->next; 545 | } 546 | } 547 | return 0; 548 | #endif /* HAVE_PCAP_FINDALLDEVS */ 549 | 550 | case 'L': 551 | Lflag++; 552 | break; 553 | 554 | case 'e': 555 | ++eflag; 556 | break; 557 | 558 | case 'E': 559 | #ifndef HAVE_LIBCRYPTO 560 | warning("crypto code not compiled in"); 561 | #endif 562 | gndo->ndo_espsecret = optarg; 563 | break; 564 | 565 | case 'f': 566 | ++fflag; 567 | break; 568 | 569 | case 'F': 570 | infile = optarg; 571 | break; 572 | 573 | case 'i': 574 | if (optarg[0] == '0' && optarg[1] == 0) 575 | error("Invalid adapter index"); 576 | 577 | #ifdef HAVE_PCAP_FINDALLDEVS 578 | /* 579 | * If the argument is a number, treat it as 580 | * an index into the list of adapters, as 581 | * printed by "tcpdump -D". 582 | * 583 | * This should be OK on UNIX systems, as interfaces 584 | * shouldn't have names that begin with digits. 585 | * It can be useful on Windows, where more than 586 | * one interface can have the same name. 587 | */ 588 | if ((devnum = atoi(optarg)) != 0) { 589 | if (devnum < 0) 590 | error("Invalid adapter index"); 591 | 592 | if (pcap_findalldevs(&devpointer, ebuf) < 0) 593 | error("%s", ebuf); 594 | else { 595 | for (i = 0; i < devnum-1; i++){ 596 | devpointer = devpointer->next; 597 | if (devpointer == NULL) 598 | error("Invalid adapter index"); 599 | } 600 | } 601 | device = devpointer->name; 602 | break; 603 | } 604 | #endif /* HAVE_PCAP_FINDALLDEVS */ 605 | device = optarg; 606 | break; 607 | 608 | case 'l': 609 | #ifdef WIN32 610 | /* 611 | * _IOLBF is the same as _IOFBF in Microsoft's C 612 | * libraries; the only alternative they offer 613 | * is _IONBF. 614 | * 615 | * XXX - this should really be checking for MSVC++, 616 | * not WIN32, if, for example, MinGW has its own 617 | * C library that is more UNIX-compatible. 618 | */ 619 | setvbuf(stdout, NULL, _IONBF, 0); 620 | #else /* WIN32 */ 621 | #ifdef HAVE_SETLINEBUF 622 | setlinebuf(stdout); 623 | #else 624 | setvbuf(stdout, NULL, _IOLBF, 0); 625 | #endif 626 | #endif /* WIN32 */ 627 | break; 628 | 629 | case 'n': 630 | ++nflag; 631 | break; 632 | 633 | case 'N': 634 | ++Nflag; 635 | break; 636 | 637 | case 'm': 638 | #ifdef LIBSMI 639 | if (smiLoadModule(optarg) == 0) { 640 | error("could not load MIB module %s", optarg); 641 | } 642 | sflag = 1; 643 | #else 644 | (void)fprintf(stderr, "%s: ignoring option `-m %s' ", 645 | program_name, optarg); 646 | (void)fprintf(stderr, "(no libsmi support)\n"); 647 | #endif 648 | break; 649 | 650 | case 'M': 651 | /* TCP-MD5 shared secret */ 652 | #ifndef HAVE_LIBCRYPTO 653 | warning("crypto code not compiled in"); 654 | #endif 655 | tcpmd5secret = optarg; 656 | break; 657 | 658 | case 'O': 659 | Oflag = 0; 660 | break; 661 | 662 | case 'p': 663 | ++pflag; 664 | break; 665 | 666 | case 'q': 667 | ++qflag; 668 | ++suppress_default_print; 669 | break; 670 | 671 | case 'r': 672 | RFileName = optarg; 673 | break; 674 | 675 | case 'R': 676 | Rflag = 0; 677 | break; 678 | 679 | case 's': { 680 | char *end; 681 | 682 | snaplen = strtol(optarg, &end, 0); 683 | if (optarg == end || *end != '\0' 684 | || snaplen < 0 || snaplen > 65535) 685 | error("invalid snaplen %s", optarg); 686 | else if (snaplen == 0) 687 | snaplen = 65535; 688 | break; 689 | } 690 | 691 | case 'S': 692 | ++Sflag; 693 | break; 694 | 695 | case 't': 696 | ++tflag; 697 | break; 698 | 699 | case 'T': 700 | if (strcasecmp(optarg, "vat") == 0) 701 | packettype = PT_VAT; 702 | else if (strcasecmp(optarg, "wb") == 0) 703 | packettype = PT_WB; 704 | else if (strcasecmp(optarg, "rpc") == 0) 705 | packettype = PT_RPC; 706 | else if (strcasecmp(optarg, "rtp") == 0) 707 | packettype = PT_RTP; 708 | else if (strcasecmp(optarg, "rtcp") == 0) 709 | packettype = PT_RTCP; 710 | else if (strcasecmp(optarg, "snmp") == 0) 711 | packettype = PT_SNMP; 712 | else if (strcasecmp(optarg, "cnfp") == 0) 713 | packettype = PT_CNFP; 714 | else if (strcasecmp(optarg, "tftp") == 0) 715 | packettype = PT_TFTP; 716 | else if (strcasecmp(optarg, "aodv") == 0) 717 | packettype = PT_AODV; 718 | else 719 | error("unknown packet type `%s'", optarg); 720 | break; 721 | 722 | case 'u': 723 | ++uflag; 724 | break; 725 | 726 | #ifdef HAVE_PCAP_DUMP_FLUSH 727 | case 'U': 728 | ++Uflag; 729 | break; 730 | #endif 731 | 732 | case 'v': 733 | /*DL5DI=>*/ 734 | else if (strcasecmp(optarg, "dmr") == 0){ 735 | packettype = PT_DMR; 736 | ++xflag; 737 | } 738 | /*<=DL5DI*/ 739 | ++vflag; 740 | break; 741 | 742 | case 'w': 743 | WFileName = optarg; 744 | break; 745 | 746 | case 'W': 747 | Wflag = atoi(optarg); 748 | if (Wflag < 0) 749 | error("invalid number of output files %s", optarg); 750 | WflagChars = getWflagChars(Wflag); 751 | break; 752 | 753 | case 'x': 754 | ++xflag; 755 | ++suppress_default_print; 756 | break; 757 | 758 | case 'X': 759 | ++Xflag; 760 | ++suppress_default_print; 761 | break; 762 | 763 | case 'y': 764 | gndo->ndo_dltname = optarg; 765 | gndo->ndo_dlt = 766 | pcap_datalink_name_to_val(gndo->ndo_dltname); 767 | if (gndo->ndo_dlt < 0) 768 | error("invalid data link type %s", gndo->ndo_dltname); 769 | break; 770 | 771 | #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG) 772 | case 'Y': 773 | { 774 | /* Undocumented flag */ 775 | #ifdef HAVE_PCAP_DEBUG 776 | extern int pcap_debug; 777 | pcap_debug = 1; 778 | #else 779 | extern int yydebug; 780 | yydebug = 1; 781 | #endif 782 | } 783 | break; 784 | #endif 785 | case 'Z': 786 | if (optarg) { 787 | username = strdup(optarg); 788 | } 789 | else { 790 | usage(); 791 | /* NOTREACHED */ 792 | } 793 | break; 794 | 795 | default: 796 | usage(); 797 | /* NOTREACHED */ 798 | } 799 | 800 | switch (tflag) { 801 | 802 | case 0: /* Default */ 803 | case 4: /* Default + Date*/ 804 | thiszone = gmt2local(0); 805 | break; 806 | 807 | case 1: /* No time stamp */ 808 | case 2: /* Unix timeval style */ 809 | case 3: /* Microseconds since previous packet */ 810 | break; 811 | 812 | default: /* Not supported */ 813 | error("only -t, -tt, -ttt, and -tttt are supported"); 814 | break; 815 | } 816 | 817 | #ifdef WITH_CHROOT 818 | /* if run as root, prepare for chrooting */ 819 | if (getuid() == 0 || geteuid() == 0) { 820 | /* future extensibility for cmd-line arguments */ 821 | if (!chroot_dir) 822 | case 5: /* Default + Date UTC*/ /*DL5DI*/ 823 | thiszone = gmt2local(0); 824 | break; 825 | 826 | chroot_dir = WITH_CHROOT; 827 | } 828 | #endif 829 | 830 | #ifdef WITH_USER 831 | /* if run as root, prepare for dropping root privileges */ 832 | if (getuid() == 0 || geteuid() == 0) { 833 | /* Run with '-Z root' to restore old behaviour */ 834 | if (!username) 835 | username = WITH_USER; 836 | } 837 | #endif 838 | 839 | if (RFileName != NULL) { 840 | int dlt; 841 | const char *dlt_name; 842 | 843 | #ifndef WIN32 844 | /* 845 | * We don't need network access, so relinquish any set-UID 846 | * or set-GID privileges we have (if any). 847 | * 848 | * We do *not* want set-UID privileges when opening a 849 | * trace file, as that might let the user read other 850 | * people's trace files (especially if we're set-UID 851 | * root). 852 | */ 853 | if (setgid(getgid()) != 0 || setuid(getuid()) != 0 ) 854 | fprintf(stderr, "Warning: setgid/setuid failed !\n"); 855 | #endif /* WIN32 */ 856 | pd = pcap_open_offline(RFileName, ebuf); 857 | if (pd == NULL) 858 | error("%s", ebuf); 859 | dlt = pcap_datalink(pd); 860 | dlt_name = pcap_datalink_val_to_name(dlt); 861 | if (dlt_name == NULL) { 862 | fprintf(stderr, "reading from file %s, link-type %u\n", 863 | RFileName, dlt); 864 | } else { 865 | fprintf(stderr, 866 | "reading from file %s, link-type %s (%s)\n", 867 | RFileName, dlt_name, 868 | pcap_datalink_val_to_description(dlt)); 869 | } 870 | localnet = 0; 871 | netmask = 0; 872 | if (fflag != 0) 873 | error("-f and -r options are incompatible"); 874 | } else { 875 | if (device == NULL) { 876 | device = pcap_lookupdev(ebuf); 877 | if (device == NULL) 878 | error("%s", ebuf); 879 | } 880 | #ifdef WIN32 881 | if(strlen(device) == 1) //we assume that an ASCII string is always longer than 1 char 882 | { //a Unicode string has a \0 as second byte (so strlen() is 1) 883 | fprintf(stderr, "%s: listening on %ws\n", program_name, device); 884 | } 885 | else 886 | { 887 | fprintf(stderr, "%s: listening on %s\n", program_name, device); 888 | } 889 | 890 | fflush(stderr); 891 | #endif /* WIN32 */ 892 | *ebuf = '\0'; 893 | pd = pcap_open_live(device, snaplen, !pflag, 1000, ebuf); 894 | if (pd == NULL) 895 | error("%s", ebuf); 896 | else if (*ebuf) 897 | warning("%s", ebuf); 898 | /* 899 | * Let user own process after socket has been opened. 900 | */ 901 | #ifndef WIN32 902 | if (setgid(getgid()) != 0 || setuid(getuid()) != 0) 903 | fprintf(stderr, "Warning: setgid/setuid failed !\n"); 904 | #endif /* WIN32 */ 905 | #ifdef WIN32 906 | if(UserBufferSize != 1000000) 907 | if(pcap_setbuff(pd, UserBufferSize)==-1){ 908 | error("%s", pcap_geterr(pd)); 909 | } 910 | #endif /* WIN32 */ 911 | if (Lflag) 912 | show_dlts_and_exit(pd); 913 | if (gndo->ndo_dlt >= 0) { 914 | #ifdef HAVE_PCAP_SET_DATALINK 915 | if (pcap_set_datalink(pd, gndo->ndo_dlt) < 0) 916 | error("%s", pcap_geterr(pd)); 917 | #else 918 | /* 919 | * We don't actually support changing the 920 | * data link type, so we only let them 921 | * set it to what it already is. 922 | */ 923 | if (gndo->ndo_dlt != pcap_datalink(pd)) { 924 | error("%s is not one of the DLTs supported by this device\n", 925 | gndo->ndo_dltname); 926 | } 927 | #endif 928 | (void)fprintf(stderr, "%s: data link type %s\n", 929 | program_name, gndo->ndo_dltname); 930 | (void)fflush(stderr); 931 | } 932 | i = pcap_snapshot(pd); 933 | if (snaplen < i) { 934 | warning("snaplen raised from %d to %d", snaplen, i); 935 | snaplen = i; 936 | } 937 | if (pcap_lookupnet(device, &localnet, &netmask, ebuf) < 0) { 938 | localnet = 0; 939 | netmask = 0; 940 | warning("%s", ebuf); 941 | } 942 | } 943 | if (infile) 944 | cmdbuf = read_infile(infile); 945 | else 946 | cmdbuf = copy_argv(&argv[optind]); 947 | 948 | if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0) 949 | error("%s", pcap_geterr(pd)); 950 | if (dflag) { 951 | bpf_dump(&fcode, dflag); 952 | pcap_close(pd); 953 | exit(0); 954 | } 955 | init_addrtoname(localnet, netmask); 956 | 957 | #ifndef WIN32 958 | (void)setsignal(SIGPIPE, cleanup); 959 | #endif /* WIN32 */ 960 | (void)setsignal(SIGTERM, cleanup); 961 | (void)setsignal(SIGINT, cleanup); 962 | /* Cooperate with nohup(1) */ 963 | #ifndef WIN32 964 | if ((oldhandler = setsignal(SIGHUP, cleanup)) != SIG_DFL) 965 | (void)setsignal(SIGHUP, oldhandler); 966 | #endif /* WIN32 */ 967 | 968 | if (pcap_setfilter(pd, &fcode) < 0) 969 | error("%s", pcap_geterr(pd)); 970 | if (WFileName) { 971 | pcap_dumper_t *p; 972 | 973 | WFileNameAlt = (char *)malloc(strlen(WFileName) + MAX_CFLAG_CHARS + 1); 974 | if (WFileNameAlt == NULL) 975 | error("malloc of WFileNameAlt"); 976 | MakeFilename(WFileNameAlt, WFileName, 0, WflagChars); 977 | p = pcap_dump_open(pd, WFileNameAlt); 978 | if (p == NULL) 979 | error("%s", pcap_geterr(pd)); 980 | if (Cflag != 0) { 981 | callback = dump_packet_and_trunc; 982 | dumpinfo.WFileName = WFileName; 983 | dumpinfo.pd = pd; 984 | dumpinfo.p = p; 985 | pcap_userdata = (u_char *)&dumpinfo; 986 | } else { 987 | callback = dump_packet; 988 | pcap_userdata = (u_char *)p; 989 | } 990 | } else { 991 | type = pcap_datalink(pd); 992 | printinfo.printer = lookup_printer(type); 993 | if (printinfo.printer == NULL) { 994 | gndo->ndo_dltname = pcap_datalink_val_to_name(type); 995 | if (gndo->ndo_dltname != NULL) 996 | error("unsupported data link type %s", 997 | gndo->ndo_dltname); 998 | else 999 | error("unsupported data link type %d", type); 1000 | } 1001 | callback = print_packet; 1002 | pcap_userdata = (u_char *)&printinfo; 1003 | } 1004 | #ifndef WIN32 1005 | /* 1006 | * We cannot do this earlier, because we want to be able to open 1007 | * the file (if done) for writing before giving up permissions. 1008 | */ 1009 | if (getuid() == 0 || geteuid() == 0) { 1010 | if (username || chroot_dir) 1011 | droproot(username, chroot_dir); 1012 | } 1013 | #endif /* WIN32 */ 1014 | #ifdef SIGINFO 1015 | (void)setsignal(SIGINFO, requestinfo); 1016 | #endif 1017 | 1018 | if (vflag > 0 && WFileName) { 1019 | /* 1020 | * When capturing to a file, "-v" means tcpdump should, 1021 | * every 10 secodns, "v"erbosely report the number of 1022 | * packets captured. 1023 | */ 1024 | #ifdef USE_WIN32_MM_TIMER 1025 | /* call verbose_stats_dump() each 1000 +/-100msec */ 1026 | timer_id = timeSetEvent(1000, 100, verbose_stats_dump, 0, TIME_PERIODIC); 1027 | setvbuf(stderr, NULL, _IONBF, 0); 1028 | #elif defined(HAVE_ALARM) 1029 | (void)setsignal(SIGALRM, verbose_stats_dump); 1030 | alarm(1); 1031 | #endif 1032 | } 1033 | 1034 | #ifndef WIN32 1035 | if (RFileName == NULL) { 1036 | int dlt; 1037 | const char *dlt_name; 1038 | 1039 | if (!vflag && !WFileName) { 1040 | (void)fprintf(stderr, 1041 | "%s: verbose output suppressed, use -v or -vv for full protocol decode\n", 1042 | program_name); 1043 | } else 1044 | (void)fprintf(stderr, "%s: ", program_name); 1045 | dlt = pcap_datalink(pd); 1046 | dlt_name = pcap_datalink_val_to_name(dlt); 1047 | if (dlt_name == NULL) { 1048 | (void)fprintf(stderr, "listening on %s, link-type %u, capture size %u bytes\n", 1049 | device, dlt, snaplen); 1050 | } else { 1051 | (void)fprintf(stderr, "listening on %s, link-type %s (%s), capture size %u bytes\n", 1052 | device, dlt_name, 1053 | pcap_datalink_val_to_description(dlt), snaplen); 1054 | } 1055 | (void)fflush(stderr); 1056 | } 1057 | #endif /* WIN32 */ 1058 | status = pcap_loop(pd, cnt, callback, pcap_userdata); 1059 | if (WFileName == NULL) { 1060 | /* 1061 | * We're printing packets. Flush the printed output, 1062 | * so it doesn't get intermingled with error output. 1063 | */ 1064 | if (status == -2) { 1065 | /* 1066 | * We got interrupted, so perhaps we didn't 1067 | * manage to finish a line we were printing. 1068 | * Print an extra newline, just in case. 1069 | */ 1070 | putchar('\n'); 1071 | } 1072 | (void)fflush(stdout); 1073 | } 1074 | if (status == -1) { 1075 | /* 1076 | * Error. Report it. 1077 | */ 1078 | (void)fprintf(stderr, "%s: pcap_loop: %s\n", 1079 | program_name, pcap_geterr(pd)); 1080 | } 1081 | if (RFileName == NULL) { 1082 | /* 1083 | * We're doing a live capture. Report the capture 1084 | * statistics. 1085 | */ 1086 | info(1); 1087 | } 1088 | pcap_close(pd); 1089 | exit(status == -1 ? 1 : 0); 1090 | } 1091 | 1092 | /* make a clean exit on interrupts */ 1093 | static RETSIGTYPE 1094 | cleanup(int signo _U_) 1095 | { 1096 | #ifdef USE_WIN32_MM_TIMER 1097 | if (timer_id) 1098 | timeKillEvent(timer_id); 1099 | timer_id = 0; 1100 | #elif defined(HAVE_ALARM) 1101 | alarm(0); 1102 | #endif 1103 | 1104 | #ifdef HAVE_PCAP_BREAKLOOP 1105 | /* 1106 | * We have "pcap_breakloop()"; use it, so that we do as little 1107 | * as possible in the signal handler (it's probably not safe 1108 | * to do anything with standard I/O streams in a signal handler - 1109 | * the ANSI C standard doesn't say it is). 1110 | */ 1111 | pcap_breakloop(pd); 1112 | #else 1113 | /* 1114 | * We don't have "pcap_breakloop()"; this isn't safe, but 1115 | * it's the best we can do. Print the summary if we're 1116 | * not reading from a savefile - i.e., if we're doing a 1117 | * live capture - and exit. 1118 | */ 1119 | if (pd != NULL && pcap_file(pd) == NULL) { 1120 | /* 1121 | * We got interrupted, so perhaps we didn't 1122 | * manage to finish a line we were printing. 1123 | * Print an extra newline, just in case. 1124 | */ 1125 | putchar('\n'); 1126 | (void)fflush(stdout); 1127 | info(1); 1128 | } 1129 | exit(0); 1130 | #endif 1131 | } 1132 | 1133 | static void 1134 | info(register int verbose) 1135 | { 1136 | struct pcap_stat stat; 1137 | 1138 | if (pcap_stats(pd, &stat) < 0) { 1139 | (void)fprintf(stderr, "pcap_stats: %s\n", pcap_geterr(pd)); 1140 | return; 1141 | } 1142 | 1143 | if (!verbose) 1144 | fprintf(stderr, "%s: ", program_name); 1145 | 1146 | (void)fprintf(stderr, "%u packets captured", packets_captured); 1147 | if (!verbose) 1148 | fputs(", ", stderr); 1149 | else 1150 | putc('\n', stderr); 1151 | (void)fprintf(stderr, "%d packets received by filter", stat.ps_recv); 1152 | if (!verbose) 1153 | fputs(", ", stderr); 1154 | else 1155 | putc('\n', stderr); 1156 | (void)fprintf(stderr, "%d packets dropped by kernel\n", stat.ps_drop); 1157 | infoprint = 0; 1158 | } 1159 | 1160 | static void 1161 | dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) 1162 | { 1163 | struct dump_info *dump_info; 1164 | char *name; 1165 | 1166 | ++packets_captured; 1167 | 1168 | ++infodelay; 1169 | 1170 | dump_info = (struct dump_info *)user; 1171 | 1172 | /* 1173 | * XXX - this won't prevent capture files from getting 1174 | * larger than Cflag - the last packet written to the 1175 | * file could put it over Cflag. 1176 | */ 1177 | if (pcap_dump_ftell(dump_info->p) > Cflag) { 1178 | /* 1179 | * Close the current file and open a new one. 1180 | */ 1181 | pcap_dump_close(dump_info->p); 1182 | Cflag_count++; 1183 | if (Wflag > 0) { 1184 | if (Cflag_count >= Wflag) 1185 | Cflag_count = 0; 1186 | } else { 1187 | if (Cflag_count >= MAX_CFLAG) 1188 | error("too many output files"); 1189 | } 1190 | name = (char *)malloc(strlen(dump_info->WFileName) + MAX_CFLAG_CHARS + 1); 1191 | if (name == NULL) 1192 | error("dump_packet_and_trunc: malloc"); 1193 | MakeFilename(name, dump_info->WFileName, Cflag_count, WflagChars); 1194 | dump_info->p = pcap_dump_open(dump_info->pd, name); 1195 | free(name); 1196 | if (dump_info->p == NULL) 1197 | error("%s", pcap_geterr(pd)); 1198 | } 1199 | 1200 | pcap_dump((u_char *)dump_info->p, h, sp); 1201 | #ifdef HAVE_PCAP_DUMP_FLUSH 1202 | if (Uflag) 1203 | pcap_dump_flush(dump_info->p); 1204 | #endif 1205 | 1206 | --infodelay; 1207 | if (infoprint) 1208 | info(0); 1209 | } 1210 | 1211 | static void 1212 | dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) 1213 | { 1214 | ++packets_captured; 1215 | 1216 | ++infodelay; 1217 | 1218 | pcap_dump(user, h, sp); 1219 | #ifdef HAVE_PCAP_DUMP_FLUSH 1220 | if (Uflag) 1221 | pcap_dump_flush((pcap_dumper_t *)user); 1222 | #endif 1223 | 1224 | --infodelay; 1225 | if (infoprint) 1226 | info(0); 1227 | } 1228 | 1229 | static void 1230 | print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) 1231 | { 1232 | struct print_info *print_info; 1233 | u_int hdrlen; 1234 | 1235 | ++packets_captured; 1236 | 1237 | ++infodelay; 1238 | 1239 | /* 1240 | * Some printers want to check that they're not walking off the 1241 | * end of the packet. 1242 | * Rather than pass it all the way down, we set this global. 1243 | */ 1244 | snapend = sp + h->caplen; 1245 | 1246 | if(packettype != PT_DMR){ 1247 | /* print timestamp */ 1248 | ts_print(&h->ts); 1249 | print_info = (struct print_info *)user; 1250 | /* print header */ 1251 | hdrlen = (*print_info->printer)(h, sp); 1252 | } 1253 | 1254 | if (Xflag) { 1255 | /* 1256 | * Print the raw packet data in hex and ASCII. 1257 | */ 1258 | if (Xflag > 1) { 1259 | /* 1260 | * Include the link-layer header. 1261 | */ 1262 | hex_and_ascii_print("\n\t", sp, h->caplen); 1263 | } else { 1264 | /* 1265 | * Don't include the link-layer header - and if 1266 | * we have nothing past the link-layer header, 1267 | * print nothing. 1268 | */ 1269 | if (h->caplen > hdrlen) 1270 | hex_and_ascii_print("\n\t", sp + hdrlen, 1271 | h->caplen - hdrlen); 1272 | } 1273 | } else if (xflag) { 1274 | /* 1275 | * Print the raw packet data in hex. 1276 | */ 1277 | /* DL5DI: use special DMR format */ 1278 | if(packettype == PT_DMR){ 1279 | dmr_print(sp+14, h->caplen); 1280 | } else if (xflag > 1) { 1281 | /* 1282 | * Include the link-layer header. 1283 | */ 1284 | hex_print("\n\t", sp, h->caplen); 1285 | } else { 1286 | /* 1287 | * Don't include the link-layer header - and if 1288 | * we have nothing past the link-layer header, 1289 | * print nothing. 1290 | */ 1291 | if (h->caplen > hdrlen) 1292 | hex_print("\n\t", sp + hdrlen, h->caplen - hdrlen); 1293 | } 1294 | } else if (Aflag) { 1295 | /* 1296 | * Print the raw packet data in ASCII. 1297 | */ 1298 | if (Aflag > 1) { 1299 | /* 1300 | * Include the link-layer header. 1301 | */ 1302 | ascii_print(sp, h->caplen); 1303 | } else { 1304 | /* 1305 | * Don't include the link-layer header - and if 1306 | * we have nothing past the link-layer header, 1307 | * print nothing. 1308 | */ 1309 | if (h->caplen > hdrlen) 1310 | ascii_print(sp + hdrlen, h->caplen - hdrlen); 1311 | } 1312 | } 1313 | 1314 | if(packettype != PT_DMR) 1315 | putchar('\n'); 1316 | 1317 | --infodelay; 1318 | if (infoprint) 1319 | info(0); 1320 | } 1321 | 1322 | #ifdef WIN32 1323 | /* 1324 | * XXX - there should really be libpcap calls to get the version 1325 | * number as a string (the string would be generated from #defines 1326 | * at run time, so that it's not generated from string constants 1327 | * in the library, as, on many UNIX systems, those constants would 1328 | * be statically linked into the application executable image, and 1329 | * would thus reflect the version of libpcap on the system on 1330 | * which the application was *linked*, not the system on which it's 1331 | * *running*. 1332 | * 1333 | * That routine should be documented, unlike the "version[]" 1334 | * string, so that UNIX vendors providing their own libpcaps 1335 | * don't omit it (as a couple of vendors have...). 1336 | * 1337 | * Packet.dll should perhaps also export a routine to return the 1338 | * version number of the Packet.dll code, to supply the 1339 | * "Wpcap_version" information on Windows. 1340 | */ 1341 | char WDversion[]="3.9.3"; 1342 | #if !defined(HAVE_GENERATED_VERSION) 1343 | char version[]="3.9.3"; 1344 | #endif 1345 | char pcap_version[]="0.9.3"; 1346 | char Wpcap_version[]="3.1"; 1347 | #endif 1348 | 1349 | /* 1350 | * By default, print the specified data out in hex and ASCII. 1351 | */ 1352 | static void 1353 | ndo_default_print(netdissect_options *ndo _U_, const u_char *bp, u_int length) 1354 | { 1355 | hex_and_ascii_print("\n\t", bp, length); /* pass on lf and identation string */ 1356 | } 1357 | 1358 | void 1359 | default_print(const u_char *bp, u_int length) 1360 | { 1361 | ndo_default_print(gndo, bp, length); 1362 | } 1363 | 1364 | #ifdef SIGINFO 1365 | RETSIGTYPE requestinfo(int signo _U_) 1366 | { 1367 | if (infodelay) 1368 | ++infoprint; 1369 | else 1370 | info(0); 1371 | } 1372 | #endif 1373 | 1374 | /* 1375 | * Called once each second in verbose mode while dumping to file 1376 | */ 1377 | #ifdef USE_WIN32_MM_TIMER 1378 | void CALLBACK verbose_stats_dump (UINT timer_id _U_, UINT msg _U_, DWORD_PTR arg _U_, 1379 | DWORD_PTR dw1 _U_, DWORD_PTR dw2 _U_) 1380 | { 1381 | struct pcap_stat stat; 1382 | 1383 | if (infodelay == 0 && pcap_stats(pd, &stat) >= 0) 1384 | fprintf(stderr, "Got %u\r", packets_captured); 1385 | } 1386 | #elif defined(HAVE_ALARM) 1387 | static void verbose_stats_dump(int sig _U_) 1388 | { 1389 | struct pcap_stat stat; 1390 | 1391 | if (infodelay == 0 && pcap_stats(pd, &stat) >= 0) 1392 | fprintf(stderr, "Got %u\r", packets_captured); 1393 | alarm(1); 1394 | } 1395 | #endif 1396 | 1397 | static void 1398 | usage(void) 1399 | { 1400 | extern char version[]; 1401 | #ifndef HAVE_PCAP_LIB_VERSION 1402 | #if defined(WIN32) || defined(HAVE_PCAP_VERSION) 1403 | extern char pcap_version[]; 1404 | #else /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */ 1405 | static char pcap_version[] = "unknown"; 1406 | #endif /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */ 1407 | #endif /* HAVE_PCAP_LIB_VERSION */ 1408 | 1409 | #ifdef HAVE_PCAP_LIB_VERSION 1410 | #ifdef WIN32 1411 | (void)fprintf(stderr, "%s version %s, based on tcpdump version %s\n", program_name, WDversion, version); 1412 | #else /* WIN32 */ 1413 | (void)fprintf(stderr, "%s version %s\n", program_name, version); 1414 | #endif /* WIN32 */ 1415 | (void)fprintf(stderr, "%s\n",pcap_lib_version()); 1416 | #else /* HAVE_PCAP_LIB_VERSION */ 1417 | #ifdef WIN32 1418 | (void)fprintf(stderr, "%s version %s, based on tcpdump version %s\n", program_name, WDversion, version); 1419 | (void)fprintf(stderr, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version, pcap_version); 1420 | #else /* WIN32 */ 1421 | (void)fprintf(stderr, "%s version %s\n", program_name, version); 1422 | (void)fprintf(stderr, "libpcap version %s\n", pcap_version); 1423 | #endif /* WIN32 */ 1424 | #endif /* HAVE_PCAP_LIB_VERSION */ 1425 | (void)fprintf(stderr, 1426 | "Usage: %s [-aAd" D_FLAG "eflLnNOpqRStu" U_FLAG "vxX]" B_FLAG_USAGE " [-c count] [ -C file_size ]\n", program_name); 1427 | (void)fprintf(stderr, 1428 | "\t\t[ -E algo:secret ] [ -F file ] [ -i interface ] [ -M secret ]\n"); 1429 | (void)fprintf(stderr, 1430 | "\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n"); 1431 | (void)fprintf(stderr, 1432 | "\t\t[ -W filecount ] [ -y datalinktype ] [ -Z user ]\n"); 1433 | (void)fprintf(stderr, 1434 | "\t\t[ expression ]\n"); 1435 | exit(1); 1436 | } 1437 | 1438 | 1439 | 1440 | /* VARARGS */ 1441 | static void 1442 | ndo_error(netdissect_options *ndo _U_, const char *fmt, ...) 1443 | { 1444 | va_list ap; 1445 | 1446 | (void)fprintf(stderr, "%s: ", program_name); 1447 | va_start(ap, fmt); 1448 | (void)vfprintf(stderr, fmt, ap); 1449 | va_end(ap); 1450 | if (*fmt) { 1451 | fmt += strlen(fmt); 1452 | if (fmt[-1] != '\n') 1453 | (void)fputc('\n', stderr); 1454 | } 1455 | exit(1); 1456 | /* NOTREACHED */ 1457 | } 1458 | 1459 | /* VARARGS */ 1460 | static void 1461 | ndo_warning(netdissect_options *ndo _U_, const char *fmt, ...) 1462 | { 1463 | va_list ap; 1464 | 1465 | (void)fprintf(stderr, "%s: WARNING: ", program_name); 1466 | va_start(ap, fmt); 1467 | (void)vfprintf(stderr, fmt, ap); 1468 | va_end(ap); 1469 | if (*fmt) { 1470 | fmt += strlen(fmt); 1471 | if (fmt[-1] != '\n') 1472 | (void)fputc('\n', stderr); 1473 | } 1474 | } 1475 | 1476 | -------------------------------------------------------------------------------- /DMRmonitor/trbomon_v2.c: -------------------------------------------------------------------------------- 1 | /* 2 | dmrmonitor-motorola - monitor mototrbo repeater and send to server 3 | Copyright (C) 2012 David Kierzokwski (kd8eyf@digitalham.info) 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 | #include 19 | #include 20 | #include 21 | #include "/usr/include/pcap/pcap.h" // NEED TO FIX THIS 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | struct UDP_hdr { 29 | u_short uh_sport; //Source Port 30 | u_short uh_dport; //Destnation Port 31 | u_short uh_ulen; //Datagram Length 32 | u_short uh_sum; //Datagram Checksum 33 | }; 34 | int isDMR=0,DMRonly=0,debug = 0; 35 | char *devname = NULL; 36 | 37 | void usage( int8_t e ); 38 | void processPacket(u_char *arg, const struct pcap_pkthdr* pkthdr, const u_char * packet) 39 | { 40 | struct ip * ip; 41 | struct UDP_hdr * udp; 42 | unsigned int IP_header_length; 43 | unsigned int capture_len = pkthdr->len; 44 | int Role = 0,TS1Linked=0,TS2Linked=0; // Role Peer = 0, Slave = 1 45 | char buffer[15]; // Used for temporay data conversions 46 | long PacketType,SourceID, UserID, DestinationID; 47 | char *packetDescription ="unknown"; 48 | int i=0, *counter = (int *)arg; 49 | isDMR = 0; 50 | packet += sizeof (struct ether_header); 51 | capture_len -= sizeof(struct ether_header); 52 | ip = (struct ip*) packet; 53 | IP_header_length = ip->ip_hl *4; 54 | packet += IP_header_length; 55 | capture_len -= IP_header_length; 56 | udp = (struct UDP_hdr*) packet; 57 | packet += sizeof (struct UDP_hdr); 58 | capture_len -= sizeof (struct UDP_hdr); 59 | sprintf(buffer,"%x",*packet); 60 | PacketType = strtol(buffer,NULL,16); 61 | if ((capture_len >= 20) && (capture_len <= 21)) { //Based on size we might have a motorola heartbeat packet 62 | if(((*packet) >= 150) && ((*packet)<=153)) { //Check first offset to see if it really is 63 | isDMR = 1; 64 | switch(*packet) { //Set the packet Description 65 | case 150: 66 | packetDescription = "Master Ping"; 67 | Role = 1; 68 | break; 69 | case 151: 70 | packetDescription = "Master Ping Reply"; 71 | Role = 1; 72 | break; 73 | case 152: 74 | packetDescription = "Peer Ping"; 75 | break; 76 | case 153: 77 | packetDescription = "Peer Ping Reply"; 78 | break; 79 | } 80 | sprintf(buffer,"%x",*packet); 81 | PacketType = strtol(buffer,NULL,16); 82 | sprintf(buffer,"%02x%02x%02x",*(packet+2),*(packet+3),*(packet+4)); 83 | SourceID = strtol(buffer,NULL,16); 84 | sprintf(buffer,"%02x",*(packet+5)); 85 | //printf("%02x",*(packet+5)); 86 | 87 | } 88 | } 89 | if ((isDMR == 0) && (DMRonly == 1)) return; 90 | if (debug == 1) { 91 | uint32_t i=0, j=0; 92 | printf("\n\n\n"); 93 | printf("Packet Count:\t%d\n", ++(*counter)); 94 | printf("Packet Size:\t%d\n", capture_len); 95 | printf("Size ETH Header\t%lu\n",sizeof(struct ether_header)); 96 | printf("Size IP Header\t%u\n",IP_header_length); 97 | printf("UDP Src Port\t%d\n", ntohs(udp->uh_sport)); 98 | printf("IDP Dst Port\t%d\n", ntohs(udp->uh_dport)); 99 | printf("Packet Type\t%lu\n",PacketType); 100 | printf("Packet Desc\t%s\n",packetDescription); 101 | printf("Soute Role\t%i\n",Role); 102 | printf("Source ID\t%lu\n",SourceID); 103 | printf("Slot1 Status\t%i\n",TS1Linked); 104 | printf("Slot2 Status\t%i\n",TS2Linked); 105 | printf("\n%04x ",j); 106 | while (i < capture_len) { 107 | printf("%02x ", packet[i]); 108 | i++; 109 | j++; 110 | if (j == 8) { 111 | printf(" "); 112 | } 113 | if (j == 16) { 114 | printf("\n%04x ",i); 115 | j=0; 116 | } 117 | } 118 | } 119 | if (debug == 2) { 120 | while (i < capture_len) { 121 | printf("%02X", packet[i]); 122 | i++; 123 | } 124 | printf("\n"); 125 | } 126 | } 127 | int main(int argc, char *argv[] ) 128 | { 129 | char packet_filter[] = "ip and udp"; 130 | struct bpf_program fcode; 131 | u_int netmask; 132 | pcap_t *descr = NULL; 133 | int32_t c; 134 | while ((c = getopt(argc, argv, "opdVhi:")) != EOF) { 135 | switch (c) { 136 | case 'd': 137 | debug = 1; 138 | break; 139 | case 'p': 140 | debug = 2; 141 | break; 142 | case 'V': 143 | version(); 144 | break; 145 | case 'i': 146 | devname = optarg; 147 | break; 148 | case 'h': 149 | usage(-1); 150 | break; 151 | case 'o': 152 | DMRonly = 1; 153 | break; 154 | } 155 | } 156 | if (devname == NULL) { 157 | usage(-1); 158 | } 159 | if (debug == 1) { 160 | printf("USING CAPTURE DEVICE: %s\n", devname); 161 | } 162 | 163 | pcap_if_t *alldevsp , *device; 164 | pcap_t *handle; 165 | char errbuf[100] , devs[100][100]; 166 | int count = 1 , n; 167 | handle = pcap_open_live(devname , 65536 , 1 , 0 , errbuf); 168 | if (handle == NULL) { 169 | fprintf(stderr, "Couldn't open device %s : %s\n" , devname , errbuf); 170 | exit(1); 171 | } 172 | pcap_compile(handle, &fcode, packet_filter, 1, netmask); 173 | 174 | if ( pcap_loop(handle, -1, processPacket, (u_char *)&count) == -1) { 175 | fprintf(stderr, "ERROR: %s\n", pcap_geterr(descr) ); 176 | exit(1); 177 | } 178 | 179 | 180 | return 0; 181 | } 182 | void usage(int8_t e) 183 | { 184 | printf( "Usage: dmrmon-remote [OPTION]... [REMOTE SERVER]...\n" 185 | "Listen send DMR data for remote server for processing\n" 186 | "\n" 187 | " -i, --interface Interface to listen on\n" 188 | " -h, --help This Help\n" 189 | " -V, --version Version Information\n" 190 | " -d, --debug Show verbose information\n" 191 | " -p, --payload Dump UDP payload data in one line hex (usefull for reverse engineering)\n" 192 | " -o, --dmr Only print packets identified as DMR\n" 193 | "\n" 194 | "With no REMOTE SERVER or REMOTE SERVER is -, output to standard output\n" 195 | "\n" 196 | "Examples:\n" 197 | " dmrmon-remote -i eth0 192.168.10.20 50000\n" 198 | " Send the DMR data heard on eth0 to remote server\n" 199 | "\n" 200 | "Report cat bugs to kd8eyf@digitalham.info\n"); 201 | exit(e); 202 | } 203 | 204 | int version ( void ) 205 | { 206 | printf ("dmrmon 0.01\n"); 207 | exit(1); 208 | } 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | -------------------------------------------------------------------------------- /DMRserver/dmr-server.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # DAVID KIERZKOWSKI, KD8EYF 4 | # 13287 Teak Ct. 5 | # Sterling Heights, MI 48312 6 | # 7 | # (C) Hans-J. Barthen, DL5DI 8 | # Franz-Josef-Str. 20 9 | # D-56642 Kruft 10 | # 11 | # RAW UDP VOICE PAYLOAD HEX OFFSET- THANKS 2 DL5DI 12 | # OFFSET: 0 USE: Format ID L:A/GI 13 | # OFFSET: 1-4 USE: Repeater ID 14 | # OFFSET: 5 USE: Sequence Number 15 | # OFFSET: 6-8 USE: Source ID 16 | # OFFSET: 9-11 USE: DestinationID 17 | # OFFSET: 12 USE: Priority Voice / Data 18 | # OFFSET: 13-16 USE: Call Control 19 | # OFFSET: 17 USE: Call Control Info 20 | # OFFSET: 18 USE: Controb Source ID 21 | # OFFSET: 17b32 USE: Timeslot 22 | # OFFSET: 19 USE: Payload Type 23 | # OFFSET: 20-21 USE: Sequence Number 24 | # OFFSET: 22-25 USE: TimeStamp 25 | # OFFSET: 26-29 USE: SyncSrcID 26 | # OFFSET: 30 USE: DataTypeVoiceHeader 27 | # OFFSET: 31 USE: RSSI/threshold and parity values 28 | # OFFSET: 32-33 USE: length to follow (words) 29 | # OFFSET: 34 USE: RSSI Status 30 | # OFFSET: 35 USE: Slot Type Sync 31 | # OFFSET: 36-37 USE: Data Size 32 | 33 | # 0 1 2 3 34 | # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234 35 | # 2012-09-16 23:17:25 50201 98 312601 6a 36 | # 2012-09-16 23:11:15 50201 80 312601 145 3126002 2 02 00004e00 20 80 dd 64761 1183fed8 0 01 80 11 84 0a 96 37 | # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 38 | 39 | # DL5DI DMR-MONITOR.pl VOICE STRING 40 | # POSITION:1 USE: DATE 41 | # POSITION:2 USE: TIME 42 | # POSITION:3 USE: Source Network 43 | # POSITION:4 USE: PAcket Type 44 | # POSITION:5 USE: Source Repeater ID 45 | # POSITION:6 USE: Call Sequence Number 46 | # POSITION:7 USE: Destination ID 47 | # POSITION:8 USE: Prio - Voice / Data ? 48 | # POSITION:9 USE: Flow Control Flags 49 | # POSITION:10 USE: CallControlInfo 50 | # POSITION:11 USE: ContribSrcID 51 | # POSITION:12 USE: Payload Type 52 | # POSITION:13 USE: Sequence Number 53 | # POSITION:14 USE: TimeStamp 54 | # POSITION:15 USE: SyncSrcID 55 | # POSITION:16 USE: DataTypeVoiceHeader 56 | # POSITION:17 USE: RSSI Threshold and Parity Values 57 | # POSITION:18 USE: Length in words to follow 58 | # POSITION:19 USE: Rssi Status 59 | # POSITION:20 USE: Slot Type 60 | # POSITION:21 USE: Data Size 61 | use IO::Socket::INET; #Load Network module 62 | use DBI; #load db module 63 | my ($socket,$rdata); 64 | my ($peeraddress,$peerport); 65 | $socket = new IO::Socket::INET (LocalPort => 50000,Proto => 'udp',) or die "ERROR in Socket Creation : $!\n"; #open UDP port 66 | $err = 0; 67 | while($err == 0) { 68 | $SqlConn ||= DBI->connect("DBI:mysql:database=dmrdb:host=localhost", "dmruser") or die "Can't connect to database: $DBI::errstr\n"; #connect to db 69 | $Frame = $socket->getline(); #store new line in a Frame 70 | #print $Frame; 71 | ($Date,$Time,$SourceNet,$PacketTypeHex) = split(/ /,$Frame); #Get The timestamp network and type of packet for pre processing 72 | $DateTime = $Date . " " . $Time; #assemble timestamp 73 | $PacketType = hex($PacketTypeHex); #decode packet type from hex to dec 74 | if (($PacketType ge 150) && ($PacketType le 153)){ #looks like a MOTOROLA HEARTBEAT 75 | ($DmrID,$TimeSlotHex) = split(/ /,substr($Frame,29)); #pull out the timeslot status 76 | $Ts1Online = "0"; # 77 | $Ts2Online = "0"; 78 | if(hex(substr($TimeSlotHex,1,1)) & 2) { $Ts2Online = 1; } 79 | if(hex(substr($TimeSlotHex,1,1)) & 8) { $Ts1Online = 1; } 80 | printf "HB TYP:%s TS1:%s TS2:%s RTD: %08d SRN: %05d\n",$PacketType, $Ts1Online, $Ts2Online, $DmrID, $SourceNet; 81 | $Query = "INSERT INTO `Network` (`DmrID`,`Description`,`Publish`,`DateTime`) VALUES ('$SourceNet', 'UNKNOWN - $SourceNet', '0', '$DateTime') ON DUPLICATE KEY UPDATE DateTime='$DateTime';"; 82 | $Statement = $SqlConn->prepare($Query); 83 | $Statement->execute(); 84 | $Query = "INSERT INTO `RepeaterLog` (`DmrID`, `SourceNet`, `DateTime`, `Ts1Online`, `Ts2Online`, `PacketType`, `TimeSlotRaw`) VALUES ('$DmrID','$SourceNet','$DateTime','$Ts1Online','$Ts2Online','$PacketType','$TimeSlotHex');"; 85 | $Statement = $SqlConn->prepare($Query); 86 | $Statement->execute(); 87 | $Query = "INSERT INTO `Repeater` (`DmrID`, `SourceNet`, `LastHeard`, `Ts1Online`, `Ts2Online`) VALUES ('$DmrID','$SourceNet','$DateTime','$Ts1Online','$Ts2Online') ON DUPLICATE KEY UPDATE `LastHeard` = '$DateTime', `SourceNet` = '$SourceNet', `Ts1Online` = '$Ts1Online', `Ts2Online` = '$Ts2Online';"; 88 | } 89 | $Statement = $SqlConn->prepare($Query); 90 | $Statement->execute(); 91 | if (($PacketType ge 128) && ($PacketType le 132)) { #MOTOROLA VOICE / DATA 92 | ($RepeaterID,$Sequence,$DmrID,$DestinationID,$Priority,$FlowControlFlags,$CallControlInfo,$ContribSrcID,$PayloadType,$SeqNumber,$TimeStamp,$SyncSrcID,$DataType,$RssiThreshold,$Length,$RssiStatus,$SlotType,$DataSize) = split(/ /,substr($Frame,29)); 93 | $TimeSlot=1;$Group=0;$Private=0;$Final=0;$Data=0;$Voice=0;$Private=0;$Answer=0; 94 | if(hex(substr($CallControlInfo,0,1)) & 2) { $TimeSlot = 2; } 95 | if(hex(substr($CallControlInfo,0,1)) & 4) { $Final = 1;} 96 | if(hex(substr($PacketTypeHex,1,1)) & 4) { $Answer = 1;} 97 | elsif(hex(substr($PacketTypeHex,1,1)) & 1) { $Private = 1;} 98 | else{ $Group = 1;} 99 | if(hex(substr($Priority,1,1)) & 1) { $Data = "1";} 100 | if(hex(substr($Priority,1,1)) & 2) { $Voice = "1";} 101 | printf "V/D TS:%s G:%s P:%s F:%s D:%s V:%s A:%s TYP:%s RID:%08d SEQ:%03d DMRID:%08d DST:%08d PRI:%s FCF:%s CCI:%s CSI:%s PLT:%s SQN:%05s TSP:%s SSI:%s DAT:%s RST:%s LEN:%02s RSS:%s SLT:%s DAS:%05s",$TimeSlot,$Group,$Private,$Final,$Data,$Voice,$Answer,$PacketType,$RepeaterID,$Sequence,$DmrID,$DestinationID,$Priority,$FlowControlFlags,$CallControlInfo,$ContribSrcID,$PayloadType,$SeqNumber,$TimeStamp,$SyncSrcID,$DataType,$RssiThreshold,$Length,$RssiStatus,$SlotType,$DataSize; 102 | $Query = "INSERT INTO `Network` (`DmrID`,`Description`,`Publish`,`DateTime`) VALUES ('$SourceNet', 'UNKNOWN - $SourceNet', '0', '$DateTime') ON DUPLICATE KEY UPDATE DateTime='$DateTime';"; 103 | $Statement = $SqlConn->prepare($Query); 104 | $Statement->execute(); 105 | $Query = "INSERT INTO `dmrdb`.`UserLog` (`Key`, `StartTime`, `EndTime`, `SourceNet`, `PacketType`, `RepeaterID`, `DmrID`, `DestinationID`, `Sequence`, `TimeSlot`, `GroupCall`, `PrivateCall`, `VoiceCall`, `DataCall`, `Priority`, `FlowControlFlags`, `CallControlInfo`, `ContribSrcID`, `PayloadType`, `SeqNumber`, `TimeStamp`, `SyncSrcID`, `DataType`, `RssiThreshold`, `Length`, `RssiStatus`, `SlotType`, `DataSize`) VALUES (MD5('$Date$SourceID$RepeaterID$Sequence$SourceNet$TimeSlot'),'$DateTime','0000-00-00 00:00:00','$SourceNet', '$PacketType', '$RepeaterID', '$DmrID', '$DestinationID', '$Sequence', '$TimeSlot','$Group','$Private','$Voice','$Data','$Priority','$FlowControlFlags','$CallControlInfo','$ContribSrcID','$PayloadType','$SeqNumber','$TimeStamp','$SyncSrcID','$DataType','$RssiThreshold','$Length','$RssiStatus','$SlotType','$DataSize') ON DUPLICATE KEY UPDATE EndTime='$DateTime';"; 106 | $Statement = $SqlConn->prepare($Query); 107 | $Statement->execute(); 108 | $Query = "INSERT INTO `dmrdb`.`LastHeard` (`DmrID`,`StartTime`,`SourceNet`,`TimeSlot`,`RepeaterID`,`DestinationID`) VALUES('$DmrID','$DateTime','$SourceNet','$TimeSlot','$RepeaterID','$DestinationID') ON DUPLICATE KEY UPDATE StartTime='$DateTime', SourceNet='$SourceNet', TimeSlot='$TimeSlot', RepeaterID='$RepeaterID', DestinationID='$DestinationID';"; 109 | $Statement = $SqlConn->prepare($Query); 110 | $Statement ->execute(); 111 | } 112 | } 113 | $dbh->close; 114 | $socket->close(); 115 | exit; 116 | 117 | -------------------------------------------------------------------------------- /DMRserver/dmrmon-server.c: -------------------------------------------------------------------------------- 1 | /* 2 | dmrmon-server - listen for dmrmon-remote and update database 3 | Copyright (C) 2012 David Kierzokwski (kd8eyf@digitalham.info) 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -------------------------------------------------------------------------------- /README.hytera: -------------------------------------------------------------------------------- 1 | Hytera "Multi Site Connect" Protocol 2 | Voice Packets 114 bytes Port 30001 3 | Keepalive/Control? 60/102/146/162 bytes port 30000/30002 4 | 5 | |------------------------------------------------------------------------| 6 | | Hytera Voice UDP Payload | 7 | |0 1 2 3 | 8 | |0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 | 9 | |------------------------------------------------------------------------| 10 | |<4 BYTE><> <> <---- AMBE+2 VOICE | 11 | |------------------------------------------------------------------------| 12 | 13 | cont... 14 | 15 | |------------------------------------------------------------------------| 16 | |3 4 5 6 7 | 17 | |6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | 18 | |------------------------------------------------------------------------| 19 | |----> <--SYNC --> <---- AMBE+2 VOICE ----> <> | 20 | |------------------------------------------------------------------------| 21 | OFFSET 0 - 3 22 | "ZZZZ" = some form of special frame, always denoted with 23 | pattern at offset 0x08 24 | 0xXXXX = Offset 18 - 19 "BBBB" or "1111" 25 | the first 2 bytes are the port number e.g. 0x7531 = 30001 26 | 27 | OFFSET 4 28 | 00 to FF = Voice Frame Sequence Number Looping 29 | Does not Increment for Sync Frames 30 | 31 | OFFSET 8 32 | 0x01 = Voice Frame 33 | 0x02 = Start Of Transmission or Sync Frame 34 | 0x03 = End of Transmission 35 | 0x42 = "B" as a part of "BZZZ" 36 | 37 | OFFSET 9 38 | "ZZZ" - only when the value at offset 8 is "B" 39 | always associated with pattern at Offset 0x00 noted above 40 | 41 | OFFSET 16 - 17 42 | "1111" = Slot 1 43 | "2222" = Slot 2 44 | 45 | OFFSET 18 - 19 46 | "DDDD" = Startup packet 47 | "1111" = Startup packet 48 | "EEEE" = Sync packet 49 | "7777" = Voice packet 50 | "8888" = Voice packet 51 | "9999" = Voice packet 52 | "AAAA" = Voice packet 53 | "BBBB" = Voice packet 54 | "CCCC" = Voice packet 55 | 56 | Start of Transmission SEQUENCE: DDE1E1E1 57 | Voice Sequence w/ Sync: 789AEBC 58 | Voice Packets: 789ABC 59 | 60 | OFFSET 20 - 21 61 | "1111" - Always 62 | 63 | OFFSET 22 - 23 64 | "0000" - Not Sync Packet 65 | "1111" - Sync Packet 66 | 67 | OFFSET 38,40,42 ( Sync Packets Only ) 68 | Source Radio ID Bytes ( Big Endian ) 69 | 70 | OFFSET 26 - 38 plus high order nibble of 39 for 13.5 bytes 71 | AMBE+2 1 of 2 VOICE AND DATA 72 | 73 | OFFSET 39 low order nibble - 44 plus high order nibble of 45 for total of 6 bytes 74 | DMR Sync frame between all VOICE / DATA Packets 75 | 76 | OFFSET 45 - 58 (starts at low order nibble of 45 through 58 for 13.5 bytes 77 | AMBE+2 2 of 2 VOICE AND DATA 78 | 79 | OFFSET 62 80 | 0x00 = Private Call 81 | 0x01 = Group Call 82 | 83 | OFFSET 64 - 66 84 | Destination Group ID ( big endian ) 85 | 86 | OFFSET 67 - 69 87 | Source ID ( little endian ) - First Byte Missing -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenIPSC 2 | ======== 3 | Utilities for DMR radio networks 4 | 5 | DMRmonitor - promiscisuly listenes to a interface and pass DMR traffic to dmrmon-server. NOT FUNCTIONAL YET. 6 | 7 | DMRserver - listen for dmrmon-remote data, save to database. CURRENTLY WORKS WITH DL5DI modified 'windump' 8 | 9 | sql - mysql database structure dumps 10 | 11 | scripts - command line scripts 12 | 13 | web - call log, last heard, and net status web pages. (still in development) 14 | 15 | pcap - wireshark capture files 16 | 17 | 18 | 19 | README.motorola - Information on mototrbo IPSC protocol 20 | 21 | README.hytera - Information in hytera MultiSite Connect Protocol 22 | 23 | -------------------------------------------------------------------------------- /README.motorola: -------------------------------------------------------------------------------- 1 | Motorolas MOTOTRBO IPSC protocol 2 | -----------------------------------------------------------------------------------------------------------------------------| 3 | | IPSC HEARBEAT UDP PACKET | 4 | |0 1 2 3 4 5 6 | 5 | |0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | 6 | |----------------------------------------------------------------------------------------------------------------------------| 7 | |3c754A779848ca4c7577bfe2080045200030f53e00006d11c4a2436c5679443db599c350c450001cbb1398000000f84000000030220fd1e25c79e348661f| 8 | |----------------------------------------------------------------------------------------------------------------------------| 9 | |< ETHERNET HEADER >< IPv4 HEADER >< UDP HEADER >< IPSC HEARTBEAT DATA >| 10 | 000 - 005 : Dst mac address 11 | 006 - 011 : Src mac address 12 | 012 - 013 : Packet type (IP 0x0800) 13 | 023 - 023 : Protocol (UDP 17) 14 | 026 - 029 : Src IPv4 Address 15 | 030 - 033 : Dst IPv4 Address 16 | 034 - 035 : Src UDP Port 17 | 036 - 037 : Dst UDP Port 18 | 040 - 041 : Checksum 19 | 042 - 042 : Format 20 | 046 - 048 : Repeater Peer DMR Id 21 | 049 - 050 : Destination Dmr Id (Talkgroub) 22 | 051 - 051 : Voice / Data 23 | 052 - 055 : Control Flags 24 | 056 - 056 : Call Start Stop Flags 25 | 057 - 057 : ?? << coming soon 26 | 27 | 28 | Portions of the UDP payload may be scrambled with RC4. CPS ( Customer programming software ) has a "authenciation key" field that is "40 characters 0-9, A-f". Possible that this value is used by the hardware as the keystream and not the key? 29 | 30 | -------------------------------------------------------------------------------- /pcap/H1G031440010314400100000002.pcap.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/japskunk/OpenIPSC/dfaf2e78378dded4f98105f5be62ce1d51acae52/pcap/H1G031440010314400100000002.pcap.gpg -------------------------------------------------------------------------------- /pcap/H1G121212121313131306969696.pcap.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/japskunk/OpenIPSC/dfaf2e78378dded4f98105f5be62ce1d51acae52/pcap/H1G121212121313131306969696.pcap.gpg -------------------------------------------------------------------------------- /pcap/H1P121212121313131306969696.pcap.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/japskunk/OpenIPSC/dfaf2e78378dded4f98105f5be62ce1d51acae52/pcap/H1P121212121313131306969696.pcap.gpg -------------------------------------------------------------------------------- /pcap/H1P121212121313131307878787.pcap.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/japskunk/OpenIPSC/dfaf2e78378dded4f98105f5be62ce1d51acae52/pcap/H1P121212121313131307878787.pcap.gpg -------------------------------------------------------------------------------- /pcap/H2G031440010314400100000001.pcap.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/japskunk/OpenIPSC/dfaf2e78378dded4f98105f5be62ce1d51acae52/pcap/H2G031440010314400100000001.pcap.gpg -------------------------------------------------------------------------------- /pcap/H2G121212121313131307878787.pcap.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/japskunk/OpenIPSC/dfaf2e78378dded4f98105f5be62ce1d51acae52/pcap/H2G121212121313131307878787.pcap.gpg -------------------------------------------------------------------------------- /pcap/HyteraMasterReboot.pcap.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/japskunk/OpenIPSC/dfaf2e78378dded4f98105f5be62ce1d51acae52/pcap/HyteraMasterReboot.pcap.gpg -------------------------------------------------------------------------------- /pcap/README: -------------------------------------------------------------------------------- 1 | Captures are filtered currently only showing 1 Master and 1 slave device. 2 | encrypted to protect source network. Email davidkierz@gmail.com for decryption key 3 | 4 | MSTRRRRRRRRSSSSSSSSDDDDDDDD.pcap 5 | 6 | M:Manufacture H hytera, M Motorola 7 | S:Slot 1 or 2 8 | T:Type G group voice P private voice 9 | R:Repeater DMR ID for the Source Repetaer 10 | S:Src Radio DMR ID for the Source Radio 11 | D:Destination DMR ID for the Destination 12 | -------------------------------------------------------------------------------- /pcap/status.cap.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/japskunk/OpenIPSC/dfaf2e78378dded4f98105f5be62ce1d51acae52/pcap/status.cap.gpg -------------------------------------------------------------------------------- /scripts/DmrMarcRip.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | $Value) { 98 | $Query = $Query."`".$Key."` = '".$Value."', "; 99 | } 100 | $Query = trim($Query,", "); 101 | $Query = "UPDATE `".$Table."` SET ".$Query." WHERE `".$Table."`.".$Where; 102 | return ($Query); 103 | } 104 | function LogChange($NewItem,$ChangeType, $RecordType) //LOG CHANGES TO THE CHANGE LOG 105 | { 106 | global $DateTime; 107 | switch ($ChangeType) { 108 | case "NEW": 109 | foreach ($NewItem as $NewKey => $NewValue) { 110 | $NewQuery = "INSERT INTO `ChangeLog` (`DateTime`,`DmrID`,`RecordType`,`FieldName`,`OldValue`,`NewValue`,`Event`) VALUES ('$DateTime','$NewItem[DmrID]','$RecordType','$NewKey','','$NewValue','ADD');"; 111 | mysql_query($NewQuery) or die(mysql_error()); 112 | } 113 | break; 114 | case "DELETE": 115 | foreach ($NewItem as $NewKey => $NewValue) { 116 | $DelQuery = "INSERT INTO `ChangeLog` (`DateTime`,`DmrID`,`RecordType`,`FieldName`,`OldValue`,`NewValue`,`Event`) VALUES ('$DateTime','$NewItem[DmrID]','$RecordType','$NewKey','$NewValue','','DELETE');"; 117 | mysql_query($DelQuery) or die(mysql_error()); 118 | } 119 | break; 120 | case "CHANGE": 121 | $DiffQuery = "INSERT INTO `ChangeLog` (`DateTime`,`DmrID`,`RecordType`,`FieldName`,`OldValue`,`NewValue`,`Event`) VALUES ('$DateTime','$NewItem[DmrID]','$RecordType','$NewItem[FieldName]','$NewItem[OldValue]','$NewItem[NewValue]','CHANGE');"; 122 | 123 | mysql_query($DiffQuery) or die(mysql_error()); 124 | break; 125 | } 126 | } 127 | function RipData($Url,$ColumnNames,$key) { 128 | $Dom = new DOMDocument(); 129 | $doctype = DOMImplementation::createDocumentType("html","-//W3C//DTD XHTML 1.1//EN","http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"); 130 | $Dom->appendChild($doctype); 131 | $Page = $Dom->loadHTMLFile($Url); //CRAEATE NEW DOM OBJECT 132 | $Dom->preserveWhiteSpace = false; //DELETE HTML WHITE SPACES 133 | $Table = $Dom->getElementsByTagName('table'); //IDENTIFY START OF TABLE 134 | $Rows = $Table->item(0)->getElementsByTagName('tr'); //IDENTIFY ROWS 135 | foreach ($Rows as $row) { //START A LOOP FOR EACH ROW 136 | $cols = $row->getElementsByTagName('td'); //GET THE COLUMNS 137 | if (is_numeric($cols->item($key)->textContent)) { //IS THIS AN ITEM THAT WE WANT TO PROCESS 138 | $i = 0; 139 | foreach ($cols as $col) { //LOOP THROUGH EACH COL AND STORE IN ARRAY 140 | $array[$cols->item($key)->nodeValue][$ColumnNames[$i]] =str_replace("NBSP","",strtoupper(trim(preg_replace("/[^0-9a-zA-Z .-]/","",$col->textContent)))); 141 | $i++; 142 | } 143 | } 144 | } 145 | return $array; 146 | } 147 | function GetOldData($TableName,$FieldNames) { //GET DATA FROM YESTERDAYS DMR-MARC DATABASE 148 | $Query = "SELECT * FROM `".$TableName."`;"; 149 | $Result = mysql_query($Query) or die("Error in query: $query ".mysql_error()); 150 | $NumResults = mysql_num_rows($Result); 151 | if ($NumResults > 0) { 152 | while ($row = mysql_fetch_array($Result,MYSQL_ASSOC)) { 153 | foreach ($FieldNames as $FieldName) { 154 | $array[$row[DmrID]][$FieldName] = $row[$FieldName]; //AM I OVERTHINKING THIS? 155 | } 156 | } 157 | } 158 | if (is_null($array)) 159 | { 160 | return array(); 161 | } 162 | else 163 | { 164 | return $array; 165 | } 166 | } 167 | 168 | function DBChange($Old,$New,$Both,$Table){ //CHANGE AN ITEM IN THE DATABASE 169 | foreach ($Both as $DiffRow) { 170 | $Diff = array_diff($New[$DiffRow[DmrID]],$Old[$DiffRow[DmrID]]); 171 | if ($Diff) { 172 | $ChangeQuery = BuildSqlUpdate($DiffRow,$Table,"`DmrID`='".$DiffRow[DmrID]."'")."\n"; 173 | print $Query."\n"; 174 | mysql_query($ChangeQuery) or die(mysql_error()); 175 | foreach ($Diff as $DifferentItemKey => $DifferentItemVal) { 176 | $DiffArray = array('DmrID' => $DiffRow[DmrID],'FieldName' => $DifferentItemKey, 177 | 'OldValue' => $DifferentItemVal,'NewValue' => $Old[$DiffRow[DmrID]][$DifferentItemKey]); 178 | LogChange($DiffArray,"CHANGE",$Table); 179 | } 180 | } 181 | } 182 | } 183 | function DBAdd($new,$table) { //ADD A ITEM TO THE DATABASE 184 | if (count($new) != false) { 185 | foreach ($new as $AddRow) { 186 | $Query = BuildSqlInsert($AddRow,$table)."\n"; 187 | mysql_query($Query) or die(mysql_error()); 188 | LogChange($AddRow,"NEW",$table); 189 | } 190 | } 191 | } 192 | function DBRemove($del,$table) { //REMOVE A ITEM FROM TEH DATABASE 193 | if (count($del) != false) { 194 | foreach ($del as $DelRow) { 195 | $Where = "`DmrID`='".$DelRow[DmrID]."'"; 196 | $Query = BuildSqlRemove($DelRow,$table,$Where); 197 | mysql_query($Query) or die(mysql_error()); 198 | LogChange($DelRow,"DELETE",$table); 199 | } 200 | } 201 | } 202 | 203 | ?> 204 | 205 | -------------------------------------------------------------------------------- /sql/dmrdb_dump.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 3.5.2.2 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: Oct 29, 2012 at 03:45 PM 7 | -- Server version: 5.0.51a-24+lenny5-log 8 | -- PHP Version: 5.2.6-1+lenny16 9 | 10 | SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | -- 14 | -- Database: `dmrdb` 15 | -- 16 | 17 | -- -------------------------------------------------------- 18 | 19 | -- 20 | -- Table structure for table `ChangeLog` 21 | -- 22 | -- Creation: Sep 15, 2012 at 09:54 PM 23 | -- Last update: Oct 29, 2012 at 04:00 AM 24 | -- 25 | 26 | DROP TABLE IF EXISTS `ChangeLog`; 27 | CREATE TABLE IF NOT EXISTS `ChangeLog` ( 28 | `DateTime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, 29 | `DmrID` int(32) NOT NULL, 30 | `RecordType` char(10) NOT NULL, 31 | `FieldName` char(32) NOT NULL, 32 | `OldValue` char(64) NOT NULL, 33 | `NewValue` varchar(64) NOT NULL, 34 | `Event` char(32) NOT NULL 35 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 36 | 37 | -- -------------------------------------------------------- 38 | 39 | -- 40 | -- Table structure for table `LastHeard` 41 | -- 42 | -- Creation: Oct 29, 2012 at 07:17 PM 43 | -- Last update: Oct 29, 2012 at 07:45 PM 44 | -- 45 | 46 | DROP TABLE IF EXISTS `LastHeard`; 47 | CREATE TABLE IF NOT EXISTS `LastHeard` ( 48 | `DmrID` int(11) NOT NULL, 49 | `StartTime` datetime NOT NULL, 50 | `SourceNet` int(11) NOT NULL, 51 | `TimeSlot` int(1) NOT NULL, 52 | `RepeaterID` int(11) NOT NULL, 53 | `DestinationID` int(11) NOT NULL, 54 | PRIMARY KEY (`DmrID`) 55 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 56 | 57 | -- -------------------------------------------------------- 58 | 59 | -- 60 | -- Table structure for table `Network` 61 | -- 62 | -- Creation: Sep 20, 2012 at 10:23 PM 63 | -- Last update: Oct 29, 2012 at 07:45 PM 64 | -- 65 | 66 | DROP TABLE IF EXISTS `Network`; 67 | CREATE TABLE IF NOT EXISTS `Network` ( 68 | `DmrID` int(7) NOT NULL, 69 | `Description` varchar(64) NOT NULL, 70 | `Publish` tinyint(1) NOT NULL default '1', 71 | `Mi5Publish` tinyint(1) NOT NULL, 72 | `DateTime` datetime NOT NULL, 73 | PRIMARY KEY (`DmrID`) 74 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 75 | 76 | -- -------------------------------------------------------- 77 | 78 | -- 79 | -- Table structure for table `NetworkAffilate` 80 | -- 81 | -- Creation: Aug 18, 2012 at 09:52 PM 82 | -- Last update: Aug 18, 2012 at 09:52 PM 83 | -- Last check: Sep 12, 2012 at 09:36 AM 84 | -- 85 | 86 | DROP TABLE IF EXISTS `NetworkAffilate`; 87 | CREATE TABLE IF NOT EXISTS `NetworkAffilate` ( 88 | `Description` text NOT NULL, 89 | `Pin` text NOT NULL, 90 | `ID` int(11) NOT NULL, 91 | PRIMARY KEY (`ID`), 92 | FULLTEXT KEY `Description` (`Description`) 93 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 94 | 95 | -- -------------------------------------------------------- 96 | 97 | -- 98 | -- Table structure for table `Prefix` 99 | -- 100 | -- Creation: May 30, 2012 at 10:44 AM 101 | -- Last update: Oct 18, 2012 at 04:00 AM 102 | -- Last check: Sep 12, 2012 at 09:35 AM 103 | -- 104 | 105 | DROP TABLE IF EXISTS `Prefix`; 106 | CREATE TABLE IF NOT EXISTS `Prefix` ( 107 | `DmrID` char(64) NOT NULL, 108 | `Country` char(64) NOT NULL, 109 | `State` char(64) NOT NULL, 110 | `Group` char(64) NOT NULL 111 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='DMR-ID Geographic Numbering Scheme'; 112 | 113 | -- -------------------------------------------------------- 114 | 115 | -- 116 | -- Table structure for table `Repeater` 117 | -- 118 | -- Creation: Oct 02, 2012 at 02:10 PM 119 | -- Last update: Oct 29, 2012 at 07:45 PM 120 | -- Last check: Oct 02, 2012 at 02:10 PM 121 | -- 122 | 123 | DROP TABLE IF EXISTS `Repeater`; 124 | CREATE TABLE IF NOT EXISTS `Repeater` ( 125 | `DmrID` int(8) NOT NULL, 126 | `Callsign` char(6) NOT NULL, 127 | `City` char(32) NOT NULL, 128 | `State` char(32) NOT NULL, 129 | `Country` char(32) NOT NULL, 130 | `Frequency` char(32) NOT NULL, 131 | `PublishFrequency` decimal(10,5) NOT NULL, 132 | `ColorCode` int(11) NOT NULL, 133 | `Offset` char(32) NOT NULL, 134 | `Assigned` char(32) NOT NULL, 135 | `Linked` char(32) NOT NULL, 136 | `Trustee` char(32) NOT NULL, 137 | `IpscNetwork` char(32) NOT NULL, 138 | `LastHeard` datetime NOT NULL, 139 | `Override` tinyint(1) NOT NULL default '0', 140 | `Ts1Online` tinyint(1) NOT NULL, 141 | `Ts2Online` tinyint(1) NOT NULL, 142 | `Publish` tinyint(1) NOT NULL default '0', 143 | `OverrideOnline` tinyint(1) NOT NULL default '0', 144 | `OverrideTs1Online` tinyint(1) NOT NULL default '0', 145 | `OverrideTs2Online` tinyint(1) NOT NULL default '0', 146 | `Role` binary(1) NOT NULL default '0' COMMENT '1 = Master 0 = Slave', 147 | `lat` text NOT NULL, 148 | `long` text NOT NULL, 149 | `Affilated` tinyint(1) NOT NULL default '0', 150 | `AffilatedNet` text NOT NULL, 151 | `Map` tinyint(1) NOT NULL default '0', 152 | `Short` text NOT NULL, 153 | `SourceNet` int(11) NOT NULL, 154 | PRIMARY KEY (`DmrID`), 155 | KEY `Affilated` (`Affilated`) 156 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='DMR-MARC and other database of worldwide repeaters'; 157 | 158 | -- 159 | -- RELATIONS FOR TABLE `Repeater`: 160 | -- `SourceNet` 161 | -- `Network` -> `DmrID` 162 | -- 163 | 164 | -- -------------------------------------------------------- 165 | 166 | -- 167 | -- Table structure for table `RepeaterLog` 168 | -- 169 | -- Creation: Sep 12, 2012 at 06:20 PM 170 | -- Last update: Oct 29, 2012 at 07:45 PM 171 | -- 172 | 173 | DROP TABLE IF EXISTS `RepeaterLog`; 174 | CREATE TABLE IF NOT EXISTS `RepeaterLog` ( 175 | `ID` int(11) NOT NULL auto_increment, 176 | `DmrID` int(11) NOT NULL, 177 | `SourceNet` int(11) NOT NULL, 178 | `DateTime` datetime NOT NULL, 179 | `Ts1Online` int(11) NOT NULL, 180 | `Ts2Online` int(11) NOT NULL, 181 | `PacketType` int(11) NOT NULL, 182 | `TimeSlotRaw` varchar(2) NOT NULL, 183 | PRIMARY KEY (`ID`) 184 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3017642 ; 185 | 186 | -- 187 | -- RELATIONS FOR TABLE `RepeaterLog`: 188 | -- `DmrID` 189 | -- `Repeater` -> `DmrID` 190 | -- 191 | 192 | -- -------------------------------------------------------- 193 | 194 | -- 195 | -- Table structure for table `Talkgroup` 196 | -- 197 | -- Creation: Aug 18, 2012 at 10:01 PM 198 | -- Last update: Sep 13, 2012 at 04:00 AM 199 | -- Last check: Sep 12, 2012 at 09:36 AM 200 | -- 201 | 202 | DROP TABLE IF EXISTS `Talkgroup`; 203 | CREATE TABLE IF NOT EXISTS `Talkgroup` ( 204 | `Network` char(32) NOT NULL, 205 | `Region` char(32) NOT NULL, 206 | `DmrID` int(11) NOT NULL, 207 | `Assignment` char(32) NOT NULL, 208 | `Notes` char(32) NOT NULL, 209 | PRIMARY KEY (`DmrID`) 210 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 211 | 212 | -- -------------------------------------------------------- 213 | 214 | -- 215 | -- Table structure for table `User` 216 | -- 217 | -- Creation: Sep 15, 2012 at 09:16 PM 218 | -- Last update: Oct 29, 2012 at 04:00 AM 219 | -- 220 | 221 | DROP TABLE IF EXISTS `User`; 222 | CREATE TABLE IF NOT EXISTS `User` ( 223 | `DmrID` int(11) NOT NULL, 224 | `Callsign` char(32) NOT NULL, 225 | `Name` char(32) NOT NULL, 226 | `City` char(32) NOT NULL, 227 | `State` char(32) NOT NULL, 228 | `Country` char(32) NOT NULL, 229 | `Radio` char(32) NOT NULL, 230 | `HomeRepeaterID` char(32) NOT NULL, 231 | `Remarks` char(32) NOT NULL, 232 | UNIQUE KEY `DmrID` (`DmrID`) 233 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 234 | 235 | -- -------------------------------------------------------- 236 | 237 | -- 238 | -- Table structure for table `UserLog` 239 | -- 240 | -- Creation: Sep 17, 2012 at 12:59 AM 241 | -- Last update: Oct 29, 2012 at 07:45 PM 242 | -- 243 | 244 | DROP TABLE IF EXISTS `UserLog`; 245 | CREATE TABLE IF NOT EXISTS `UserLog` ( 246 | `Key` char(32) NOT NULL, 247 | `StartTime` datetime NOT NULL, 248 | `EndTime` datetime NOT NULL, 249 | `SourceNet` int(11) NOT NULL, 250 | `PacketType` int(2) NOT NULL, 251 | `RepeaterID` int(11) NOT NULL, 252 | `DmrID` int(11) NOT NULL, 253 | `DestinationID` int(11) NOT NULL, 254 | `Sequence` int(11) NOT NULL, 255 | `TimeSlot` int(11) NOT NULL, 256 | `GroupCall` int(11) NOT NULL, 257 | `PrivateCall` int(11) NOT NULL, 258 | `VoiceCall` tinyint(1) NOT NULL, 259 | `DataCall` int(11) NOT NULL, 260 | `Priority` char(4) NOT NULL, 261 | `FlowControlFlags` char(10) NOT NULL, 262 | `CallControlInfo` char(4) NOT NULL, 263 | `ContribSrcID` char(4) NOT NULL, 264 | `PayloadType` char(4) NOT NULL, 265 | `SeqNumber` char(6) NOT NULL, 266 | `TimeStamp` char(8) NOT NULL, 267 | `SyncSrcID` char(4) NOT NULL, 268 | `DataType` char(4) NOT NULL, 269 | `RssiThreshold` char(4) NOT NULL, 270 | `Length` char(4) NOT NULL, 271 | `RssiStatus` char(4) NOT NULL, 272 | `SlotType` char(4) NOT NULL, 273 | `DataSize` char(4) NOT NULL, 274 | PRIMARY KEY (`Key`) 275 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 276 | 277 | -- 278 | -- RELATIONS FOR TABLE `UserLog`: 279 | -- `DmrID` 280 | -- `User` -> `DmrID` 281 | -- 282 | 283 | -------------------------------------------------------------------------------- /web/calllog.php: -------------------------------------------------------------------------------- 1 | 20 | 21 | 22 | 23 | 39 |
40 |
41 |

Call Log

42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 93 |
DateLongAgoRadio IDCallsignNameRepeaterRep IDCallGroupNetSlotAudType
>>>>>>>>>>>>>
94 |
95 |
96 |
97 | 102 | 103 | 104 | 0 ) { 112 | $duration = "$days" . "D " ; 113 | } elseif ( $hours > 0 ) $duration .= "$hours" . "H " ; 114 | if ( $mins > 0 ) $duration .= "$mins" . "M " ; 115 | if ( ( $secs > 0 ) && ( $hours < 1 ) && ( $mins < 10 ) ) $duration .= "$secs" . "S " ; 116 | $duration = trim( $duration ) ; 117 | if ( $seconds >= 365 * 24 * 60 ) { $duration = "NEVER" ; } ; 118 | if ( $duration == null ) $duration = '0' . 'S' ; 119 | if ( $seconds >= 1000000000 ) $duration = "NEVER" ; 120 | return $duration ;} 121 | ?> -------------------------------------------------------------------------------- /web/lastheard.php: -------------------------------------------------------------------------------- 1 | 20 | 21 | 22 | 23 | 44 |
45 |
46 |

Last Heard List

47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 125 |
DateLong AgoUserRepeaterDestinationSlotNetwork
>>>>>>>
126 |
127 |
128 |
129 | 133 | 134 | 135 | 0 ) { 143 | $duration = "$days" . "D " ; 144 | } elseif ( $hours > 0 ) $duration .= "$hours" . "H " ; 145 | if ( $mins > 0 ) $duration .= "$mins" . "M " ; 146 | if ( ( $secs > 0 ) && ( $hours < 1 ) && ( $mins < 10 ) ) $duration .= "$secs" . "S " ; 147 | $duration = trim( $duration ) ; 148 | if ( $seconds >= 365 * 24 * 60 ) { $duration = "NEVER" ; } ; 149 | if ( $duration == null ) $duration = '0' . 'S' ; 150 | if ( $seconds >= 1000000000 ) $duration = "NEVER" ; 151 | return $duration ;} 152 | ?> 153 | -------------------------------------------------------------------------------- /web/netstatus.css: -------------------------------------------------------------------------------- 1 | th{ padding: 5px 5px 5px 5px; border: 1px solid #BADFF6; font-size: 10px; color: #005596; font-weight: bold; text-align: left; white-space:nowrap; background-color: #ECEFF5; } 2 | td{ padding: 2px 4px 2px 4px; border: 1px solid #BADFF6; font-size: 9px; color: #505050; } 3 | body { background:#114E7B url(images/bg.jpg) no-repeat top center; color:#666666; font-family:monospace; position:relative; } 4 | a{ color:#0000FF; } 5 | img{ border:none; } 6 | #round_top{ width:900px; height:20px; background:url(images/round-top.png) no-repeat top center; margin:0 auto; } 7 | #round_bottom{ width:900px; height:20px; background:url(images/round-bottom.png) no-repeat top center; margin:0 auto; } 8 | #header { margin:30px auto 10px auto; width:900px; } 9 | #content { width:840px; margin:0 auto; background-color:#FFF; padding:0px 30px; } 10 | #content h2 { margin:0; padding:10px 5px; font-size: 30px; color:#424a55; } 11 | #maincontent h2 { border-bottom:3px solid #e3e3e3; margin-bottom:25px; } 12 | #footer { background: url(images/bg_footer.gif); padding:0; height:58px; margin:0 auto; padding:10px 40px; width:820px; } 13 | #footer p { font-size: 12px; color:#fff;} 14 | #footer a { color:#fff; text-decoration:underline;} 15 | .fixed:after{content:"."; display:block; height:0; clear:both; visibility:hidden;} 16 | .fixed{display:block;} 17 | .fixed{min-height:1%;} 18 | .logo { padding:5px 0 10px 20px; margin:0; float:left; color:#FFFFFF; } 19 | .logo a{} 20 | .nav { padding:7px 0 0 0; margin:50px 20px 0 0; float:right;} 21 | .nav ul { padding:0; margin:0; list-style:none; border:0;} 22 | .nav ul li { float:left; margin:0; padding:0 2px 0 0; border:0;} 23 | .nav ul li a { float:left; margin:0; padding:11px; color:#fff; font-size: 15px; text-decoration:none; outline:none; } 24 | .nav ul li a:hover{ text-decoration:underline; } 25 | .nav ul li a.active { text-decoration:underline; } 26 | .odd { background-color: #FFFFFF; white-space:nowrap; } 27 | .networkheader{ border: 0px ; font-size:14px; margin:0; padding:10px 5px; font-size: 16px; color:#424a55; } 28 | .even { background-color: #E6E6E6; white-space:nowrap; } 29 | .master { background-color: #ECEFF5; white-space:nowrap; } 30 | .netcol { background-color: #00EE00; white-space:nowrap; } 31 | .online { background-color: #00FF00; white-space:nowrap; text-align: center; overflow: hidden; } 32 | .offline { background-color: #FF0000; white-space:nowrap; text-align: center; } 33 | .unlinked { background-color: #00CC00; white-space:nowrap; text-align: center; } 34 | .unknown { background-color: #CCCCCC; white-space:nowrap; text-align: center; } 35 | .copyright{ float:left;} 36 | .credits{ float:right; 37 | text-align:right;} -------------------------------------------------------------------------------- /web/netstatus.json: -------------------------------------------------------------------------------- 1 | $DmrID ) { 46 | $Repeater["$NetworkID"][Description] = $Network["$Row[DmrID]"][Description]; 47 | $Query = "SELECT Repeater.DmrID AS DmrID, Role, Country, City, State, Frequency, PublishFrequency, Short, Offset, Callsign, Trustee, `Repeater`.`lat`,`Repeater`.`long`, Repeater.Publish, Override, OverrideOnline, Ts1Online, Ts2Online, OverrideTs1Online, OverrideTs2Online, Network.Description FROM `Repeater` LEFT JOIN Network ON Repeater.DmrID = Network.DmrID WHERE Repeater.Publish = '1' AND SourceNet = '$NetworkID' Group BY Repeater.DmrID ORDER BY Country, State, City" ; 48 | mysql_query( $Query ) or die( "MYSQL ERROR:" . mysql_error() ) ; 49 | $Result = mysql_query( $Query ) or die( mysql_errno . " " . mysql_error() ) ; 50 | while ( $Row = mysql_fetch_array( $Result ) ) { 51 | $Online = 0 ; 52 | $Ts1Linked = 0 ; 53 | $Ts2Linked = 0 ; 54 | $LongAgo = ( strtotime( "now" ) - strtotime( $LastHeard["$Row[DmrID]"][DateTime] ) ) ; 55 | $Ts1Online = $LastHeard["$Row[DmrID]"][Ts1Online]; 56 | $Ts2Online = $LastHeard["$Row[DmrID]"][Ts2Online]; 57 | $Frequency = (($Row[PublishFrequency] != $Row[Frequency])?$Row[PublishFrequency]:$Row[Frequency]); 58 | if ( $LongAgo > 120 ) { 59 | $Online = 0 ; 60 | $Ts1Linked = 0 ; 61 | $Ts2Linked = 0 ; 62 | if ($Row[LastHeard] == "0000-00-00 00:00:00") 63 | { 64 | $LongAgo = "NEVER"; 65 | } else { 66 | $LongAgo = duration($LongAgo); 67 | }; 68 | } else { 69 | $Online = 1 ; 70 | if ( $Row[Ts1Online] == 1 ) { 71 | $Ts1Linked = 1 ; 72 | } 73 | ; 74 | if ( $Row[Ts2Online] == 1 ) { 75 | $Ts2Linked = 1 ; 76 | }; 77 | } 78 | if ( $Row[Override] == 1 ) { 79 | if ( $Row[OverrideOnline] == 1 ) { 80 | $Online = 1 ; 81 | } else { 82 | $Online = 0 ; 83 | } 84 | if ( $Row[OverrideTs1Online] == 1 ) { 85 | $Ts1Linked = 1 ; 86 | } else { 87 | $Ts1Linked = 0 ; 88 | } 89 | if ( $Row[OverrideTs2Online] == 1 ) { 90 | $Ts2Linked = 1 ; 91 | } else { 92 | $Ts2Linked = 0 ; 93 | } 94 | } 95 | $Repeater["$NetworkID"]["$Row[DmrID]"][Role] = $Row[Role] ; 96 | $Repeater["$NetworkID"]["$Row[DmrID]"][Country] = $Row[Country] ; 97 | $Repeater["$NetworkID"]["$Row[DmrID]"][State] = $Row[State] ; 98 | $Repeater["$NetworkID"]["$Row[DmrID]"][City] = $Row[City] ; 99 | $Repeater["$NetworkID"]["$Row[DmrID]"][Short] = $Row[Short] ; 100 | $Repeater["$NetworkID"]["$Row[DmrID]"][Frequency] = $Frequency ; 101 | $Repeater["$NetworkID"]["$Row[DmrID]"][Offset] = $Row[Offset] ; 102 | $Repeater["$NetworkID"]["$Row[DmrID]"][Callsign] = $Row[Callsign] ; 103 | $Repeater["$NetworkID"]["$Row[DmrID]"][Owner] = $Row[Trustee] ; 104 | $Repeater["$NetworkID"]["$Row[DmrID]"][Lat] = $Row[lat] ; 105 | $Repeater["$NetworkID"]["$Row[DmrID]"][Long] = $Row[long] ; 106 | $Repeater["$NetworkID"]["$Row[DmrID]"][Online] = $Online ; 107 | $Repeater["$NetworkID"]["$Row[DmrID]"][LongAgo] = $LongAgo ; 108 | $Repeater["$NetworkID"]["$Row[DmrID]"][Ts1Linked] = $Ts1Linked ; 109 | $Repeater["$NetworkID"]["$Row[DmrID]"][Ts2Linked] = $Ts2Linked ; 110 | $Repeater["$NetworkID"][Description]=$Network[$NetworkID][Description]; 111 | } 112 | 113 | } 114 | echo json_encode( $Repeater ) ; 115 | function duration( $seconds ) 116 | { 117 | $days = floor( $seconds / 60 / 60 / 24 ) ; 118 | $hours = $seconds / 60 / 60 % 24 ; 119 | $mins = $seconds / 60 % 60 ; 120 | $secs = $seconds % 60 ; 121 | $duration = '' ; 122 | if ( $days > 0 ) { 123 | $duration = "$days"."D" ; 124 | } elseif ( $hours > 0 ) $duration .= "$hours" . "H" ; 125 | if ( $mins > 0 ) $duration .= "$mins" . "M" ; 126 | if ( ( $secs > 0 ) && ( $hours < 1 ) && ( $mins < 10 ) ) $duration .= "$secs" . 127 | "S" ; 128 | $duration = trim( $duration ) ; 129 | if ( $duration == null ) $duration = '0' . 'S' ; 130 | if ($seconds >= 1000000000) $duration = "NEVER"; 131 | return $duration ; 132 | } 133 | $cached = fopen($cachefile, 'w'); 134 | fwrite($cached, ob_get_contents()); 135 | fclose($cached); 136 | ob_end_flush(); 137 | ?> 138 | -------------------------------------------------------------------------------- /web/netstatus.php: -------------------------------------------------------------------------------- 1 | 20 | 21 | 22 | 23 | 40 | 41 |
42 |
43 |

Network Status

44 | $Network ){?> 54 | 55 | 56 | $Repeater){ 59 | if (is_int($RepeaterID)){ 60 | $trClass = ( $i % 2 != 0 )? "odd": "even"; 61 | $trClass = ($Repeater[Role]==1)?"master":$trClass; 62 | $Callsign = ($Repeater[Callsign] == $Repeater[Owner])?$Repeater[Callsign]:$Repeater[Callsign]." / ".$Repeater[Owner]; ?> 63 | 64 | 65 | 66 | 67 | 68 | 69 | LH: $Repeater[LongAgo]"; 72 | } else { 73 | ?> 74 | LINKED" : "";?> 75 | LINKED" : "";}?> 79 | 80 |
CountryStateLocationFrequencyOffsetCallsign / Trustee  STATUS    SLOT 1    SLOT 2  
ONLINELOCALLOCAL
81 |
83 |
84 |
85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /web/netstatus.phps: -------------------------------------------------------------------------------- 1 | $Network ){?> 28 | 29 | 30 | $Repeater){ 33 | if (is_int($RepeaterID)){ 34 | $trClass = ( $i % 2 != 0 )? "odd": "even"; 35 | $trClass = ($Repeater[Role]==1)?"master":$trClass; 36 | $Callsign = ($Repeater[Callsign] == $Repeater[Owner])?$Repeater[Callsign]:$Repeater[Callsign]." / ".$Repeater[Owner]; ?> 37 | 38 | 39 | 40 | 41 | 42 | 43 | LH: $Repeater[LongAgo]"; 46 | } else { 47 | ?> 48 | LINKED" : "";?> 49 | LINKED" : "";}?> 53 |
CountryStateLocationFrequencyOffsetCallsign / Trustee  STATUS    SLOT 1    SLOT 2  
ONLINELOCALLOCAL
--------------------------------------------------------------------------------