9 #include <sys/signal.h>
10 #include "kern_util.h"
14 #include "slip_common.h"
17 static int slirp_user_init(void *data, void *dev)
19 struct slirp_data *pri = data;
25 struct slirp_pre_exec_data {
30 static void slirp_pre_exec(void *arg)
32 struct slirp_pre_exec_data *data = arg;
34 if(data->stdin != -1) dup2(data->stdin, 0);
35 if(data->stdout != -1) dup2(data->stdout, 1);
38 static int slirp_tramp(char **argv, int fd)
40 struct slirp_pre_exec_data pe_data;
45 pid = run_helper(slirp_pre_exec, &pe_data, argv);
50 static int slirp_open(void *data)
52 struct slirp_data *pri = data;
55 err = os_pipe(fds, 1, 1);
59 err = slirp_tramp(pri->argw.argv, fds[1]);
61 printk("slirp_tramp failed - errno = %d\n", -err);
73 os_close_file(fds[0]);
74 os_close_file(fds[1]);
78 static void slirp_close(int fd, void *data)
80 struct slirp_data *pri = data;
84 os_close_file(pri->slave);
89 printk("slirp_close: no child process to shut down\n");
94 if(kill(pri->pid, SIGHUP)<0) {
95 printk("slirp_close: sending hangup to %d failed (%d)\n",
100 CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG));
102 printk("slirp_close: waitpid returned %d\n", errno);
107 printk("slirp_close: process %d has not exited\n", pri->pid);
114 int slirp_user_read(int fd, void *buf, int len, struct slirp_data *pri)
116 return slip_proto_read(fd, buf, len, &pri->slip);
119 int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
121 return slip_proto_write(fd, buf, len, &pri->slip);
124 static int slirp_set_mtu(int mtu, void *data)
129 const struct net_user_info slirp_user_info = {
130 .init = slirp_user_init,
132 .close = slirp_close,
134 .set_mtu = slirp_set_mtu,
136 .delete_address = NULL,
137 .max_packet = BUF_SIZE