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 8999765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:13:24+00:00 2026-06-16T00:13:24+00:00

I’m trying to create a program that monitors an IRC server, and I’m having

  • 0

I’m trying to create a program that monitors an IRC server, and I’m having trouble even with the basics of connecting. I’m working on a linux cluster, at my school.

I simply don’t know what I’m doing wrong. Here’s my code, copied almost verbatim from TCP IP Sockets in C, Chapter 2.

 int main(int argc, char** argv)
 {

      char *servName = "irc.freenode.net";
      in_port_t servPort = 6667;

      //Start populating server information into a sockaddr
      struct sockaddr_in servAddr;
           memset(&servAddr, 0, sizeof(servAddr));

           //To get the IP address of irc.freenode.net
               //Using gethostbyname
           char servIP[16];
           struct hostent *hent;
           hent = gethostbyname(servName);
           inet_ntop(AF_INET, (void *)hent->h_addr_list[0],servIP,16);         

           //Convert the IP address's endianness
           int rtnVal = inet_pton(AF_INET, servIP, &servAddr.sin_addr.s_addr);
           if(rtnVal <= 0)
                dieMsg("inet fail",rtnVal);

           servAddr.sin_port = htons(servPort);
           servAddr.sin_family = AF_INET;
           printf("%s\n",servIP);
      //End server information

      //Open a socket to use
      int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);          
      if(sock<0)
           dieMsg("sock fail",sock);

      //Connect using the sock, and the populated sockaddr struct.
      if(connect(sock,(struct sockaddr*) &servAddr, sizeof(servAddr))<0);
      {
           dieMsg("con fail",-1);
      }

      return 0;
 }

dieMsg is a function that takes a string and an int, prints them, and then exits.

The output of this code is

89.16.176.16
con fail -1

Alternatively, I’ve also used the addrinfo struct, to no avail:

int main(int argc, char** argv)
{    

     char *servHostc = "irc.freenode.net";
     char *servPortc = "6667";

     struct addrinfo addrCriteria;
     memset(&addrCriteria, 0, sizeof(addrCriteria));
     addrCriteria.ai_family = AF_INET;
     addrCriteria.ai_socktype = SOCK_STREAM;
     addrCriteria.ai_protocol = IPPROTO_TCP;

     struct addrinfo *servAddr;
     int rtnVal = getaddrinfo(servHostc,servPortc, &addrCriteria, &servAddr);
     if(rtnVal != 0)
          dieMsg("getaddrinfo() connect fail", rtnVal);

     int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

     if(connect(sock, (struct sockaddr*) &servAddr, sizeof(servAddr) < 0))
     {
          free(servAddr);
          dieMsg("Connect failed",-1);
     }

     return 0;
}

Telnet works for both addresses, so it’s not my internet connection.

$ telnet irc.freenode.net 6667
Trying 128.237.157.136...
Connected to irc.freenode.net (128.237.157.136).
Escape character is '^]'.
:hubbard.freenode.net NOTICE * :*** Looking up your hostname...
:hubbard.freenode.net NOTICE * :*** Checking Ident
:hubbard.freenode.net NOTICE * :*** Found your hostname
^]
telnet> Connection closed.
$ telnet 89.16.176.16 6667
Trying 89.16.176.16...
Connected to wolfe.freenode.net (89.16.176.16).
Escape character is '^]'.
:wolfe.freenode.net NOTICE * :*** Looking up your hostname...
:wolfe.freenode.net NOTICE * :*** Checking Ident
:wolfe.freenode.net NOTICE * :*** Found your hostname
^]
telnet> Connection closed.

I usually hate asking questions, so this is my last resort. If anyone can please please shed some light on my predicament, I will be so grateful.

  • 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-16T00:13:25+00:00Added an answer on June 16, 2026 at 12:13 am
      if(connect(sock,(struct sockaddr*) &servAddr, sizeof(servAddr))<0);
      {
           dieMsg("con fail",-1);
      }
    

    ; at the end of if.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace

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.