boolean_t rn_refines(char *m, char *n) { char *lim, *lim2; int longer = clen(n++) - clen(m++); boolean_t masks_are_equal = TRUE; lim2 = lim = n + clen(n); if (longer > 0) lim -= longer; while (n < lim) { if (*n & ~(*m)) return FALSE; if (*n++ != *m++) masks_are_equal = FALSE; } while (n < lim2) if (*n++) return FALSE; if (masks_are_equal && (longer < 0)) for (lim2 = m - longer; m < lim2; ) if (*m++) return TRUE; return (!masks_are_equal); }
struct radix_node * rn_match(char *key, struct radix_node_head *head) { struct radix_node *t, *x; char *cp = key, *cp2; char *cplim; struct radix_node *saved_t, *top = head->rnh_treetop; int off = top->rn_offset, klen, matched_off; int test, b, rn_bit; t = rn_search(key, top); /* * See if we match exactly as a host destination * or at least learn how many bits match, for normal mask finesse. * * It doesn't hurt us to limit how many bytes to check * to the length of the mask, since if it matches we had a genuine * match and the leaf we have is the most specific one anyway; * if it didn't match with a shorter length it would fail * with a long one. This wins big for class B&C netmasks which * are probably the most common case... */ if (t->rn_mask != NULL) klen = clen(t->rn_mask); else klen = clen(key); cp += off; cp2 = t->rn_key + off; cplim = key + klen; for (; cp < cplim; cp++, cp2++) if (*cp != *cp2) goto on1; /* * This extra grot is in case we are explicitly asked * to look up the default. Ugh! * * Never return the root node itself, it seems to cause a * lot of confusion. */ if (t->rn_flags & RNF_ROOT) t = t->rn_dupedkey; return t; on1: test = (*cp ^ *cp2) & 0xff; /* find first bit that differs */ for (b = 7; (test >>= 1) > 0;)
static boolean_t rn_satisfies_leaf(char *trial, struct radix_node *leaf, int skip) { char *cp = trial, *cp2 = leaf->rn_key, *cp3 = leaf->rn_mask; char *cplim; int length = min(clen(cp), clen(cp2)); if (cp3 == NULL) cp3 = rn_ones; else length = min(length, clen(cp3)); cplim = cp + length; cp3 += skip; cp2 += skip; for (cp += skip; cp < cplim; cp++, cp2++, cp3++) if ((*cp ^ *cp2) & *cp3) return FALSE; return TRUE; }
int cint(char* c) { int i=1,j=0,k; for(k=clen(c);k!=0;k--) i*=0xa; for(i=i;i!=0;i/=10) { switch(*(c+i)) { case 1: j+=(1*i); break; case 2: j+=(2*i); break; case 3: j+=(3*i); break; case 4: j+=(4*i); break; case 5: j+=(5*i); break; case 6: j+=(6*i); break; case 7: j+=(7*i); break; case 8: j+=(8*i); break; case 9: j+=(9*i); break; } } return j; }
int main(int argc, char **argv) { short mode=0; short i,j; //incrementers short p,t; //# of users stated in profile.dat(first 2 char),timeout char c; //getc buffer const char default_filename_profile[]="profile.dat\n"; char arr_status[]={ 'C','u','r','r','e','n','t','l','y',0x20,'O','f','f','l','i','n','e',0x0, 'C','u','r','r','e','n','t','l','y',0x20,'O','n','l','i','n','e',0x0, 'C','u','r','r','e','n','t','l','y',0x20,'I','n','-','G','a','m','e',0x0, 'T','e','a','m',0x20,'F','o','r','t','r','e','s','s',0x20,'2',0x0, 'e','r','r','o','r',0x0}; char **status; //{"Currently Offline\0","Currently Online\0","Currently In-Game\0","Team Fortress 2\0","error\0"}; char compare[3][40]={"<div class=\"profile_in_game_header\">\0","<div class=\"profile_in_game_name\">\0","<a href=\"steam://connect\0"}; char *filename_profile; void (*get_html)(char*,FILE*)=&vinyl_get_html; //use program's html-protocol //head *(filename_profile+0)=(char)(&default_filename_profile[0]); status=malloc(5*sizeof(char)); j=0; for(i=0;i<5;i++) { do { j++; }while(arr_status[j]!=0x0); j++; *(status+i)=&arr_status[j]; } if(argc>1 || *(*(argv+1)+0)=='-') { for(i=1;i<clen(*(argv+1));i++) { switch(*(*(argv+1)+i)) { case 'c': (*get_html)(char*)=&scratch_get_html; break; //use curl case 'l': mode+=1; break; //don't log: 1,3,5,7,9,11,13,15 case 'i': mode+=2; break; //interactive: 2,3,6,7,10,11,14,15 case 's': mode+=4; break; //silent: 4,5,6,7,12,13,14,15 case 'j': mode+=8; break; //join game: 8,9,10,11,12,13,14,15 case 'o': goto options; //options: timeout,profile file } } } goto headend; options:; for(i=2;i<argc;i+=2) { switch(*(*(argv+i)+1)) { case 't': t=cint(*(argv+i+1)); break; case 'f': filename_profile=&*(*(argv+i+1)); break; } } headend:; FILE *fpro = fopen(filename_profile,"r"); void *tmp=malloc(3*sizeof(char)); *(&tmp+(0*sizeof(char)))=getc(fpro); *(&tmp+(1*sizeof(char)))=getc(fpro); //to use as value: (char*)*((&tmp)+1*sizeof(char)); *(&tmp+(2*sizeof(char)))=0x0; p=(cint(tmp)); free(tmp); struct struct_profile *profile[p]; struct struct_memStream *memstream[p]; for(i=p;i!=0;i--) { profile[i]=malloc(sizeof(struct struct_profile)); profile[i]->status=-1; //uninitialized profile[i]->name=malloc(25*sizeof(char)); profile[i]->url=malloc(100*sizeof(char)); while(getc(fpro)!='\n'); //go to next line //set name j=0; c=getc(fpro); do { *(profile[i]->name+j)=c; j++; c=getc(fpro); }while(c!='\n'); //set url j=0; c=getc(fpro); do { *(profile[i]->url+j)=c; j++; c=getc(fpro); }while(c!='\n'); memstream[i]=malloc(sizeof(struct struct_memStream)); memstream[i]->buffer=0x0; memstream[i]->stream=open_memStream(&(memstream[i]->buffer),&(memstream[i]->size)); } //body while(0) { for(i=p;i!=0;i--) { (*get_html)(&profile[i]->url,&memstream[i]->stream); //read stream while(j!=430) { c=getc(memstream[i]->stream); if(c=='\n') j++; } j=0; c=getc(memstream[i]->stream); while(c!=EOF) { if(c==compare[0][j]) { j++; if(compare[0][j]==0x0) goto gud; } else j=0; c=getc(memstream[i]->stream); } printf("error could not find %s\n",compare[0]); gud:; c=getc(memstream[i]->stream); while(c!="<") { //if() c=getc(memstream[i]->stream); } //log //actions #if defined (WIN32) //windows #elif defined (__unix__) //unix #endif } } return 0; }
int main(int argc, char **argv) { int c; int option_index = 0; prog_name = argv[0]; bool unpack = false; const char *type = NULL; const char *input_file = NULL; const char *output_file = NULL; static struct option long_options[] = { {"unpack", no_argument, 0, 'd' }, {"type", required_argument, 0, 't' }, {"input", required_argument, 0, 'i' }, {"output", required_argument, 0, 'o' }, }; while ((c = getopt_long(argc, argv, "dt:i:o:", long_options, &option_index)) != -1) { if (c == 'd') { unpack = true; } else if (c == 'i') { input_file = optarg; } else if (c == 'o') { output_file = optarg; } else if (c == 't') { type = optarg; } } unsigned char *data; unsigned int length = 0; if (!input_file || !(data = read_file(input_file, &length)) || (!unpack && !type)) return help(); char *out_filename = (char *) malloc(strlen(input_file) + (output_file ? strlen(output_file) : 0) + 32); if (unpack) { mtk_container c; if (length < sizeof(struct mtk_container_hdr) || memcmp(data, clen(MTK_CONTAINER)) != 0) { free(data); fprintf(stderr, "File %s is not MTK container!\n", input_file); return 1; } c.header = (struct mtk_container_hdr *) data; c.data = (unsigned char *) (data + sizeof(struct mtk_container_hdr)); c.length = c.header->data_length; if (length < sizeof(struct mtk_container_hdr) + c.length) { free(data); fprintf(stderr, "File %s corrupted!\n", input_file); return 1; } printf("unpacking...\n"); printf("type: %s\n", c.header->data_type); printf("size: 0x%08X\n", c.header->data_length); if (output_file && is_dir(output_file)) { sprintf(out_filename, "%s/%s", output_file, basename((char *) input_file)); } else if (output_file) { sprintf(out_filename, "%s", output_file); } else sprintf(out_filename, "./%s.raw", basename((char *) input_file)); write_file(out_filename, 1, c.data, c.length); } else { mtk_container_hdr hdr; memset(hdr.data_type, 0, sizeof(hdr.data_type)); memset(hdr.reserved, 0xFF, sizeof(hdr.reserved)); printf("packing...\n"); printf("type: %s\n", type); printf("size: 0x%08X\n", length); hdr.data_length = length; memcpy(hdr.magic, MTK_CONTAINER, sizeof(MTK_CONTAINER)); strcpy(hdr.data_type, type); if (output_file && is_dir(output_file)) { sprintf(out_filename, "%s/%s", output_file, basename((char *) input_file)); } else if (output_file) { sprintf(out_filename, "%s", output_file); } else sprintf(out_filename, "./%s.bin", basename((char *) input_file)); write_file(out_filename, 2, &hdr, sizeof(hdr), data, length); } free(out_filename); free(data); return 0; }