int main(int argc,char *argv[]) { char *mname; FILE *fp; long size,len; char *buf,*p; int i,nrecs = 0; struct profdata *pdata,*pd; if (argc >= 2) { if (*argv[1]=='-' || *argv[1]=='?') { printf("%s V%d.%d%c (c)1998 by Frank Wille\n" "Usage:\n %s [mon.out]\n",argv[0], VERSION,REVISION,PLEVEL?('a'+PLEVEL-1):' ',argv[0]); exit(1); } else mname = argv[1]; } else mname = DEFAULTNAME; if (fp = fopen(mname,"r")) { /* determine file size */ fseek(fp,0,SEEK_END); size = ftell(fp); fseek(fp,0,SEEK_SET); if (size < 0) { fclose(fp); fprintf(stderr,"%s: Seek error on %s!\n",argv[0],mname); exit(EXIT_FAILURE); } /* allocate buffer and read file */ if (!(buf = malloc(size))) { fclose(fp); fprintf(stderr,"%s: Not enough memory!\n",argv[0]); exit(EXIT_FAILURE); } if (fread(buf,1,size,fp) != size) { fclose(fp); fprintf(stderr,"%s: %s had a read error!\n",argv[0],mname); exit(EXIT_FAILURE); } fclose(fp); /* count number of entries in mon.out and allocate profdata array */ p = buf; while (p < buf+size) { nrecs++; p = skipname(p) + 2*sizeof(unsigned long); } if (p!=buf+size || nrecs==0) { fprintf(stderr,"%s: %s: Corrupted file format.\n",argv[0],mname); exit(EXIT_FAILURE); } if (!(pdata = malloc(nrecs * sizeof(struct profdata)))) { fprintf(stderr,"%s: Not enough memory!\n",argv[0]); exit(EXIT_FAILURE); } /* fill profdata array */ for (i=0,p=buf,pd=pdata; i<nrecs; i++,pd++) { pd->funcname = p; p = skipname(p); pd->ncalls = *(unsigned long *)p; pd->tottime = *(unsigned long *)(p+sizeof(unsigned long)); p += 2*sizeof(unsigned long); } /* display */ show_total(pdata,nrecs); } else { fprintf(stderr,"%s: Can't open %s.\n",argv[0],mname); exit(EXIT_FAILURE); } return 0; }
static uintptr_t * apdns_getFQDN_MX_1 (Region rAddrLPairs, Region rAddrEPairs, Region rAddrString, char *str, uintptr_t *list, int depth, request_data *rd) { if (depth < 0) return list; // i,j are used as loop counters // the dnspackage returned from the resolver is scanned from top to buttom // next is the package pointer relative to the start of the package int j, next; char ans[NS_PACKETSZ + 1]; char dnsnamesa[NS_MAXDNAME]; char *dnsnames = dnsnamesa; char *input = str; uintptr_t *pair, *listpair; String rs; dnshead *head = (dnshead *) ans; // get the dns package int n = res_search (input, C_IN, T_MX, (unsigned char *) ans, NS_PACKETSZ + 1); input = 0; if (n == -1) return list; if (n < sizeof (dnshead)) return list; ntohhead (ans, head); if ((head->flags & 0xF) != 0) return list; if (head->anscount < 1) return list; // skip questions next = NS_HFIXEDSZ; for (j = 0; j < head->questcount; j++) { next = skipname (ans, next, n); next = iflessthan (next + 4, n); if (next < 0) return list; } // The answers int rv; for (j = 0; j < head->anscount; j++) { // int a_name = next; if (next >= n) return list; next = skipname (ans, next, n); if (next + NS_RRFIXEDSZ >= n || next < 0) return list; uint16_t a_type = twocharto16 (ans[next], ans[next + 1]); next += 4; uint32_t a_ttl = fourcharto32 (ans[next], ans[next + 1], ans[next + 2], ans[next + 3]); next += 4; uint16_t a_rdlength = twocharto16 (ans[next], ans[next + 1]); next += 2; if (a_type == T_MX) { // We got a mx record if (next + a_rdlength >= n || a_rdlength < 3) return list; uint16_t a_mx_pref = twocharto16 (ans[next], ans[next + 1]); rv = dumpname (dnsnames, NS_MAXDNAME, ans, next + 2, n); rs = convertStringToML (rAddrString, dnsnames); allocRecordML (rAddrEPairs, 3, pair); elemRecordML (pair, 0) = (uintptr_t) a_mx_pref; elemRecordML (pair, 1) = (uintptr_t) a_ttl; elemRecordML (pair, 2) = (uintptr_t) rs; allocRecordML (rAddrLPairs, 2, listpair); first (listpair) = (uintptr_t) pair; second (listpair) = (uintptr_t) list; makeCONS (listpair, list); ap_log_error (APLOG_MARK, LOG_DEBUG, 0, rd->server, "apdns_getFQDN_MX: pref %i, ttl %i, %s", a_mx_pref, a_ttl, dnsnames); } else if (a_type == T_CNAME) { // we got an alias (cononical name) rv = dumpname (dnsnames, NS_MAXDNAME, ans, next, n); input = dnsnames; break; } else { // we got something we did not ask for // or cannot handle at the momnet return list; } next += a_rdlength; } if (input) return apdns_getFQDN_MX_1 (rAddrLPairs, rAddrEPairs, rAddrString, input, list, depth - 1, rd); return list; }