I found this small daemon program that listens on a port. I want to write something that emulates a smtp daemon. I learned some things from the code in the small daemon, and wrote one for my purposes. The problem is, that it will not run. It will compile, and "./infection" will work, but it will not start as a process nor listen on a port as I need it to do. I edited it and put a loop in maybe thinking it would help it run (maybe not =P), well, not it just fork bombs me.
Here is the code, maybe you can help me figure out what i'm doing wrong:
All help would be much appreciated.Code:/* Infection, Fake SMTP Daemon- By Tal0n 01-05-04 */ /* Include the headers and etc that we need. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <netinet/in.h> #include <sys/socket.h> #include <sys/types.h> #include <signal.h> /* Define port we are using. */ #define PORT 25 /* Define the message we want displayed. */ #define MSG "220 localhost ESMTP Sendmail 8.11.3/8.11.3; Mon, 5 Jan 2004 13:56:31 -0800" /* Begin Program */ int main(int argc, char *argv[]); int main(int argc, char *argv[]) { /* Defining what the process's name will be. */ strcpy(argv[0], "fake-smtpd"); signal(SIGCHLD, SIG_IGN); /* Declare sockets and such. */ int sockfd, newfd, size; struct sockaddr_in local; struct sockaddr_in remote; /* Zero the rest of the struct. */ bzero(&local, sizeof(local)); /* Get sockets ready to use. */ local.sin_family = AF_INET; local.sin_port = (PORT); local.sin_addr.s_addr = INADDR_ANY; /* Zero the rest of the struct. */ bzero(&(local.sin_zero), 8); /* Defining 'size' as the sizeof the socket. */ size = sizeof(struct sockaddr_in); while(1) { /* Send the message if a connection is made. */ if(!fork()) { send(newfd, MSG, sizeof(MSG), 0); /* Close Sockets. */ close(newfd); } } /* End Program. */ return 0; } /* EOF */
Thank you,
-Tal0n



LinkBack URL
About LinkBacks


