#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    10
    Rep Power
    0

    socket problem...


    When i try connect to irc i get follow messages...

    NOTICE AUTH :*** Looking up your hostname
    NOTICE AUTH :*** Checking Ident
    NOTICE AUTH :*** Found your hostname
    NOTICE AUTH :*** No ident response
    ERROR :Closing Link: by barrysworld1.uk.quakenet.org (Ping Timeout)

    and my code is:

    Code:
    #include <iostream>
    #include <netinet/in.h>
    #include <sys/socket.h>
    #include <sys/types.h>
    #include <netdb.h>
    #include <unistd.h>
    
    using namespace std;
    
    #define PORT 6667
    #define MAXDATASIZE 100
    
    int main(int argc, char *argv[])
    {
      int sockfd, numbytes, len, bytes_sent;
      char *nick = "NICK Stupid";
      char *user = "USER stupid yep yup :hmmph";
      char buf[MAXDATASIZE];
      struct hostent *he;
      struct sockaddr_in their_addr;
    
      he=gethostbyname(argv[1]);
      sockfd = socket(AF_INET, SOCK_STREAM, 0);
      
      their_addr.sin_family = AF_INET;
      their_addr.sin_port = htons(PORT);
      their_addr.sin_addr = *((struct in_addr *)he->h_addr);
      memset(&(their_addr.sin_zero), '\0', 8);
    
      connect(sockfd, (struct sockaddr *) &their_addr, sizeof(struct sockaddr));
      len = strlen(nick);
      bytes_sent = send(sockfd, nick, len, 0);
      len = strlen(user),
      bytes_sent = send(sockfd, user, len, 0);
      while(1){
        numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0);
        if(numbytes)
        {
          buf[numbytes] = '\0';
          cout << buf;
        }
      }
      close(sockfd);
      return 0;
    }
    so can somebody tell me what i do wrong?
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    Well, a quick look indicates you never have an exit from your while loop polling for data.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    10
    Rep Power
    0
    Originally posted by mitakeet
    Well, a quick look indicates you never have an exit from your while loop polling for data.
    sorry but i don't understand how that help me with my problem...
  6. #4
  7. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    Without being able to run your program (I would need to have the address you are trying to connect to and it would have to be accessible to me) I won't be able to offer much more help. The errors indicate that you are unable to make a connection to the server, something I presume is obvious to you. Just glancing at your code I saw that error, so pointed it out.

    Can you ping the address you are trying to connect to? Are you sure there is a server listening on that port?

    BTW: What happens to your code if it is run with no argv[1]?

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    10
    Rep Power
    0
    i try to connect irc.quakenet.org and i'm sure that work and i get same with other servers...

    Originally posted by mitakeet

    BTW: What happens to your code if it is run with no argv[1]?
    Segmentation fault but it's not important now...i think...
  10. #6
  11. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    I can't get your code to compile on FreeBSD, what OS are you using?

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  12. #7
  13. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    read more about the irc protocol and how to handle ident. also you're not checking any of the return values from your functions.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    10
    Rep Power
    0
    Originally posted by mitakeet
    I can't get your code to compile on FreeBSD, what OS are you using?
    Slackware and g++ (GCC) 3.2.2...
  16. #9
  17. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    Well, after modifying your code to run on Windows (and putting in a bunch of error checking and fixing a few bugs), I find that the problem is not with your code, but with the data you are sending the server. I get this when I try to connect:

    NOTICE AUTH :*** Looking up your hostname
    NOTICE AUTH :*** Found your hostname, cached
    NOTICE AUTH :*** Checking Ident

    Then it appears to hang. Since every bit of that is being returned from the server, your TCP/IP connection protocol is fine, but your IRC connection protocol is somehow deficient. It is possible someone else here can help you, but I expect you will need to talk to whomsoever maintains the server to get the appropriate protocol exchange.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  18. #10
  19. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    easiest thing to do is sniff a real irc client and copy that if your too lazy to read the protocol. :)
  20. #11
  21. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    That presuposes the knowledge to sniff. Based on the quality of the code posted, I strongly doubt Jiuy can handle that advice.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    10
    Rep Power
    0
    ok...
    i put \n end of user and nick lines...and then all work fine...now i can start write better version (error handling etc)

IMN logo majestic logo threadwatch logo seochat tools logo