10 #include <sys/signal.h>
11 #include "user_util.h"
12 #include "kern_util.h"
16 #include "slip_proto.h"
20 void slirp_user_init(void *data, void *dev)
22 struct slirp_data *pri = data;
27 struct slirp_pre_exec_data {
32 static void slirp_pre_exec(void *arg)
34 struct slirp_pre_exec_data *data = arg;
36 if(data->stdin != -1) dup2(data->stdin, 0);
37 if(data->stdout != -1) dup2(data->stdout, 1);
40 static int slirp_tramp(char **argv, int fd)
42 struct slirp_pre_exec_data pe_data;
47 pid = run_helper(slirp_pre_exec, &pe_data, argv, NULL);
52 static int slirp_datachan(int *mfd, int *sfd)
56 err = os_pipe(fds, 1, 1);
58 printk("slirp_datachan: Failed to open pipe, errno = %d\n",
68 static int slirp_open(void *data)
70 struct slirp_data *pri = data;
71 int sfd, mfd, pid, err;
73 err = slirp_datachan(&mfd, &sfd);
77 pid = slirp_tramp(pri->argw.argv, sfd);
80 printk("slirp_tramp failed - errno = %d\n", pid);
95 static void slirp_close(int fd, void *data)
97 struct slirp_data *pri = data;
106 printk("slirp_close: no child process to shut down\n");
111 if(kill(pri->pid, SIGHUP)<0) {
112 printk("slirp_close: sending hangup to %d failed (%d)\n",
117 err = waitpid(pri->pid, &status, WNOHANG);
119 printk("slirp_close: waitpid returned %d\n", errno);
124 printk("slirp_close: process %d has not exited\n");
131 int slirp_user_read(int fd, void *buf, int len, struct slirp_data *pri)
133 int i, n, size, start;
137 while(i < pri->more) {
138 size = slip_unesc(pri->ibuf[i++],
139 pri->ibuf,&pri->pos,&pri->esc);
141 memcpy(buf, pri->ibuf, size);
142 memmove(pri->ibuf, &pri->ibuf[i], pri->more-i);
143 pri->more=pri->more-i;
150 n = net_read(fd, &pri->ibuf[pri->pos], sizeof(pri->ibuf) - pri->pos);
151 if(n <= 0) return(n);
154 for(i = 0; i < n; i++){
155 size = slip_unesc(pri->ibuf[start + i],
156 pri->ibuf,&pri->pos,&pri->esc);
158 memcpy(buf, pri->ibuf, size);
159 memmove(pri->ibuf, &pri->ibuf[start+i+1], n-(i+1));
167 int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
171 actual = slip_esc(buf, pri->obuf, len);
172 n = net_write(fd, pri->obuf, actual);
177 static int slirp_set_mtu(int mtu, void *data)
182 struct net_user_info slirp_user_info = {
183 .init = slirp_user_init,
185 .close = slirp_close,
187 .set_mtu = slirp_set_mtu,
189 .delete_address = NULL,
190 .max_packet = BUF_SIZE
194 * Overrides for Emacs so that we follow Linus's tabbing style.
195 * Emacs will notice this stuff at the end of the file and automatically
196 * adjust the settings for this buffer only. This must remain at the end
198 * ---------------------------------------------------------------------------
200 * c-file-style: "linux"