Thread: Telnet-client, get abracadabra from server

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    8

    Telnet-client, get abracadabra from server

    Code:
    #include <stdio.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define BUF_LEN 1024
    #define PORT 23
    
    int main (void)
    {
       int sock=socket(PF_INET, SOCK_STREAM,0);
                           if(sock==-1)  {perror("socket()="); return 0;}
    
    
          struct sockaddr_in addr;
          addr.sin_family = AF_INET;
          
          struct hostent *host=gethostbyname("192.168.56.101");
            perror("gethostbyname()=");
    
         addr.sin_addr =*(struct in_addr*)
    	              	host->h_addr_list[0];
    
         addr.sin_port=htons(PORT);
    
         int con=connect(sock,(struct sockaddr*) &addr, sizeof(addr));
         perror("connect()=");
    
         if (con==-1)return 0;
    
         char buf[BUF_LEN];
         int count;
    
          while ( (count=read(sock,buf, 2))>0 ) 
                                                          write (1,buf,count);
    
          close(sock); 
    
    return 0;
    }
    result in console:
    Code:
    [up@COR ~]$ ./telc
    gethostbyname()=: Success
    connect()=: Success
    ���� ��#��'^X
    ^C
    How can i get normal symbols? Where is my mistake?

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Telnet - Wikipedia, the free encyclopedia

    are you sure its a telnet server and not ssh?

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    i'm sure, because it is my telnet-server, and i can connect with it through standard telnet-client

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Get wireshark, and compare network traces between your app and a known good implementation.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    Maybe the server wants to perform option negotation and you're reading that stuff and not characters you were expecting.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. server client application - (i really need your help)
    By sarahnetworking in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 10:54 PM
  2. Socket Programming Problem!!!!
    By bobthebullet990 in forum Networking/Device Communication
    Replies: 2
    Last Post: 02-21-2008, 07:36 PM
  3. c program client server
    By steve1_rm in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-24-2008, 10:33 AM
  4. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM
  5. Unicode vurses Non Unicode client server application with winsock2 query?
    By dp_76 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-16-2005, 07:26 AM