9 #include <sys/signal.h>
10 #include "user_util.h"
11 #include "kern_util.h"
15 #include "slip_common.h"
19 void slirp_user_init(void *data, void *dev)
21 struct slirp_data *pri = data;
26 struct slirp_pre_exec_data {
31 static void slirp_pre_exec(void *arg)
33 struct slirp_pre_exec_data *data = arg;
35 if(data->stdin != -1) dup2(data->stdin, 0);
36 if(data->stdout != -1) dup2(data->stdout, 1);
39 static int slirp_tramp(char **argv, int fd)
41 struct slirp_pre_exec_data pe_data;
46 pid = run_helper(slirp_pre_exec, &pe_data, argv, NULL);
51 static int slirp_open(void *data)
53 struct slirp_data *pri = data;
56 err = os_pipe(fds, 1, 1);
60 err = slirp_tramp(pri->argw.argv, fds[1]);
62 printk("slirp_tramp failed - errno = %d\n", -err);
74 os_close_file(fds[0]);
75 os_close_file(fds[1]);
79 static void slirp_close(int fd, void *data)
81 struct slirp_data *pri = data;
85 os_close_file(pri->slave);
90 printk("slirp_close: no child process to shut down\n");
95 if(kill(pri->pid, SIGHUP)<0) {
96 printk("slirp_close: sending hangup to %d failed (%d)\n",
101 CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG));
103 printk("slirp_close: waitpid returned %d\n", errno);
108 printk("slirp_close: process %d has not exited\n");
115 int slirp_user_read(int fd, void *buf, int len, struct slirp_data *pri)
117 return slip_proto_read(fd, buf, len, &pri->slip);
120 int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
122 return slip_proto_write(fd, buf, len, &pri->slip);
125 static int slirp_set_mtu(int mtu, void *data)
130 struct net_user_info slirp_user_info = {
131 .init = slirp_user_init,
133 .close = slirp_close,
135 .set_mtu = slirp_set_mtu,
137 .delete_address = NULL,
138 .max_packet = BUF_SIZE