12
#include <sys/socket.h>
13
//#include "internet.h"
15
#define saddr "/tmp/ds-4olga"
16
#define maxanswersize 1024
18
//sends query to the perl-script that sends it to altavista.
24
void runparent(pid_t child) {
25
// waitpid(child,NULL,0);
28
void runchild(char *command) {
29
execl("/bin/bash","bash","-c",command,NULL);
30
cerr<<"Error in runchild: "<<errno<<"\n";
34
void request(int sd,char *req, char *answer) {
35
int readed=strlen(req);
39
if (send(sd,req,strlen(req)+1,0)<=0) {
40
printf("Error sending request, error: %i!\n",errno);
45
readed=recv(sd,answer,maxanswersize,0);
47
printf("Error getting answer, error: %i!\n",errno);
51
/* For unknown reason answer[0]==0???
52
printf("%i\n>",readed);
53
for(int i=0;i<readed;i++) printf("%i - %c;",i,answer[i]);
54
printf("< %s\n",answer+1); */
60
struct sockaddr mysock,perlsock;
61
socklen_t i=sizeof(struct sockaddr);
64
char buf[255],answer[maxanswersize];
67
s=socket(PF_UNIX,SOCK_STREAM,0);
69
printf("Error creating socket, error: %i!\n",errno);
73
mysock.sa_family=AF_UNIX;
74
strcpy(mysock.sa_data,saddr);
76
if (bind(s,&mysock,3+sizeof(saddr))==-1) {
77
printf("Error binding socket to file, error %i!\n",errno);
82
printf("Error listening, error %i!\n",errno);
88
if (child>0) runparent(child);
89
else if (child==0) runchild("./Bolvanka.pl");
91
cerr<<"Error forking child, error: "<<errno<<"\n";
96
sd=accept(s,&perlsock,&i);
98
printf("Error accepting connection, error: %i!\n",errno);
104
sprintf(buf,"Hello %i",i);
105
request(sd,buf,answer);
106
printf("Request: %s, Answer: %s\n",buf,answer[0] ? answer : answer+1);
107
// +1 for unknown reason??? In faq is full silence...
b'\\ No newline at end of file'