9 #include <sys/signal.h>
10 #include "user_util.h"
11 #include "kern_util.h"
15 #include "slip_proto.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 /* XXX This is just a trivial wrapper around os_pipe */
52 static int slirp_datachan(int *mfd, int *sfd)
56 err = os_pipe(fds, 1, 1);
58 printk("slirp_datachan: Failed to open pipe, err = %d\n", -err);
67 static int slirp_open(void *data)
69 struct slirp_data *pri = data;
70 int sfd, mfd, pid, err;
72 err = slirp_datachan(&mfd, &sfd);
76 pid = slirp_tramp(pri->argw.argv, sfd);
79 printk("slirp_tramp failed - errno = %d\n", -pid);
94 static void slirp_close(int fd, void *data)
96 struct slirp_data *pri = data;
100 os_close_file(pri->slave);
105 printk("slirp_close: no child process to shut down\n");
110 if(kill(pri->pid, SIGHUP)<0) {
111 printk("slirp_close: sending hangup to %d failed (%d)\n",
116 CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG));
118 printk("slirp_close: waitpid returned %d\n", errno);
123 printk("slirp_close: process %d has not exited\n");
130 int slirp_user_read(int fd, void *buf, int len, struct slirp_data *pri)
132 int i, n, size, start;
136 while(i < pri->more) {
137 size = slip_unesc(pri->ibuf[i++],
138 pri->ibuf,&pri->pos,&pri->esc);
140 memcpy(buf, pri->ibuf, size);
141 memmove(pri->ibuf, &pri->ibuf[i], pri->more-i);
142 pri->more=pri->more-i;
149 n = net_read(fd, &pri->ibuf[pri->pos], sizeof(pri->ibuf) - pri->pos);
150 if(n <= 0) return(n);
153 for(i = 0; i < n; i++){
154 size = slip_unesc(pri->ibuf[start + i],
155 pri->ibuf,&pri->pos,&pri->esc);
157 memcpy(buf, pri->ibuf, size);
158 memmove(pri->ibuf, &pri->ibuf[start+i+1], n-(i+1));
166 int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
170 actual = slip_esc(buf, pri->obuf, len);
171 n = net_write(fd, pri->obuf, actual);
176 static int slirp_set_mtu(int mtu, void *data)
181 struct net_user_info slirp_user_info = {
182 .init = slirp_user_init,
184 .close = slirp_close,
186 .set_mtu = slirp_set_mtu,
188 .delete_address = NULL,
189 .max_packet = BUF_SIZE
193 * Overrides for Emacs so that we follow Linus's tabbing style.
194 * Emacs will notice this stuff at the end of the file and automatically
195 * adjust the settings for this buffer only. This must remain at the end
197 * ---------------------------------------------------------------------------
199 * c-file-style: "linux"