chanuser::chanuser(const char *m, const chan *ch, const int f, const bool scan) #ifdef HAVE_MODULES : CustomDataStorage() #endif { char *a = strchr(m, '!'); char *b = strchr(m, '@'); reason = NULL; if(!a || !b) { memset(this, 0, sizeof(chanuser)); return; } mem_strncpy(nick, m, (int) abs(m - a) +1); mem_strncpy(ident, a+1, (int) abs(a - b)); mem_strcpy(host, b+1); flags = f; if(scan) flags |= userlist.getFlags(m, ch); hash = ::hash32(nick); handle = NULL; switch(isValidIp(host)) { case 4: dnsinfo = HOST_IPV4; mem_strcpy(ip4, host); mem_strcpy(ip6, ""); break; case 6: dnsinfo = HOST_IPV6; mem_strcpy(ip4, ""); mem_strcpy(ip6, host); break; default: dnsinfo = HOST_DOMAIN; mem_strcpy(ip4, ""); mem_strcpy(ip6, ""); break; } clones_to_check = CLONE_HOST | CLONE_IPV6 | CLONE_IPV4 | CLONE_IDENT | CLONE_PROXY; HOOK( onNewChanuser( this ) ); }
void interaction::traceIpHost(const char* ipHost) { //----------------------- // check if we over limit //----------------------- if(rLimitor->isOverLimit()) { // notify user dprintf(connfd, "*********************************************\n"); dprintf(connfd, "Making too many requests than you can\n"); dprintf(connfd, "%s\n",rLimitor->currentLimit()); dprintf(connfd, "*********************************************\n"); // log it extern eventsLog servLog; servLog.logIt("User from IP: %s (with pid %d)" " making too many requests\n", userIp(*clientAddr), getpid()); return; } //--------------------------------------------- // check if ip hinted by ipHost is valid or not //--------------------------------------------- if(strict) { if(!isValidIp(ipHost)) { return; } } pid_t child_pid; if((child_pid=fork())<0) { sys_err("call to fork() failed"); } else if(child_pid==0) { // in child // Close stuff from parents // redirect stderr and stdout to connfd Dup2(connfd, STDOUT_FILENO); Dup2(connfd, STDERR_FILENO); cout<<"------------------------------------------" <<"----------------------------------"<<endl; // call execlp 'NULL' must be provided execlp("traceroute","traceroute",ipHost, NULL); } else {// in parent if(VOMIT) { cout<<"client interaction process: "<<getpid() <<" forked a child with pid: "<<child_pid<<endl; } // block until child finish waitpid(child_pid, NULL, 0); } }
//synchronious lookup int inet::gethostbyname(const char *host, char *buf, int protocol) { if(isValidIp(host)) { strncpy(buf, host, MAX_LEN); return 1; } #ifdef NO_6DNS struct hostent *h = ::gethostbyname(host); #else struct hostent *h = gethostbyname2(host, protocol); #endif if(h) { if(inet_ntop(protocol, h->h_addr, buf, MAX_LEN)) return 1; } return 0; }
atstat_e network_config(int32_t cNum, c8_t *ipAddr) { struct sockaddr_in clientAddr; int32_t portnumber; int32_t addr_len; atbool_e ipCheck; if(cNum < MIN_CLIENT|| cNum > MAX_CLIENT-1 || ipAddr == NULL){ printf("invalid parameter!\n"); return AT_FAILED; } ipCheck = isValidIp(ipAddr); if(ipCheck == AT_FALSE){ return AT_FAILED; } if(gClientFlag[cNum] == USED){ printf("client using\n"); return AT_FAILED; } portnumber = SERVER_PORT; bzero(&clientAddr,sizeof(struct sockaddr_in)); clientAddr.sin_family = AF_INET; clientAddr.sin_port = htons(portnumber); if(inet_aton(ipAddr,&clientAddr.sin_addr)<0) { fprintf(stderr,"Ip error:%s\n",strerror(errno)); return AT_FAILED; } addr_len = sizeof(struct sockaddr_in); gSockets[cNum] = socket(AF_INET,SOCK_DGRAM,0); if(gSockets[cNum] == FAILED){ printf("create socket failed!\n"); return AT_FAILED; } setClientSockAddr(cNum, &clientAddr); return AT_OK; }