Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7902497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:30:32+00:00 2026-06-03T09:30:32+00:00

am writing IRC client in C lang. and encountered some problems while connecting to

  • 0

am writing IRC client in C lang. and encountered some problems while connecting to serwer.
I get the following when i run the program:

OUTPUT

Set Fully Qualified host Domain Name(human readable):  ::automaticaly provided::

Set the port number of the server You want to connect to: ::automaticaly provided::

Destination server IP: 88.190.23.245

Socket descriptor: 3

Connection has been successfully established

Peer's IP is: 88.190.23.245
Peer's port is: 5190

:irc2.gbatemp.net NOTICE AUTH :*** Looking up your hostname...

:irc2.gbatemp.net NOTICE AUTH :*** Found your hostname (cached)

Type Your nick name: ::automaticaly provided::

Type Your user name: ::automaticaly provided::

(10-20 seconds break here and than what follows down here)


ERROR :Closing Link: thisIsMyNickNameXXXa[85.221.165.54] (Ping timeout)

temp.net NOTICE AUTH :*** Found your hostname (cached)

ERROR :Closing Link: thisIsMyNickNameXXXa[85.221.165.54] (Ping timeout)

temp.net NOTICE AUTH :*** Found your hostname (cached)

ERROR :Closing Link: thisIsMyNickNameXXXa[85.221.165.54] (Ping timeout)

temp.net NOTICE AUTH :*** Found your hostname (cached)

.......
.............
...................

=============================================================

::automaticaly provided:: – means that is passed by a program for now, so i dont have to type it many times.

btw. am connecting to irc.gbatemp.net:5190 (no password required as far as am concerned)

after providing necessary data 10-20 seconds break happens (i specified in the OUTPUT part) and than ERROR temp.net part follows ad infinitum (i marked it with dots)

So the main part of the problem is how and when should i send PONG message in respons to PING ? i did my research but still cant make it. Why cant i see PING message in the STDOUT ?

am providing the code responsible for the output and PINGPONG part bellow (commented)
(main problem for now is PING PONG as Error states PING TIMEOUT) propably while(1) loop is not perfect yet, but i suppose it s subject for another topic) code bellow:

    int readReady=0;
    int writeReady=0;
    pid_t pID;
    char buf[1024];     //I/O buffer (?)
    pid_t sID;
    char *NICK = "NICK thisIsMyNickNameXXXa\n\r";
    char *USER = "USER tomaazrxtc 8 * :nameandsurname";
    char ping[512];
    char *change;

    pID=fork();
            if(pID < 0){
                //failed to execute fork()
                perror("Error while forking");
                getchar();getchar();
                exit(1);
            }
            if(pID > 0){
                exit(0);
                }
            //child down here
                //setting new session
                sID = setsid();
                if(sID < 0){
                    perror("Error while setting new session");
                    getchar();getchar();
                    exit(1);
                }

//---------receiving NOTICE AUTH :*** part-------------------------------

                if(recv(sockfd, buf, 1024,0)>0){
                printf(buf);
                }
                else{
                    perror("Error while receiving data");
                }

//---------providing and sending NICK and USERNAME-----------------------

                printf("Type Your nick name: \n");
                //scanf(nickname); pamietaj zeby zapewnic podawanie tylko nicku, a format handler zrobic osobno

                send(sockfd, NICK, strlen(NICK), 0);

                printf("Type Your user name: \n");
                //scanf(username); pamietaj zeby zapewnic podawanie tylko nicku, a format handler zrobic osobno

                send(sockfd, USER, strlen(USER), 0);

//--------Shoudnt I receive PING message just here ?????-----------------

                recv(sockfd, buf, strlen(buf), 0);
                printf(buf);

//--------PONG'ing function which I havent tested yet since i cant see PING message----

                recv(sockfd, ping, 512,0);
                if(strstr(ping, "PING")){
                    change = strstr(ping, "PING");
                    strncpy(change, "PONG", 4);
                    send(sockfd, ping, 512, 0);
                    }

//-------------------------------------------------------------------------


                while(1){
                    //sleep(1);
                    if((readReady = readReadiness(sockfd))==0){    //nothing to recv
                        if((writeReady = writeReadiness(sockfd))>0){  //sending is possible
                                scanf(buf);
                                send(sockfd, buf, strlen(buf), 0);
                                continue;
                        }
                        else
                            continue; //if there s no data to read and cant send (is it even possible?)
                    }
                    else{ //if there s some data to recv() on the socket buffer
                        recv(sockfd, buf, strlen(buf), 0);
                        printf(buf);
                        continue;
                    }
                }
//--------------------------------------------------------------------------

Ok. I will leave the question for others in future and provide an answer. It was trival.

I just added \n\r at the end of USER variable (just like in NICK string).
Connected like a charm !!

at last : ))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:30:33+00:00Added an answer on June 3, 2026 at 9:30 am

    So, a few issues I spot right away are:

    1. NICK is not properly terminated. It should be \r\n.
    2. USER is not terminated at all, it should end with \r\n.
    3. When you send your ping response, you have a hard coded size of 512. send() doesn’t work on strings, it works on raw data. So, you’ll be passing along lots of garbage here too. You need to pass the length based on what you received.
    4. printf(buf); is not safe. Any incoming string that happens to contain formatting specifiers will cause printf() to try and interpret them (this is known as a “format string vulnerability”). They should be replaced with printf("%s", buf); to achieve the same behavior in a safe way.
    5. In general your code assumes that the messages received from the IRC are nul-terminated. They are not. You should be using the return value of recv() to know how much data you received.
    6. You are using strlen() to determine the size of your buffer. This function calculates the length of a string, not the size of your buffer. You should be using the sizeof operator instead.
    7. I’m not sure what scanf(buf); is supposed to do, but it’s almost certainly not what you wanted. Maybe you were looking for fgets()?
    8. Your recv() call for ping happens right after the one for buf. How do you know which will happen when and how long they will be? Seems like you should always be working with the same buffer.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing script in remote.ini The script looks like on 1:start:{ server some.irc.server server
Writing a python program, and I came up with this error while using the
Writing some classes for a Framework extension, and I have the following code: public
I'm connecting to an IRC server but while it's sitting waiting for data I'd
Morning All, I have been writing an ever so simple IRC client in visual
I'm writing an IRC client in C++ and currently I'm having an issue where,
I am currently writing an IRC client and I've been trying to figure out
I'm writing an IRC bot using twisted python, and some actions should only be
I'm writing a c# program (An IRC bot to be specific) and using the
I am writing a IRC client in C++ (with the help of the SFML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.