2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL.
14 static int slirp_user_init(void *data
, void *dev
)
16 struct slirp_data
*pri
= data
;
22 struct slirp_pre_exec_data
{
27 static void slirp_pre_exec(void *arg
)
29 struct slirp_pre_exec_data
*data
= arg
;
31 if (data
->stdin_fd
!= -1)
32 dup2(data
->stdin_fd
, 0);
33 if (data
->stdout_fd
!= -1)
34 dup2(data
->stdout_fd
, 1);
37 static int slirp_tramp(char **argv
, int fd
)
39 struct slirp_pre_exec_data pe_data
;
42 pe_data
.stdin_fd
= fd
;
43 pe_data
.stdout_fd
= fd
;
44 pid
= run_helper(slirp_pre_exec
, &pe_data
, argv
);
49 static int slirp_open(void *data
)
51 struct slirp_data
*pri
= data
;
54 err
= os_pipe(fds
, 1, 1);
58 err
= slirp_tramp(pri
->argw
.argv
, fds
[1]);
60 printk(UM_KERN_ERR
"slirp_tramp failed - errno = %d\n", -err
);
77 static void slirp_close(int fd
, void *data
)
79 struct slirp_data
*pri
= data
;
88 printk(UM_KERN_ERR
"slirp_close: no child process to shut "
94 if (kill(pri
->pid
, SIGHUP
)<0) {
95 printk(UM_KERN_ERR
"slirp_close: sending hangup to %d failed "
96 "(%d)\n", pri
->pid
, errno
);
99 err
= helper_wait(pri
->pid
);
106 int slirp_user_read(int fd
, void *buf
, int len
, struct slirp_data
*pri
)
108 return slip_proto_read(fd
, buf
, len
, &pri
->slip
);
111 int slirp_user_write(int fd
, void *buf
, int len
, struct slirp_data
*pri
)
113 return slip_proto_write(fd
, buf
, len
, &pri
->slip
);
116 const struct net_user_info slirp_user_info
= {
117 .init
= slirp_user_init
,
119 .close
= slirp_close
,
122 .delete_address
= NULL
,
124 .max_packet
= BUF_SIZE
,