43 #include <netinet/in.h> 44 #include <netinet/tcp.h> 47 #include <sys/types.h> 49 #include <sys/socket.h> 51 #include <arpa/inet.h> 59 #define SIGNAL_PORT 8418 60 #define COMMAND_PORT 8417 61 #define SEND_ENVIORNMENT 71 #define WINBUF_NUM 2400 123 perror(
"signal socket");
131 perror(
"command socket");
166 #ifdef SEND_ENVIORNMENT 171 if(feof(stdin) ||
buf[0]==
'\n')
206 count=read(file,buffer+pos,num);
207 if(count==0 || (count<0 &&
errno!=EAGAIN))
220 struct hostent* host_entity;
223 struct sockaddr_in host;
227 if(!strcmp(name,
"localhost"))
228 address=htonl(2130706433);
231 address=inet_addr(name);
232 if(address==(in_addr_t)-1)
238 fprintf(stderr,
"EAGI proxy: Wrong address!\n");
241 address=*((
int*)host_entity->h_addr);
245 desc=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
248 fprintf(stderr,
"EAGI proxy: Cannot create socket!\n");
252 memset((
void*)&host,0,
sizeof(
struct sockaddr_in));
254 host.sin_family=AF_INET;
255 host.sin_port=htons(port);
258 res=connect(desc,(
struct sockaddr*)&host,
sizeof(host));
261 fprintf(stderr,
"EAGI proxy: Cannot connect!\n");
266 opts = fcntl(desc,F_GETFL);
268 perror(
"fcntl(F_GETFL)");
271 opts = (opts | O_NONBLOCK);
272 if (fcntl(desc,F_SETFL,opts) < 0) {
273 perror(
"fcntl(F_SETFL)");
293 perror(
"Error reading");
351 memcpy(be,buf,
end-be);
369 fprintf(stderr,
"Buffer overflow!\n");
385 ret=write(desc,buf,size);
390 perror(
"Error writing");
406 opts = fcntl(desc,F_GETFL);
409 perror(
"fcntl(F_GETFL)");
413 opts = (opts | O_NONBLOCK );
414 if(fcntl(desc,F_SETFL,opts) < 0)
416 perror(
"fcntl(F_SETFL)");
#define pthread_mutex_init
int read_some(int file, char *buffer, int size)
Time-related functions and macros.
pthread_mutex_t command_mutex
void write_buf(int file, char *buffer, int num)
#define pthread_mutex_lock
void * readSignal(void *ptr)
void * readStdin(void *ptr)
int write_amap(int file, char *buffer, int num)
int connect_to_host(char *host, int port)
void setnonblocking(int desc)
void read_full(int file, char *buffer, int num)
#define pthread_mutex_unlock