33 #include <openvas/misc/network.h> 34 #include <openvas/misc/internal_com.h> 56 static struct host *hosts = NULL;
57 static int g_soc = -1;
58 static int g_max_hosts = 15;
63 forward (
int in,
int out)
70 if (internal_recv (in, &buf, &bufsz, &type) < 0)
73 if (type & INTERNAL_COMM_MSG_TYPE_CTRL)
75 errno = type & ~INTERNAL_COMM_MSG_TYPE_CTRL;
78 else if ((type & INTERNAL_COMM_MSG_TYPE_DATA) == 0)
80 log_write (
"hosts.c:forward(): bad msg type (%d)\n", type);
92 e = nsend (out, buf + n, len - n, 0);
93 if (e < 0 && errno == EINTR)
108 forward_all (
int in,
int out)
110 while (forward (in, out) == 0);
117 host_rm (
struct host *h)
120 waitpid (h->
pid, NULL, WNOHANG);
121 forward_all (h->
soc, g_soc);
142 struct host *h = hosts;
145 for (num = 0; h != NULL; num++, h = h->
next);
154 hosts_get (
char *
name)
156 struct host *h = hosts;
171 g_max_hosts = max_hosts;
182 while (hosts_num () >= g_max_hosts)
190 h = g_malloc0 (
sizeof (
struct host));
219 hosts_stop_host (
struct host *h)
225 kill (h->
pid, SIGUSR1);
237 hosts_stop_host (
host);
245 hosts_read_data (
void)
250 struct host *h = hosts;
254 waitpid (-1, NULL, WNOHANG);
262 if (kill (h->
pid, 0) < 0)
271 FD_SET (h->
soc, &rd);
282 e = select (max + 1, &rd, NULL, NULL, &tv);
284 if (e < 0 && errno == EINTR)
296 if (FD_ISSET (h->
soc, &rd) != 0)
299 && (forward (h->
soc, g_soc) == 0))
312 hosts_read_client (
struct arglist *globals)
329 e = select (g_soc + 1, &rd, NULL, NULL, &tv);
330 if (e < 0 && errno == EINTR)
336 if (e > 0 && FD_ISSET (g_soc, &rd) != 0)
341 result = recv_line (g_soc, buf,
sizeof (buf) - 1);
359 if (hosts_read_client (globals) < 0)
362 log_write (
"Client abruptly closed the communication");
void hosts_stop_all(void)
void log_write(const char *str,...)
Write into the logfile / syslog.
int hosts_new(struct arglist *globals, char *name, int soc)
int hosts_init(int soc, int max_hosts)
Host information, implemented as doubly linked list.
int ntp_parse_input(struct arglist *globals, char *input)
Parses the input sent by the client before the NEW_ATTACK message.
int hosts_set_pid(char *name, pid_t pid)
int hosts_read(struct arglist *globals)
Returns -1 if client asked to stop all tests or connection was lost or error. 0 otherwise.