IRC Bot error

Discussion in 'C' started by Vip3r, Aug 9, 2008.

  1. Vip3r

    Vip3r New Member

    Joined:
    Aug 5, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Dont have one
    Location:
    New jersey
    Ok i have this irc bot:

    Code:
    #include <iostream> 
    
    #include <errno.h> 
    
    #include <cstring> 
    
    #include <netdb.h> 
    
    #include <sys/types.h> 
    
    #include <netinet/in.h> 
    
    #include <sys/socket.h> 
    
    #include <unistd.h> 
    
    
    
    using namespace std; 
    
    
    
    
    char *substr (const char *str, int start, int end) { 
    
    char *sub = new char[strlen(str)]; 
    
    start -=1 ; 
    
    
    
    for(int i = 0;start<end;i += 1) { 
    
    sub[i] = str[start]; 
    
    start += 1; 
    
    } 
    
    sub[end] = '\0'; 
    
    
    
    return sub; 
    
    } 
    
    
    
    int main() { 
    
    
    
    struct hostent *he; 
    
    struct sockaddr_in their_addr; 
    
    int sockfd; 
    
    char msg[512]; 
    
    char buffer[512]; 
    
    int length; 
    
    int stay = 1; 
    
    
    
    cout << "SimpleBot" << endl << "A Simple IRC Bot" << endl; 
    
    
    
    
    if ((he=gethostbyname("irc.quickstrike.org")) == NULL) { 
    
    perror("gethostbyname"); 
    
    exit(1); 
    
    } 
    
    
    
    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 
    
    perror("socket"); 
    
    exit(1); 
    
    } 
    
    
    
    their_addr.sin_family = AF_INET; 
    
    their_addr.sin_port = htons(6667); 
    
    their_addr.sin_addr = *((struct in_addr *)he->h_addr); 
    
    memset(&(their_addr.sin_zero), '\0',  ; 
    
    
    
    if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) { 
    
    perror("connect"); 
    
    exit(1); 
    
    } 
    
    
    
    
    
    strcpy(msg,"USER simple simple simple :SimpleBot Example>br /<NICK SimpleIRC>br /<"); 
    
    
    
    if (send(sockfd, msg, strlen(msg), 0) == -1) { 
    
    perror("send"); 
    
    } 
    
    
    
    while (stay) { 
    
    
    
    if ((length=recv(sockfd, buffer, 511, 0)) == -1) { 
    
    perror("recv"); 
    
    exit(1); 
    
    } 
    
    buffer[length] = '\0'; 
    
    
    
    
    
    for (int i = 0; buffer[i] != '\0'; i += 1) { 
    
    
    
    if (strncmp(substr(buffer,i,i+4),"PING",4) == 0) { 
    
    
    sprintf(msg, "PONG %s>br /<join :#testchan>br /<",substr(buffer,i+6,i+13)); 
    
    
    
    if (send(sockfd, msg, strlen(msg), 0) == -1) { 
    
    perror("send"); 
    
    } 
    
    } 
    
    
    
    if (strncmp(substr(buffer,i,i+5),"hello",5) == 0) { 
    
    
    
    strcpy(msg, "PRIVMSG #testchan :bye!>br /<QUIT>br /<"); 
    
    
    
    if (send(sockfd, msg, strlen(msg), 0) == -1) { 
    
    perror("send"); 
    
    } 
    
    
    
    stay = 0;
    
    } 
    
    
    
    } 
    
    
    
    } 
    
    
    
    close(sockfd); 
    
    
    
    return 0; 
    
    }
    
    And the errors i get are these:

    Code:
    c:\users\bioshock\documents\c++\ircbot.cpp:7: netdb.h: No such file or directory
    c:\users\bioshock\documents\c++\ircbot.cpp:11: netinet\in.h: No such file or directory
    c:\users\bioshock\documents\c++\ircbot.cpp:13: sys\socket.h: No such file or directory
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice