Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for libplaton/platon/net/connection.c between version 1.1 and 1.2

version 1.1, 2001/10/05 13:42:11 version 1.2, 2002/09/29 03:55:02
Line 1 
Line 1 
 #include<stdio.h>  #include <stdio.h>
 #include<stdlib.h>  #include <stdlib.h>
 #include<string.h>  #include <string.h>
 #include<sys/time.h>  #include <sys/time.h>
 #include<sys/types.h>  #include <sys/types.h>
 #include<unistd.h>  #include <unistd.h>
 #include<sys/socket.h>  #include <sys/socket.h>
 #include<netinet/in.h>  #include <netinet/in.h>
 #include<netdb.h>  #include <netdb.h>
 #include<arpa/inet.h>  #include <arpa/inet.h>
   
 #include "tn_noobj.h"  #include "connection.h"
   
 static char*__telnet_buffer=NULL;  static char*__net_connection_buffer=NULL;
   
 int telnet_connect(const char*host,int port){  int net_connection_connect(const char*host,int port){
         int sock;          int sock;
         struct sockaddr_in sin;          struct sockaddr_in sin;
         struct hostent*he;          struct hostent*he;
   
         he=gethostbyname(host);          he=gethostbyname(host);
 #if DEBUG  #if DEBUG
         fprintf(stderr,"telnet_connect()\n");          fprintf(stderr,"net_connection_connect()\n");
         if(he==NULL)          if(he==NULL)
                 fprintf(stderr,"  ERROR: Unknown host. [%s]\n",host);                  fprintf(stderr,"  ERROR: Unknown host. [%s]\n",host);
         else          else
Line 31  int telnet_connect(const char*host,int p
Line 31  int telnet_connect(const char*host,int p
         if(port<=0){          if(port<=0){
 #if DEBUG  #if DEBUG
                 fprintf(stderr,"  WARNING: Bad port (%d) changed to default (%d).\n",                  fprintf(stderr,"  WARNING: Bad port (%d) changed to default (%d).\n",
                                                                 port, TELNET_PORT);                                                                  port, NET_CONNECTION_PORT);
 #endif  #endif
                 port=TELNET_PORT;                  port=NET_CONNECTION_PORT;
         }          }
   
         sin.sin_family=AF_INET;          sin.sin_family=AF_INET;
Line 63  int telnet_connect(const char*host,int p
Line 63  int telnet_connect(const char*host,int p
         return(sock);          return(sock);
 }  }
   
 int telnet_read(int handle,char*buffer,int size){  int net_connection_read(int handle,char*buffer,int size){
         struct timeval tv;          struct timeval tv;
         fd_set rd,act;          fd_set rd,act;
   
Line 88  int telnet_read(int handle,char*buffer,i
Line 88  int telnet_read(int handle,char*buffer,i
 }  }
   
   
 int telnet_gets(int handle,char*buffer,int size){  int net_connection_gets(int handle,char*buffer,int size){
   
         register int ret;          register int ret;
   
         if(__telnet_buffer!=NULL){          if(__net_connection_buffer!=NULL){
                 strncpy(buffer,__telnet_buffer,size-1);                  strncpy(buffer,__net_connection_buffer,size-1);
                 buffer[size-1]='\0';                  buffer[size-1]='\0';
         }          }
         else buffer[0]='\0';          else buffer[0]='\0';
   
         if((int)strlen(buffer)<(size-1)){          if((int)strlen(buffer)<(size-1)){
                 ret=telnet_read(handle,strchr(buffer,'\0'),size-strlen(buffer)-1);                  ret=net_connection_read(handle,strchr(buffer,'\0'),size-strlen(buffer)-1);
         }          }
         else ret=1;          else ret=1;
   
         if(ret>=0){          if(ret>=0){
                 if(strstr(buffer,TELNET_EOL)!=NULL){                  if(strstr(buffer,NET_CONNECTION_EOL)!=NULL){
                         __telnet_buffer =                          __net_connection_buffer =
                                 (char*)realloc(__telnet_buffer,(strlen(strstr(buffer,TELNET_EOL)+strlen(TELNET_EOL))+1)*sizeof(char));                                  (char*)realloc(__net_connection_buffer,(strlen(strstr(buffer,NET_CONNECTION_EOL)+strlen(NET_CONNECTION_EOL))+1)*sizeof(char));
                         strcpy(__telnet_buffer,strstr(buffer,TELNET_EOL)+strlen(TELNET_EOL));                          strcpy(__net_connection_buffer,strstr(buffer,NET_CONNECTION_EOL)+strlen(NET_CONNECTION_EOL));
                         *(strstr(buffer,TELNET_EOL)+strlen(TELNET_EOL))='\0';                          *(strstr(buffer,NET_CONNECTION_EOL)+strlen(NET_CONNECTION_EOL))='\0';
                 }                  }
                 else{                  else{
                         if(__telnet_buffer!=NULL){                          if(__net_connection_buffer!=NULL){
                                 if(strlen(buffer)<strlen(__telnet_buffer)){                                  if(strlen(buffer)<strlen(__net_connection_buffer)){
                                         strcpy(__telnet_buffer,__telnet_buffer+strlen(buffer));                                          strcpy(__net_connection_buffer,__net_connection_buffer+strlen(buffer));
                                         __telnet_buffer=(char*)realloc(__telnet_buffer,strlen(__telnet_buffer)+1);                                          __net_connection_buffer=(char*)realloc(__net_connection_buffer,strlen(__net_connection_buffer)+1);
                                 }                                  }
                                 else{                                  else{
                                         free(__telnet_buffer);                                          free(__net_connection_buffer);
                                         __telnet_buffer=NULL;                                          __net_connection_buffer=NULL;
                                 }                                  }
                         }                          }
                 }                  }
                 ret=strlen(buffer);                  ret=strlen(buffer);
         }          }
         else{          else{
                 free(__telnet_buffer);                  free(__net_connection_buffer);
                 __telnet_buffer=NULL;                  __net_connection_buffer=NULL;
         }          }
   
         return(ret);          return(ret);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top