C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 03-23-2008, 05:41 PM   #1
Registered User
 
Join Date: Oct 2007
Posts: 9
c irc bot

Uhm, just wondering what's wrong with the code:
Code:
#include <stdio.h>
#include <winsock.h>

int main(int argc, char *argv[])
{
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
        return 0;

    SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (hSocket == INVALID_SOCKET)
    {
        WSACleanup();
        return 0;
    }
    
    SOCKADDR_IN sockAddr;
    sockAddr.sin_port = htons(6667);
    sockAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
    sockAddr.sin_family = AF_INET;
    
    if (connect(hSocket, (SOCKADDR *)&sockAddr, sizeof(sockAddr)) != 0)
    {
        WSACleanup();
        return 0;
    }
    
    char buffer[260], temp[260];
    
    while (1)
    {
        int bytesRcv = recv(hSocket, buffer, sizeof(buffer), 0);
        
        if (bytesRcv != 0 || bytesRcv != SOCKET_ERROR)
        {
            printf("%s", buffer);
            
            if (strstr(buffer, "No ident response") != NULL)
            {
                sprintf(temp, "USER something something something :something");
                send(hSocket, temp, strlen(temp), 0);

                sprintf(temp, "NICK something");
                send(hSocket, temp, strlen(temp), 0);
            }
        } else break;
    }
    
    return 0;
}
Btw, I have my own ircd that I downloaded..
After receiving the message "No ident response", it should send a "user" and "nick" message and then after that the server should send me back a "ping" message..
Thanks in advance..
niqo is offline   Reply With Quote
Old 03-23-2008, 06:01 PM   #2
Registered User
 
Join Date: Jan 2008
Posts: 281
Quote:
Originally Posted by niqo View Post
Uhm, just wondering what's wrong with the code:
Isn't it your job to tell us what's wrong with the code, and our job to tell you how to fix it? I'm confused now.
arpsmack is offline   Reply With Quote
Old 03-23-2008, 06:38 PM   #3
C++ Developer
 
XSquared's Avatar
 
Join Date: Jun 2002
Location: UWaterloo
Posts: 2,718
All IRC commands must be terminated with \r\n.
__________________
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
XSquared is offline   Reply With Quote
Old 03-24-2008, 04:40 AM   #4
Registered User
 
Join Date: Oct 2007
Posts: 9
Yupz. . Got it working a while ago.. I added the \r\n. Hehe Anyways, am I writing the code correctly? Cause I noticed in one source code that it did a memset before putting another value at my variable buffer or temp.. Do i need to add that?
niqo is offline   Reply With Quote
Old 03-24-2008, 05:14 AM   #5
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,336
Quote:
Originally Posted by niqo View Post
Yupz. . Got it working a while ago.. I added the \r\n. Hehe Anyways, am I writing the code correctly? Cause I noticed in one source code that it did a memset before putting another value at my variable buffer or temp.. Do i need to add that?
if you check the return value of the recv and work according to it - you do not need the memset beforehead
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 03-24-2008, 05:24 AM   #6
Banned
 
Join Date: Nov 2007
Posts: 678
should not this be posted in network section?

anyway. does anybody know why this happened:

i found my ip by visiting a site (modem based 64kbps net)
then wrote a simple server and asked my brother to connect to me using winxp telnet!
but he could not connect! why??
manav is offline   Reply With Quote
Old 03-24-2008, 05:24 AM   #7
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,710
Well you'll want to read this thoroughly.
Useful Links And Good Books

Edit:
And moved, as noted by manav.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Design guidelines advice - IRC Bot class IceDane C# Programming 2 12-05-2008 01:21 AM
Need some help with making irc bot kazz C++ Programming 6 11-23-2007 11:47 AM
IRC, reading the stream Iyouboushi C# Programming 6 08-03-2006 05:34 PM
Cross-compilable IRC bot radiohead C Programming 2 03-19-2006 09:27 PM
Whats wrong with my IRC Bot?? peradox Networking/Device Communication 8 05-23-2005 05:16 PM


All times are GMT -6. The time now is 08:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22