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?