Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,315 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,073 people online right now. Registration is fast and FREE... Join Now!




IRC Bot

 
Reply to this topicStart new topic

IRC Bot, Can't seem to join a channel

RapidShark
post 13 Mar, 2008 - 05:03 AM
Post #1


New D.I.C Head

*
Joined: 30 Mar, 2007
Posts: 5


My Contributions


Hey. I've been trying to get this thing to work for a while, and finally managed to be able to connect to the server, but now I can't seem to join a channel. Any help would be great. Thanks =]


[code]
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>

void fail(char *bleh) {
perror(bleh);
exit(-1);
}

int main() {

int sent;
int get;
int fd;
char buf[513];
struct hostent *he;
struct sockaddr_in theaddr;
char nick[]="NICK TheBot\r\n";
char real[]="REALNAME TheBot\r\n";
char ident[]="IDENT meep\r\n";
char j[]="JOIN #smack\r\n";

if((he = gethostbyname("mofo.planet-sec.org")) == NULL) herror("gethostbyname");

if((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1) fail("socket");

theaddr.sin_family = AF_INET;
theaddr.sin_port = htons(6667);
theaddr.sin_addr = *((struct in_addr *)he->h_addr);
memset(theaddr.sin_zero, '\0', sizeof(theaddr.sin_zero));

if(connect(fd, (struct sockaddr *)&theaddr, sizeof(theaddr)) == -1) fail("connect");

printf("connected!\n");
sent = send(fd, nick, strlen(nick), 0);
sent = send(fd, real, strlen(real), 0);
sent = send(fd, ident, strlen(ident), 0);
sent = send(fd, j, strlen(j), 0);
printf("Joined Channel\n");
return 0;

}

This post has been edited by RapidShark: 13 Mar, 2008 - 05:04 AM
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 13 Mar, 2008 - 05:05 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,170



Thanked 33 times

Dream Kudos: 25
My Contributions


Are you getting an error message? Or does it just hang?
User is offlineProfile CardPM

Go to the top of the page

RapidShark
post 13 Mar, 2008 - 05:08 AM
Post #3


New D.I.C Head

*
Joined: 30 Mar, 2007
Posts: 5


My Contributions


It just hangs.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 02:22AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month