2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL.
10 #include "kern_constants.h"
16 static int slirp_user_init(void *data
, void *dev
)
18 struct slirp_data
*pri
= data
;
24 struct slirp_pre_exec_data
{
29 static void slirp_pre_exec(void *arg
)
31 struct slirp_pre_exec_data
*data
= arg
;
33 if (data
->stdin
!= -1)
35 if (data
->stdout
!= -1)
36 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
);
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(UM_KERN_ERR
"slirp_tramp failed - errno = %d\n", -err
);
79 static void slirp_close(int fd
, void *data
)
81 struct slirp_data
*pri
= data
;
90 printk(UM_KERN_ERR
"slirp_close: no child process to shut "
96 if (kill(pri
->pid
, SIGHUP
)<0) {
97 printk(UM_KERN_ERR
"slirp_close: sending hangup to %d failed "
98 "(%d)\n", pri
->pid
, errno
);
102 CATCH_EINTR(err
= waitpid(pri
->pid
, &status
, WNOHANG
));
104 printk(UM_KERN_ERR
"slirp_close: waitpid returned %d\n", errno
);
109 printk(UM_KERN_ERR
"slirp_close: process %d has not exited\n",
117 int slirp_user_read(int fd
, void *buf
, int len
, struct slirp_data
*pri
)
119 return slip_proto_read(fd
, buf
, len
, &pri
->slip
);
122 int slirp_user_write(int fd
, void *buf
, int len
, struct slirp_data
*pri
)
124 return slip_proto_write(fd
, buf
, len
, &pri
->slip
);
127 const struct net_user_info slirp_user_info
= {
128 .init
= slirp_user_init
,
130 .close
= slirp_close
,
133 .delete_address
= NULL
,
135 .max_packet
= BUF_SIZE
,