/* * search for a tuple that has the given 'attr=val' and also 'rattr=x'. * copy 'x' into 'buf' and return the whole tuple. * * return 0 if not found. */ Ndbtuple* dnsquery(char *net, char *val, char *type) { char rip[128]; char *p; Ndbtuple *t; int fd; /* if the address is V4 or V6 null address, give up early */ if(strcmp(val, "::") == 0 || strcmp(val, "0.0.0.0") == 0) return nil; if(net == nil) net = "/net"; snprint(rip, sizeof(rip), "%s/dns", net); fd = open(rip, ORDWR); if(fd < 0) { if(strcmp(net, "/net") == 0) snprint(rip, sizeof(rip), "/srv/dns"); else { snprint(rip, sizeof(rip), "/srv/dns%s", net); p = strrchr(rip, '/'); *p = '_'; } fd = open(rip, ORDWR); if(fd < 0) return nil; if(mount(fd, -1, net, MBEFORE, "") < 0) { close(fd); return nil; } /* fd is now closed */ snprint(rip, sizeof(rip), "%s/dns", net); fd = open(rip, ORDWR); if(fd < 0) return nil; } /* zero out the error string */ werrstr(""); /* if this is a reverse lookup, first lookup the domain name */ if(strcmp(type, "ptr") == 0) { mkptrname(val, rip, sizeof rip); t = doquery(fd, rip, "ptr"); } else t = doquery(fd, val, type); /* * TODO: make fd static and keep it open to reduce 9P traffic * walking to /net*^/dns. */ close(fd); ndbsetmalloctag(t, getcallerpc(&net)); return t; }
static int procfs_read_stats(char *page, char **start, off_t off, int count, int *eof, void *data) { char *p = page; struct ndis_handle *handle = (struct ndis_handle *) data; struct ndis_wireless_stats stats; unsigned int res, written, needed; long rssi; if (off != 0) { *eof = 1; return 0; } res = doquery(handle, NDIS_OID_RSSI, (char*)&rssi, sizeof(rssi), &written, &needed); if (!res) p += sprintf(p, "signal_level=%ld dBm\n", rssi); res = doquery(handle, NDIS_OID_STATISTICS, (char*)&stats, sizeof(stats), &written, &needed); if (!res) { p += sprintf(p, "tx_frames=%Lu\n", stats.tx_frag); p += sprintf(p, "tx_multicast_frames=%Lu\n", stats.tx_multi_frag); p += sprintf(p, "tx_failed=%Lu\n", stats.failed); p += sprintf(p, "tx_retry=%Lu\n", stats.retry); p += sprintf(p, "tx_multi_rerty=%Lu\n", stats.multi_retry); p += sprintf(p, "tx_rtss_success=%Lu\n", stats.rtss_succ); p += sprintf(p, "tx_rtss_fail=%Lu\n", stats.rtss_fail); p += sprintf(p, "ack_fail=%Lu\n", stats.ack_fail); p += sprintf(p, "frame_duplicates=%Lu\n", stats.frame_dup); p += sprintf(p, "rx_frames=%Lu\n", stats.rx_frag); p += sprintf(p, "rx_multicast_frames=%Lu\n", stats.rx_multi_frag); p += sprintf(p, "fcs_errors=%Lu\n", stats.fcs_err); } if (p - page > count) { ERROR("wrote %u bytes (limit is %u)\n", p - page, count); *eof = 1; } return (p - page); }
int ntpq_read_assoc_peervars( associd_t associd, char * resultbuf, int maxsize ) { const char * datap; int res; size_t dsize; u_short rstatus; res = doquery(CTL_OP_READVAR, associd, 0, 0, NULL, &rstatus, &dsize, &datap); if (res != 0) return 0; if (dsize <= 0) { if (numhosts > 1) fprintf(stderr, "server=%s ", currenthost); fprintf(stderr, "***No information returned for association %d\n", associd); return 0; } if (dsize > maxsize) dsize = maxsize; memcpy(resultbuf, datap, dsize); return dsize; }
int NetGuard_Command_Input_WH8::getportcount(char *ip){ const char *query = "ifNumber.0"; char *tmpresult; int count; #ifdef debug printf("entering get port count part\n"); #endif #ifdef debug printf("query: %s\n",query); #endif tmpresult = doquery(ip,(char*)query); if (tmpresult) { count = atoi(tmpresult); free(tmpresult); #ifdef debug printf("port count found: %d\n",count); #endif if(count > 48) return 48; else if(count > 24) return 24; else return count; } else { free((char*)query); printf("Error cant get port count\n"); return -1; } }
/***************************************************************************** * * ntpq_read_sysvars * * This function reads the sysvars variable-set from a NTP host and writes it * to the result buffer specified, honoring the maxsize limit. * * It returns the number of bytes written or 0 when the variable-set is empty * or could not be read. * **************************************************************************** * Parameters: * resultbuf char* character buffer where the variable set * should be stored * maxsize int the maximum number of bytes that can be * written to resultbuf * * Returns: * int number of chars that have been copied to * resultbuf * - OR - * 0 (zero) if an error occured ****************************************************************************/ size_t ntpq_read_sysvars( char * resultbuf, size_t maxsize) { const char * datap; int res; int i_dsize; size_t dsize; u_short rstatus; res = doquery(CTL_OP_READVAR, 0, 0, 0, NULL, &rstatus, &i_dsize, &datap); if (res != 0) return 0; if (i_dsize == 0) { if (numhosts > 1) fprintf(stderr, "server=%s ", currenthost); fprintf(stderr, "***No sysvar information returned\n"); return 0; } else { dsize = max(0, i_dsize); dsize = min(dsize, maxsize); memcpy(resultbuf, datap, dsize); } return dsize; }
int main(int argc, char **argv) { int c, flags = 0; const char *query = 0; Pool *pool = pool_create(); Repo *repo = repo_create(pool, "<stdin>"); while ((c = getopt (argc, argv, "hq:")) >= 0) { switch(c) { case 'h': usage(0); break; case 'q': query = optarg; break; default: usage(1); break; } } repo_add_repomdxml(repo, stdin, flags); if (query) doquery(pool, repo, query); else tool_write(repo, 0, 0); pool_free(pool); exit(0); }
/*ARGSUSED*/ static void radiostatus( struct parse *pcmd, FILE *fp ) { char *datap; int res; int dsize; u_short rstatus; res = doquery(CTL_OP_READCLOCK, 0, 0, 0, (char *)0, &rstatus, &dsize, &datap); if (res != 0) return; if (numhosts > 1) (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) { (void) fprintf(fp, "No radio status string returned\n"); return; } asciize(dsize, datap, fp); }
/* * saveconfig - dump ntp server configuration to server file */ static void saveconfig( struct parse *pcmd, FILE *fp ) { const char *datap; int res; int dsize; u_short rstatus; if (0 == pcmd->nargs) return; res = doquery(CTL_OP_SAVECONFIG, 0, 1, strlen(pcmd->argval[0].string), pcmd->argval[0].string, &rstatus, &dsize, &datap); if (res != 0) return; if (0 == dsize) fprintf(fp, "(no response message, curiously)"); else fprintf(fp, "%.*s", dsize, datap); }
int NetGuard_Command_Input_WH8::getadminstatus(u_int32_t ip, int port) { const char *getstatus = "interfaces.2.1.7.%d"; char *query, *tmpresult; int count; #ifdef debug printf("entering get admin status\n"); #endif query = (char*)calloc(strlen(getstatus)+10,sizeof(char)); sprintf(query,getstatus,port); #ifdef debug printf("query: %s\n",query); #endif char *myip = inet_ntoa(*(struct in_addr *)&ip); tmpresult = doquery(myip,query); //delete myip; if (tmpresult) { count = atoi(tmpresult); switch (count) { case 1: return 1; default: return 0; }; } else { free(query); printf("Error cant get admin status\n"); return 0; } }
/* * pstatus - print peer status returned by the server */ static void pstatus( struct parse *pcmd, FILE *fp ) { const char *datap; int res; associd_t associd; int dsize; u_short rstatus; /* HMS: uval? */ if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) return; res = doquery(CTL_OP_READSTAT, associd, 0, 0, NULL, &rstatus, &dsize, &datap); if (res != 0) return; if (numhosts > 1) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) { fprintf(fp, "No information returned for association %u\n", associd); return; } fprintf(fp, "associd=%u ", associd); printvars(dsize, datap, (int)rstatus, TYPE_PEER, 0, fp); }
int NetGuard_Command_Input_WH8::getmacslearned(u_int32_t ip, int port){ const char *macsl = "enterprises.9.9.315.1.2.1.1.4.%i"; char *query, *tmpresult; int count; #ifdef debug printf("entering get getmacslearned\n"); #endif query = (char*)calloc(strlen(macsl)+10,sizeof(char)); sprintf(query,macsl,port); #ifdef debug printf("query: %s\n",query); #endif char *myip = inet_ntoa(*(struct in_addr *)&ip); tmpresult = doquery(myip,query); //delete myip; if (tmpresult) { count = atoi(tmpresult); free(tmpresult); #ifdef debug printf("getmacslearned count found: %d\n",count); #endif return count; } else { free(query); printf("Error cant get getmacslearned count\n"); return -1; } }
char *NetGuard_Command_Input_WH8::doportquery(char *ip,char *oid, int port) { char *query; char *tmpresult; query = (char*)calloc(strlen(oid)+10,sizeof(char)); sprintf(query,oid,port); tmpresult = doquery(ip,query); free(query); return tmpresult; }
/* * config - send a configuration command to a remote host */ static void config ( struct parse *pcmd, FILE *fp ) { char *cfgcmd; u_short rstatus; int rsize; const char *rdata; char *resp; int res; int col; int i; cfgcmd = pcmd->argval[0].string; if (debug > 2) fprintf(stderr, "In Config\n" "Keyword = %s\n" "Command = %s\n", pcmd->keyword, cfgcmd); res = doquery(CTL_OP_CONFIGURE, 0, 1, strlen(cfgcmd), cfgcmd, &rstatus, &rsize, &rdata); if (res != 0) return; if (rsize > 0 && '\n' == rdata[rsize - 1]) rsize--; resp = emalloc(rsize + 1); memcpy(resp, rdata, rsize); resp[rsize] = '\0'; col = -1; if (1 == sscanf(resp, "column %d syntax error", &col) && col >= 0 && (size_t)col <= strlen(cfgcmd) + 1) { if (interactive) { printf("______"); /* "ntpq> " */ printf("________"); /* ":config " */ } else printf("%s\n", cfgcmd); for (i = 1; i < col; i++) putchar('_'); printf("^\n"); } printf("%s\n", resp); free(resp); }
int ntpq_read_assoc_peervars( associd_t associd, char *resultbuf, int maxsize ) { const char *datap; int res; int dsize; u_short rstatus; l_fp rec; l_fp ts; char value[NTPQ_BUFLEN]; res = doquery(CTL_OP_READVAR, associd, 0, 0, NULL, &rstatus, &dsize, &datap); if (res != 0) return 0; get_systime(&ts); if (dsize == 0) { if (numhosts > 1) fprintf(stderr, "server=%s ", currenthost); fprintf(stderr, "***No information returned for association %d\n", associd); return 0; } else { if ( dsize > maxsize ) dsize = maxsize; memcpy(resultbuf, datap, dsize); resultbuf[dsize] = '\0'; ntpq_getvar(resultbuf, dsize, "rec", value, sizeof(value)); if (!decodets(value, &rec)) L_CLR(&rec); memcpy(resultbuf, value, maxsize); resultbuf[dsize] = '\0'; dsize = strlen(resultbuf); } return dsize; }
/* * dogetassoc - query the host for its list of associations */ static int dogetassoc( FILE *fp ) { const char *datap; int res; int dsize; u_short rstatus; res = doquery(CTL_OP_READSTAT, 0, 0, 0, (char *)0, &rstatus, &dsize, &datap); if (res != 0) return 0; if (dsize == 0) { if (numhosts > 1) (void) fprintf(fp, "server=%s ", currenthost); (void) fprintf(fp, "No association ID's returned\n"); return 0; } if (dsize & 0x3) { if (numhosts > 1) (void) fprintf(stderr, "server=%s ", currenthost); (void) fprintf(stderr, "***Server returned %d octets, should be multiple of 4\n", dsize); return 0; } numassoc = 0; while (dsize > 0) { assoc_cache[numassoc].assid = ntohs(*((const u_short *)datap)); datap += sizeof(u_short); assoc_cache[numassoc].status = ntohs(*((const u_short *)datap)); datap += sizeof(u_short); if (++numassoc >= MAXASSOC) break; dsize -= sizeof(u_short) + sizeof(u_short); } sortassoc(); return 1; }
int NetGuard_Command_Input_WH8::getportnumber(char *ip, int port){ const char *query = "ifIndex.2"; char *tmpresult; #ifdef debug printf("entering get port count part\n"); #endif #ifdef debug printf("query: %s\n",query); #endif tmpresult = doquery(ip,(char*)query); if (tmpresult) { return port; }else{ return (10100+port); } }
/* * doquerylist - send a message including variables in a list */ static int doquerylist( struct varlist *vlist, int op, associd_t associd, int auth, u_short *rstatus, int *dsize, const char **datap ) { char data[CTL_MAX_DATA_LEN]; int datalen; datalen = sizeof(data); makequerydata(vlist, &datalen, data); return doquery(op, associd, auth, datalen, data, rstatus, dsize, datap); }
/* * dogetpeers - given an association ID, read and print the spreadsheet * peer variables. */ static int dogetpeers( struct varlist *pvl, associd_t associd, FILE *fp, int af ) { const char *datap; int res; int dsize; u_short rstatus; #ifdef notdef res = doquerylist(pvl, CTL_OP_READVAR, associd, 0, &rstatus, &dsize, &datap); #else /* * Damn fuzzballs */ res = doquery(CTL_OP_READVAR, associd, 0, 0, NULL, &rstatus, &dsize, &datap); #endif if (res != 0) return 0; if (dsize == 0) { if (numhosts > 1) fprintf(stderr, "server=%s ", currenthost); fprintf(stderr, "***No information returned for association %u\n", associd); return 0; } return doprintpeers(pvl, associd, (int)rstatus, dsize, datap, fp, af); }
int ntpq_queryhost(unsigned short VARSET, unsigned short association, char *resultbuf, int maxlen) { const char *datap; int res; int dsize; u_short rstatus; if ( numhosts > 0 ) res = doquery(VARSET,association,0,0, (char *)0, &rstatus, &dsize, &datap); else return 0; if ( ( res != 0) || ( dsize == 0 ) ) /* no data */ return 0; if ( dsize > maxlen) dsize = maxlen; /* fill result resultbuf */ memcpy(resultbuf, datap, dsize); return dsize; }
int main(int argc,char **argv) { /* read query from stdin, expect name of indexes in argv[1] */ static FILE *fa, *fb, *fc; char nma[PATH_MAX], nmb[PATH_MAX], nmc[PATH_MAX], *qitem[100], *rprog = NULL; char nmd[PATH_MAX], grepquery[256]; static char oldname[30] ; static int was =0; /* these pointers are unions of pointer to int and pointer to long */ long *hpt = 0; unsigned *master =0; int falseflg, nhash, nitem, nfound = 0, frtbl, kk; /* special wart for refpart: default is tags only */ falseflg = 0; while (argc > 1 && argv[1][0] == '-') { switch(argv[1][1]) { case 'a': /* all output, incl. false drops */ falseflg = 1; break; case 'r': argc--; argv++; rprog = argv[1]; break; case 'F': /* put out full text */ full = setfrom(argv[1][2]); break; case 'T': /* put out tags */ tags = setfrom(argv[1][2]); break; case 'i': /* input in argument string */ argc--; argv++; sinput = argv[1]; break; case 's': /*text output to string */ case 'o': argc--; argv++; soutput = argv[1]; if ((intptr_t) argv[2]<16000) { soutlen = (intptr_t)argv[2]; argc--; argv++; } break; case 't': /*tag output to string */ argc--; argv++; tagout = argv[1]; break; case 'l': /* length of internal lists */ argc--; argv++; lmaster = atoi(argv[1]); break; case 'g': /* suppress fgrep search on old files */ keepold = 0; break; case 'C': /* coordination level */ colevel = atoi(argv[1]+2); # if D1 fprintf(stderr, "colevel set to %d\n",colevel); # endif break; case 'P': /* print term freqs */ prfreqs=1; break; case 'm': measure=1; break; } argc--; argv++; } if(argc < 2) exit(1); strcpy (nma, todir(argv[1])); if (was == 0 || strcmp (oldname, nma) !=0) { strcpy (oldname,nma); strcpy (nmb, nma); strcpy (nmc, nmb); strcpy(nmd,nma); strcat (nma, ".ia"); strcat (nmb, ".ib"); strcat (nmc, ".ic"); strcat (nmd, ".id"); if (was) { fclose(fa); fclose(fb); fclose(fc); } fa = fopen(nma, "r"); if (fa==NULL) { strcpy(*fgnamp++ = calloc(strlen(oldname)+2,1), oldname); fb=NULL; goto search; } fb = fopen(nmb, "r"); fc = fopen(nmc, "r"); was =1; if (fb== NULL || fc ==NULL) { err("Index incomplete %s", nmb); exit(1); } indexdate = gdate(fb); fd = fopen(nmd, "r"); } fseek (fa, 0, SEEK_SET); fread (&nhash, sizeof(nhash), 1, fa); fread (&iflong, sizeof(iflong), 1, fa); if(master==0) master = calloc (lmaster, iflong? sizeof(long): sizeof(unsigned)); hpt = calloc(nhash, sizeof(*hpt)); kk=fread( hpt, sizeof(*hpt), nhash, fa); # if D1 fprintf(stderr,"read %d hashes, iflong %d, nhash %d\n", kk, iflong, nhash); # endif assert (kk==nhash); hfreq = calloc(nhash, sizeof(*hfreq)); assert (hfreq != NULL); frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); hfrflg = (frtbl == nhash); # if D1 fprintf(stderr, "read freqs %d\n", frtbl); # endif search: while (1) { nitem = getq(qitem); if (measure) tick(); if (nitem==0) continue; if (nitem < 0) break; if (tagout) tagout[0]=0; if (fb!=NULL) { nfound = doquery(hpt, nhash, fb, nitem, qitem, master); # if D1 fprintf(stderr,"after doquery nfound %d\n", nfound); # endif fgnamp=fgnames; if (falseflg == 0) nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full); # if D1 fprintf(stderr,"after baddrop nfound %d\n", nfound); # endif } if (fgnamp>fgnames) { char **fgp, tgbuff[100]; int k; # if D1 fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); # endif memset(tgbuff, 0, sizeof (tgbuff)); grepquery[0]=0; for(k=0; k<nitem; k++) { strcat(grepquery, " "); strcat(grepquery, qitem[k]); } # if D1 fprintf(stderr, "grepquery %s\n",grepquery); # endif for(fgp=fgnames; fgp<fgnamp; fgp++) { # if D1 fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery); # endif makefgrep(*fgp); # if D1 fprintf(stderr, "grepmade\n"); # endif if (tagout==0) tagout=tgbuff; grepcall(grepquery, tagout, *fgp); # if D1 fprintf(stderr, "tagout now /%s/\n", tagout); # endif if (full) { int nout; char *bout; char *tagp; char *oldtagp; tagp = tagout; while (*tagp) { oldtagp = tagp; while (*tagp && (*tagp != '\n')) tagp++; if (*tagp) tagp++; nout = findline(oldtagp, &bout, 1000, 0L); if (nout > 0) { fputs(bout, stdout); free(bout); } } } } } if (tags) result (master, nfound >tags ? tags: nfound, fc); if (measure) tock(); } /* NOTREACHED */ return 0; }
/* * config_from_file - remotely configure an ntpd daemon using the * specified configuration file * SK: This function is a kludge at best and is full of bad design * bugs: * 1. ntpq uses UDP, which means that there is no guarantee of in-order, * error-free delivery. * 2. The maximum length of a packet is constrained, and as a result, the * maximum length of a line in a configuration file is constrained. * Longer lines will lead to unpredictable results. * 3. Since this function is sending a line at a time, we can't update * the control key through the configuration file (YUCK!!) */ static void config_from_file ( struct parse *pcmd, FILE *fp ) { u_short rstatus; int rsize; const char *rdata; int res; FILE *config_fd; char config_cmd[MAXLINE]; size_t config_len; int i; int retry_limit; if (debug > 2) fprintf(stderr, "In Config\n" "Keyword = %s\n" "Filename = %s\n", pcmd->keyword, pcmd->argval[0].string); config_fd = fopen(pcmd->argval[0].string, "r"); if (NULL == config_fd) { printf("ERROR!! Couldn't open file: %s\n", pcmd->argval[0].string); return; } printf("Sending configuration file, one line at a time.\n"); i = 0; while (fgets(config_cmd, MAXLINE, config_fd) != NULL) { config_len = strlen(config_cmd); /* ensure even the last line has newline, if possible */ if (config_len > 0 && config_len + 2 < sizeof(config_cmd) && '\n' != config_cmd[config_len - 1]) config_cmd[config_len++] = '\n'; ++i; retry_limit = 2; do res = doquery(CTL_OP_CONFIGURE, 0, 1, strlen(config_cmd), config_cmd, &rstatus, &rsize, &rdata); while (res != 0 && retry_limit--); if (res != 0) { printf("Line No: %d query failed: %s", i, config_cmd); printf("Subsequent lines not sent.\n"); fclose(config_fd); return; } if (rsize > 0 && '\n' == rdata[rsize - 1]) rsize--; if (rsize > 0 && '\r' == rdata[rsize - 1]) rsize--; printf("Line No: %d %.*s: %s", i, rsize, rdata, config_cmd); } printf("Done sending file\n"); fclose(config_fd); }
bool NetGuard_Command_Input_WH8::find_mac(mac_addr mac,u_int32_t *ip, int *port, string *name) { int x,y,z,i,count = 0; char *tmp; const char* namequery = "enterprises.9.2.2.1.1.28.%d"; const char *macquery = "iso.3.6.1.4.1.9.9.315.1.2.2.1.4.%d"; char *query, *myresult,*tmpresult; unsigned char *mymac, *hwa; char *results[MAXDUMPQUERRYLENGTH]; int found = FALSE; mymac = getmacfrommac_addr(mac); #ifdef debug printf("entering search mac part\n"); printf("need to find Mac Address at \t %02x:%02x:%02x:%02x:%02x:%02x\n", mymac[0],mymac[1],mymac[2],mymac[3],mymac[4],mymac[5]); #endif query = (char*)calloc(MAXDUMPQUERRYLENGTH,sizeof(char)); myresult = (char*)calloc(MAXDUMPQUERRYLENGTH,sizeof(char)); i = 0; while ( switches[i] != NULL && !found) { tmp = (char*)switches[i]; count = getportcount(tmp); for (z=1;z<=count;z++){ x = getportnumber(tmp,z); query = (char*)calloc(MAXDUMPQUERRYLENGTH,sizeof(char)); sprintf(query,macquery,x); dowalkquery(tmp,query,results); y = 0; myresult = results[y]; while (myresult != NULL){ hwa = getmacfromoid(myresult); if (hwa != NULL) { #ifdef debug printf("Mac Address at \t%s \t%i \t %02x:%02x:%02x:%02x:%02x:%02x\n", tmp, x, hwa[0],hwa[1],hwa[2],hwa[3],hwa[4],hwa[5]); #endif if (hwa[5] == mymac[5] && hwa[4] == mymac[4] && hwa[3] == mymac[3] && hwa[2] == mymac[2] && hwa[1] == mymac[1] && hwa[0] == mymac[0]) { found = 1; struct in_addr m_ip; inet_aton(switches[i],&m_ip); *ip = m_ip.s_addr; *port = x; free(query); query = (char*)calloc(MAXDUMPQUERRYLENGTH,sizeof(char)); sprintf(query,namequery,x); tmpresult = doquery(tmp,query); #ifdef debug printf("Switch: %s (%s) Port: %d\n",tmpresult,*ip,*port); #endif *name = strdup(tmpresult); free(tmpresult); } free(hwa); } free(myresult); y++; myresult = results[y]; } free(query); if (found) break; } i++; } free(mymac); return found; }
WINAPI rgethostbyname(char *name) { struct hostent* host; DNS_STATUS status; const char *cp; char queryname[DNS_MAX_NAME_BUFFER_LENGTH ]; #ifdef DEBUG char debstr[80]; #endif char** domain; struct in_addr host_addr; host = (struct hostent*)(TlsGetValue(dwGhnIndex)); if (host == NULL) { LPVOID lpvData = (LPVOID) LocalAlloc(LPTR, sizeof(struct hostent)); if (lpvData != NULL) { TlsSetValue(dwGhnIndex, lpvData); host = (struct hostent*)lpvData; } else return NULL; } if (host->h_name == NULL) host->h_name = LocalAlloc(LPTR, DNS_MAX_LABEL_BUFFER_LENGTH); if (host->h_aliases == NULL) host->h_aliases = LocalAlloc(LPTR, 1*sizeof(LPSTR)); if (host->h_addr_list == NULL) { host->h_addr_list = LocalAlloc(LPTR, 2*sizeof(LPSTR)); host->h_addr_list[0] = LocalAlloc(LPTR, DNS_MAX_LABEL_BUFFER_LENGTH); } /* * disallow names consisting only of digits/dots, unless * they end in a dot. */ if (isdigit(name[0])) { for (cp = name;; ++cp) { if (!*cp) { if (*--cp == '.') break; /* * All-numeric, no dot at the end. * Fake up a hostent as if we'd actually * done a lookup. */ if (!inet_aton(name, &host_addr)) { return((struct hostent *) NULL); } strcpy(host->h_name, name); host->h_aliases[0] = NULL; host->h_addrtype = AF_INET; host->h_length = sizeof(u_long); memcpy(host->h_addr_list[0], &host_addr, sizeof(host_addr)); host->h_addr_list[1] = NULL; return (host); } if (!isdigit(*cp) && *cp != '.') break; } } strcpy(queryname, name); if ((_res.options & RES_INIT) == 0 && res_init() == -1) return NULL; if (strchr(name, '.') == NULL) { if (_res.options & RES_DEFNAMES) { for (domain = _res.dnsrch; *domain; domain++) { strcpy(queryname, name); strcat(queryname, "."); strcat(queryname, *domain); status = doquery(queryname, host); if (status == 0) break; } } } else { status = doquery(queryname, host); } if (status) { #ifdef DEBUG if (_res.options & RES_DEBUG) { wsprintf(debstr, "res_query failed\n"); OutputDebugString(debstr); } #endif return NULL; } return host; }
static int dostats(int i) { int ret = 0; do { g_indname = g_indnames[i]; g_ind = g_indlist[i]; g_is->reset_index(); CHK2(g_is->set_index(*g_ind, *g_tab) == 0, g_is->getNdbError()); if (_delete) { g_info << g_indname << ": delete stats" << endl; if (ndb_rand() % 2 == 0) { CHK2(g_dic->deleteIndexStat(*g_ind, *g_tab) == 0, g_dic->getNdbError()); } else { CHK2(g_is->delete_stat(g_ndb_sys) == 0, g_is->getNdbError()); } } if (_update) { g_info << g_indname << ": update stats" << endl; if (ndb_rand() % 2 == 0) { CHK2(g_dic->updateIndexStat(*g_ind, *g_tab) == 0, g_dic->getNdbError()); } else { CHK2(g_is->update_stat(g_ndb_sys) == 0, g_is->getNdbError()); } } NdbIndexStat::Head head; g_is->read_head(g_ndb_sys); g_is->get_head(head); CHK2(head.m_found != -1, g_is->getNdbError()); if (head.m_found == false) { g_info << "no stats" << endl; break; } show_head(head); g_info << "read stats" << endl; CHK2(g_is->read_stat(g_ndb_sys) == 0, g_is->getNdbError()); g_is->move_cache(); g_is->clean_cache(); g_info << "query cache created" << endl; NdbIndexStat::CacheInfo infoQuery; g_is->get_cache_info(infoQuery, NdbIndexStat::CacheQuery); show_cache_info("query cache", infoQuery); if (_dump) { NdbIndexStatImpl& impl = g_is->getImpl(); NdbIndexStatImpl::CacheIter iter(impl); CHK2(impl.dump_cache_start(iter) == 0, g_is->getNdbError()); while (impl.dump_cache_next(iter) == true) { show_cache_entry(iter); } } if (_query > 0) { CHK2(doquery() == 0, "failed"); } } while (0); return ret; }
static int procfs_read_hw(char *page, char **start, off_t off, int count, int *eof, void *data) { char *p = page; struct ndis_handle *handle = (struct ndis_handle *)data; struct ndis_configuration config; unsigned int res, written, needed, power_mode; unsigned long tx_power, bit_rate, rts_threshold, frag_threshold; unsigned long antenna; if (off != 0) { *eof = 1; return 0; } res = doquery(handle, NDIS_OID_CONFIGURATION, (char*)&config, sizeof(config), &written, &needed); if (!res) { p += sprintf(p, "beacon_period=%u msec\n", config.beacon_period); p += sprintf(p, "atim_window=%u msec\n", config.atim_window); p += sprintf(p, "frequency=%u kHZ\n", config.ds_config); p += sprintf(p, "hop_pattern=%u\n", config.fh_config.hop_pattern); p += sprintf(p, "hop_set=%u\n", config.fh_config.hop_set); p += sprintf(p, "dwell_time=%u msec\n", config.fh_config.dwell_time); } res = doquery(handle, NDIS_OID_TX_POWER_LEVEL, (char*)&tx_power, sizeof(tx_power), &written, &needed); if (!res) p += sprintf(p, "tx_power=%lu mW\n", tx_power); res = doquery(handle, NDIS_OID_GEN_SPEED, (char*)&bit_rate, sizeof(bit_rate), &written, &needed); if (!res) p += sprintf(p, "bit_rate=%lu kBps\n", bit_rate / 10); res = doquery(handle, NDIS_OID_RTS_THRESH, (char*)&rts_threshold, sizeof(rts_threshold), &written, &needed); if (!res) p += sprintf(p, "rts_threshold=%lu bytes\n", rts_threshold); res = doquery(handle, NDIS_OID_FRAG_THRESH, (char*)&frag_threshold, sizeof(frag_threshold), &written, &needed); if (!res) p += sprintf(p, "frag_threshold=%lu bytes\n", frag_threshold); res = query_int(handle, NDIS_OID_POWER_MODE, &power_mode); if (!res) p += sprintf(p, "power_mode=%s\n", (power_mode == NDIS_POWER_OFF) ? "always_on" : (power_mode == NDIS_POWER_MAX) ? "max_savings" : "min_savings"); res = doquery(handle, NDIS_OID_NUM_ANTENNA, (char *)&antenna, sizeof(antenna), &written, &needed); if (!res) p += sprintf(p, "num_antennas=%lu\n", antenna); res = doquery(handle, NDIS_OID_TX_ANTENNA, (char *)&antenna, sizeof(antenna), &written, &needed); if (!res) p += sprintf(p, "tx_antenna=%lu\n", antenna); res = doquery(handle, NDIS_OID_RX_ANTENNA, (char *)&antenna, sizeof(antenna), &written, &needed); if (!res) p += sprintf(p, "rx_antenna=%lu\n", antenna); if (p - page > count) { WARNING("wrote %u bytes (limit is %u)", p - page, count); *eof = 1; } return (p - page); }
static int procfs_read_encr(char *page, char **start, off_t off, int count, int *eof, void *data) { char *p = page; struct ndis_handle *handle = (struct ndis_handle *) data; int i, encr_status, auth_mode, op_mode; unsigned int res, written, needed; struct ndis_essid essid; mac_address ap_address; if (off != 0) { *eof = 1; return 0; } res = doquery(handle, NDIS_OID_BSSID, (char*)&ap_address, sizeof(ap_address), &written, &needed); if (res) memset(ap_address, 0, ETH_ALEN); p += sprintf(p, "ap_address=%2.2X", ap_address[0]); for (i = 1 ; i < ETH_ALEN ; i++) p += sprintf(p, ":%2.2X", ap_address[i]); p += sprintf(p, "\n"); res = doquery(handle, NDIS_OID_ESSID, (char*)&essid, sizeof(essid), &written, &needed); if (!res) { essid.essid[essid.length] = '\0'; p += sprintf(p, "essid=%s\n", essid.essid); } res = query_int(handle, NDIS_OID_ENCR_STATUS, &encr_status); res |= query_int(handle, NDIS_OID_AUTH_MODE, &auth_mode); if (!res) { int active = handle->encr_info.active; p += sprintf(p, "tx_key=%u\n", handle->encr_info.active); p += sprintf(p, "key="); if (handle->encr_info.keys[active].length > 0) for (i = 0; i < NDIS_ENCODING_TOKEN_MAX && i < handle->encr_info.keys[active].length; i++) p += sprintf(p, "%2.2X", handle->encr_info.keys[active].key[i]); else p += sprintf(p, "off"); p += sprintf(p, "\n"); p += sprintf(p, "status=%sabled\n", (encr_status == ENCR_DISABLED) ? "dis" : "en"); p += sprintf(p, "auth_mode=%s\n", (auth_mode == AUTHMODE_RESTRICTED) ? "restricted" : "open"); } res = query_int(handle, NDIS_OID_MODE, &op_mode); p += sprintf(p, "mode=%s\n", (op_mode == NDIS_MODE_ADHOC) ? "adhoc" : (op_mode == NDIS_MODE_INFRA) ? "managed" : "auto"); if (p - page > count) { WARNING("wrote %u bytes (limit is %u)", p - page, count); *eof = 1; } return (p - page); }
void huntmain(int argc,char **argv) { /* read query from stdin, expect name of indexes in argv[1] */ static FILE *fa, *fb, *fc; char indexname[PATH_MAX], *qitem[100], *rprog = 0; char grepquery[200]; static char oldname[30] ; static int nhash = 0; static int maxhash = 0; int falseflg = 0, nitem, nfound, frtbl; static long *hpt = 0; unsigned *masterp; # if D1 fprintf(stderr, "in glue1 argc %d argv %o %o\n", argc, argv[0],argv[1]); # endif savedir(); while (argv[1][0] == '-') { # if D1 fprintf(stderr, "argv.1 is %s\n",argv[1]); # endif switch(argv[1][1]) { case 'a': /* all output, incl. false drops */ falseflg = 1; break; case 'r': argc--; argv++; rprog = argv[1]; break; case 'F': /* put out full text */ full = setfrom(argv[1][2]); break; case 'T': /* put out tags */ tags = setfrom(argv[1][2]); break; case 'i': /* input in argument string */ argc--; argv++; sinput = argv[1]; break; case 's': /*text output to string */ case 'o': argc--; argv++; soutput = argv[1]; if ((intptr_t) argv[2]<16000) { soutlen = (intptr_t) argv[2]; argc--; argv++; } break; case 't': /*tag output to string */ argc--; argv++; tagout = argv[1]; if ((intptr_t)argv[2]<16000) { taglen = (intptr_t)argv[2]; argc--; argv++; } break; case 'l': /* specify length of lists */ argc--; argv++; lmaster = atoi(argv[1]); # if D1 fprintf(stderr, "lmaster now %d\n",lmaster); # endif break; case 'C': argc--; argv++; colevel = atoi(argv[1]); break; } argc--; argv++; } n_strcpy (indexname, todir(argv[1]), sizeof(indexname)); # if D1 fprintf(stderr, "in huntmain indexname %s typeindex %d\n", indexname, typeindex); # endif if (typeindex == 0 || strcmp (oldname, indexname) !=0) { n_strcpy (oldname, indexname, sizeof(oldname)); unopen(fa); unopen(fb); unopen(fc); if (ckexist(indexname, ".ib")) { # if D1 fprintf(stderr, "found old index\n"); # endif fa = iopen(indexname, ".ia"); fb = iopen(indexname, ".ib"); fc = iopen(indexname, ".ic"); typeindex =1; # if D1 fprintf(stderr, "opened f's as %o %o %o\n",fa,fb,fc); # endif indexdate = gdate(fb); fread (&nhash, sizeof(nhash), 1, fa); fread (&iflong, sizeof(iflong), 1, fa); if (nhash > maxhash) { if (hpt) free (hpt); hpt=0; if (hfreq) free(hfreq); hfreq=0; maxhash=nhash; # if D1 fprintf(stderr, "Freed if needed maxhash %d\n",maxhash); # endif } if (hpt==0) hpt = zalloc(nhash, sizeof(*hpt)); # if D1 fprintf(stderr, "hpt now %o\n",hpt); # endif if (hpt == NULL) err("No space for hash list (%d)", nhash); fread( hpt, sizeof(*hpt), nhash, fa); if (hfreq==0) hfreq=zalloc(nhash, sizeof(*hfreq)); if (hfreq==NULL) err("No space for hash frequencies (%d)", nhash); frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); hfrflg = (frtbl == nhash); # if D1 fprintf(stderr,"Read pointer files\n"); # endif if (master.a == NULL) { if (iflong) master.b = zalloc(lmaster, sizeof(long)); else master.a = zalloc(lmaster, sizeof(int)); } if (master.a == NULL) err("no space for answer list", 0); } else if (makefgrep(indexname)) typeindex=2; else { err("No files %s\n", indexname); exit(1); } } if (iflong) masterp = (unsigned *) master.b; else masterp = master.a; # if D1 fprintf(stderr, "typeindex now %d\n",typeindex); # endif tagout[0]=0; if (typeindex==2) { grepcall(sinput, tagout, indexname); # if D1 fprintf(stderr, " back from grepcall\n"); # endif restodir(); return; } nitem = getq(qitem); # if D1 fprintf(stderr, "approaching doquery fb %o\n", fb); # endif nfound = doquery(hpt, nhash, fb, nitem, qitem, masterp); # ifdef D1 fprintf(stderr, "return from doquery with nfound %d\n", nfound); # endif if (falseflg == 0) nfound = baddrop(masterp, nfound, fc, nitem, qitem, rprog, full); # ifdef D1 fprintf(stderr, "after baddrop with nfound %d\n",nfound); fprintf(stderr, "tagout is /%s/, sout /%s/\n",tagout, soutput); # endif if (tags) result (masterp, nfound >tags ? tags : nfound, fc); # if D1 fprintf(stderr, "done with huntmain\n"); fprintf(stderr, "tagout is /%s/\n", tagout); fprintf(stderr, "string out is /%s/\n", soutput); # endif if (fgnamp>fgnames) { char **fgp; int k; # if D1 fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); # endif grepquery[0]=0; for(k=0; k<nitem; k++) { n_strcat(grepquery, " ", sizeof(grepquery)); n_strcat(grepquery, qitem[k], sizeof(grepquery)); } for(fgp=fgnames; fgp<fgnamp; fgp++) { # if D1 fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery); # endif makefgrep(*fgp); grepcall(grepquery, tagout, *fgp); # if D1 fprintf(stderr, "tagout now /%s/\n", tagout); # endif } } restodir(); }
int main(int argc, char **argv) { const char *contentfile = 0; const char *attrname = 0; const char *descrdir = 0; const char *basefile = 0; const char *query = 0; const char *mergefile = 0; Id defvendor = 0; int flags = 0; #ifdef SUSE int add_auto = 0; #endif int c; Pool *pool; Repo *repo; while ((c = getopt(argc, argv, "hn:c:d:b:q:M:X")) >= 0) { switch (c) { case 'h': usage(0); break; case 'n': attrname = optarg; break; case 'c': contentfile = optarg; break; case 'd': descrdir = optarg; break; case 'b': basefile = optarg; break; case 'q': query = optarg; break; case 'M': mergefile = optarg; break; case 'X': #ifdef SUSE add_auto = 1; #endif break; default: usage(1); break; } } pool = pool_create(); repo = repo_create(pool, "<susetags>"); repo_add_repodata(repo, 0); if (contentfile) { FILE *fp = fopen(contentfile, "r"); if (!fp) { perror(contentfile); exit(1); } if (repo_add_content(repo, fp, REPO_REUSE_REPODATA)) { fprintf(stderr, "susetags2solv: %s: %s\n", contentfile, pool_errstr(pool)); exit(1); } defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR); fclose(fp); } if (attrname) { /* ensure '.attr' suffix */ const char *dot = strrchr(attrname, '.'); if (!dot || strcmp(dot, ".attr")) { int len = strlen (attrname); char *newname = (char *)malloc(len + 6); /* alloc for <attrname>+'.attr'+'\0' */ strcpy (newname, attrname); strcpy (newname+len, ".attr"); attrname = newname; } } /* * descrdir path given, open files and read from there */ if (descrdir) { char *fnp; int ndirs, i; struct dirent **files; ndirs = scandir(descrdir, &files, 0, alphasort); if (ndirs < 0) { perror(descrdir); exit(1); } /* bring packages to front */ for (i = 0; i < ndirs; i++) { char *fn = files[i]->d_name; if (!strcmp(fn, "packages") || !strcmp(fn, "packages.gz")) break; } if (i == ndirs) { fprintf(stderr, "found no packages file\n"); exit(1); } if (i) { struct dirent *de = files[i]; memmove(files + 1, files, i * sizeof(de)); files[0] = de; } fnp = solv_malloc(strlen(descrdir) + 128); for (i = 0; i < ndirs; i++) { char *fn = files[i]->d_name; if (!strcmp(fn, "packages") || !strcmp(fn, "packages.gz")) { FILE *fp; sprintf(fnp, "%s/%s", descrdir, fn); fp = solv_xfopen(fnp, 0); if (!fp) { perror(fn); exit(1); } if (repo_add_susetags(repo, fp, defvendor, 0, flags | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE)) { fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool)); exit(1); } fclose(fp); } else if (!strcmp(fn, "packages.DU") || !strcmp(fn, "packages.DU.gz")) { FILE *fp; sprintf(fnp, "%s/%s", descrdir, fn); fp = solv_xfopen(fnp, 0); if (!fp) { perror(fn); exit(1); } if (repo_add_susetags(repo, fp, defvendor, 0, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE)) { fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool)); exit(1); } fclose(fp); } else if (!strcmp(fn, "packages.FL") || !strcmp(fn, "packages.FL.gz")) { #if 0 sprintf(fnp, "%s/%s", descrdir, fn); FILE *fp = solv_xfopen(fnp, 0); if (!fp) { perror(fn); exit(1); } if (repo_add_susetags(repo, fp, defvendor, 0, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE)) { fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool)); exit(1); } fclose(fp); #else /* ignore for now. reactivate when filters work */ continue; #endif } else if (!strncmp(fn, "packages.", 9)) { char lang[6]; char *p; FILE *fp; sprintf(fnp, "%s/%s", descrdir, fn); p = strrchr(fnp, '.'); if (p && !strcmp(p, ".gz")) { *p = 0; p = strrchr(fnp, '.'); } if (!p || !p[1] || strlen(p + 1) > 5) continue; strcpy(lang, p + 1); sprintf(fnp, "%s/%s", descrdir, fn); fp = solv_xfopen(fnp, 0); if (!fp) { perror(fn); exit(1); } if (repo_add_susetags(repo, fp, defvendor, lang, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE)) { fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool)); exit(1); } fclose(fp); } } for (i = 0; i < ndirs; i++) free(files[i]); free(files); free(fnp); repo_internalize(repo); } else { /* read data from stdin */ if (repo_add_susetags(repo, stdin, defvendor, 0, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE)) { fprintf(stderr, "susetags2solv: %s\n", pool_errstr(pool)); exit(1); } } repo_internalize(repo); if (mergefile) { FILE *fp = fopen(mergefile, "r"); if (!fp) { perror(mergefile); exit(1); } if (repo_add_solv(repo, fp, 0)) { fprintf(stderr, "susetags2solv: %s\n", pool_errstr(pool)); exit(1); } fclose(fp); } #ifdef SUSE if (add_auto) repo_add_autopattern(repo, 0); #endif if (query) doquery(pool, repo, query); else tool_write(repo, basefile, attrname); pool_free(pool); exit(0); }
int main(int argc, char **argv) { int maxverses = -1; char outputformat = FMT_PLAIN, optionfilters = OP_NONE, searchtype = ST_NONE; char *text = 0, *locale = 0, *ref = 0; char runquery = 0; // used to check that we have enough arguments to perform a legal query // (a querytype & text = 1 and a ref = 2) for (int i = 1; i < argc; i++) { if (!stricmp("-b", argv[i])) { if (i+1 <= argc) { text = argv[i+1]; i++; runquery |= RQ_BOOK; } } else if (!stricmp("-s", argv[i])) { if (i+1 <= argc) { if (!stricmp("phrase", argv[i+1])) { searchtype = ST_PHRASE; i++; } else if (!stricmp("regex", argv[i+1])) { searchtype = ST_REGEX; i++; } else if (!stricmp("multiword", argv[i+1])) { searchtype = ST_MULTIWORD; i++; } else i++; } } else if (!stricmp("-l", argv[i])) { if (i+1 <= argc) { locale = argv[i+1]; i++; } } else if (!stricmp("-m", argv[i])) { if (i+1 <= argc) { maxverses = atoi(argv[i+1]); i++; } } else if (!stricmp("-o", argv[i])) { if (i+1 <= argc) { if (strchr(argv[i+1], 'f')) optionfilters |= OP_FOOTNOTES; if (strchr(argv[i+1], 'n')) optionfilters |= OP_STRONGS; if (strchr(argv[i+1], 'h')) optionfilters |= OP_HEADINGS; if (strchr(argv[i+1], 'm')) optionfilters |= OP_MORPH; i++; } } else if (!stricmp("-f", argv[i])) { if (i+1 <= argc) { if (!stricmp("thml", argv[i+1])) { outputformat = FMT_THML; i++; } else if (!stricmp("gbf", argv[i+1])) { outputformat = FMT_GBF; i++; } else if (!stricmp("html", argv[i+1])) { outputformat = FMT_HTML; i++; } else if (!stricmp("rtf", argv[i+1])) { outputformat = FMT_RTF; i++; } else if (!stricmp("olb", argv[i+1])) { outputformat = FMT_OLB; i++; } else i++; } } else if (!stricmp("-k", argv[i])) { i++; if (i < argc) { string key = argv[i]; i++; for (; i < argc; i++) key = key + " " + argv[i]; ref = new char[key.length() + 1]; strcpy (ref, key.c_str()); if (strlen(ref)) runquery |= RQ_REF; } } } if (runquery == (RQ_BOOK | RQ_REF)) { doquery(maxverses, outputformat, optionfilters, searchtype, text, locale, ref, &cout); } else printsyntax(); }