2004-04-22 08:10:48 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Danny Gasparovski.
|
2007-09-17 05:08:06 +08:00
|
|
|
*
|
2004-04-22 08:10:48 +08:00
|
|
|
* Please read the file COPYRIGHT for the
|
|
|
|
* terms and conditions of the copyright.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <slirp.h>
|
2009-06-24 20:42:29 +08:00
|
|
|
#include <libslirp.h>
|
|
|
|
|
|
|
|
#include "monitor.h"
|
2004-04-22 08:10:48 +08:00
|
|
|
|
2009-06-24 20:42:29 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR;
|
|
|
|
#endif
|
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
struct quehead {
|
|
|
|
struct quehead *qh_link;
|
|
|
|
struct quehead *qh_rlink;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void
|
2009-03-07 23:32:56 +08:00
|
|
|
insque(void *a, void *b)
|
2004-04-22 08:10:48 +08:00
|
|
|
{
|
|
|
|
register struct quehead *element = (struct quehead *) a;
|
|
|
|
register struct quehead *head = (struct quehead *) b;
|
|
|
|
element->qh_link = head->qh_link;
|
|
|
|
head->qh_link = (struct quehead *)element;
|
|
|
|
element->qh_rlink = (struct quehead *)head;
|
|
|
|
((struct quehead *)(element->qh_link))->qh_rlink
|
|
|
|
= (struct quehead *)element;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2009-03-07 23:32:56 +08:00
|
|
|
remque(void *a)
|
2004-04-22 08:10:48 +08:00
|
|
|
{
|
|
|
|
register struct quehead *element = (struct quehead *) a;
|
|
|
|
((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
|
|
|
|
((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
|
|
|
|
element->qh_rlink = NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-24 20:42:28 +08:00
|
|
|
int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec,
|
|
|
|
struct in_addr addr, int port)
|
2004-04-22 08:10:48 +08:00
|
|
|
{
|
|
|
|
struct ex_list *tmp_ptr;
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
/* First, check if the port is "bound" */
|
|
|
|
for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
|
2009-06-24 20:42:28 +08:00
|
|
|
if (port == tmp_ptr->ex_fport &&
|
|
|
|
addr.s_addr == tmp_ptr->ex_addr.s_addr)
|
|
|
|
return -1;
|
2004-04-22 08:10:48 +08:00
|
|
|
}
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
tmp_ptr = *ex_ptr;
|
|
|
|
*ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
|
|
|
|
(*ex_ptr)->ex_fport = port;
|
|
|
|
(*ex_ptr)->ex_addr = addr;
|
|
|
|
(*ex_ptr)->ex_pty = do_pty;
|
2009-01-09 03:18:21 +08:00
|
|
|
(*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
|
2004-04-22 08:10:48 +08:00
|
|
|
(*ex_ptr)->ex_next = tmp_ptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_STRERROR
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For systems with no strerror
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern int sys_nerr;
|
|
|
|
extern char *sys_errlist[];
|
|
|
|
|
|
|
|
char *
|
|
|
|
strerror(error)
|
|
|
|
int error;
|
|
|
|
{
|
|
|
|
if (error < sys_nerr)
|
|
|
|
return sys_errlist[error];
|
|
|
|
else
|
|
|
|
return "Unknown error.";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-09-06 07:10:26 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
int
|
2007-10-27 03:01:16 +08:00
|
|
|
fork_exec(struct socket *so, const char *ex, int do_pty)
|
2004-09-06 07:10:26 +08:00
|
|
|
{
|
|
|
|
/* not implemented */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
/*
|
|
|
|
* XXX This is ugly
|
|
|
|
* We create and bind a socket, then fork off to another
|
|
|
|
* process, which connects to this socket, after which we
|
|
|
|
* exec the wanted program. If something (strange) happens,
|
|
|
|
* the accept() call could block us forever.
|
2007-09-17 05:08:06 +08:00
|
|
|
*
|
2004-04-22 08:10:48 +08:00
|
|
|
* do_pty = 0 Fork/exec inetd style
|
|
|
|
* do_pty = 1 Fork/exec using slirp.telnetd
|
|
|
|
* do_ptr = 2 Fork/exec using pty
|
|
|
|
*/
|
|
|
|
int
|
2007-10-27 03:01:16 +08:00
|
|
|
fork_exec(struct socket *so, const char *ex, int do_pty)
|
2004-04-22 08:10:48 +08:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct sockaddr_in addr;
|
2008-05-10 09:49:53 +08:00
|
|
|
socklen_t addrlen = sizeof(addr);
|
2004-04-22 08:10:48 +08:00
|
|
|
int opt;
|
2007-10-27 03:01:16 +08:00
|
|
|
int master = -1;
|
2008-09-14 14:45:34 +08:00
|
|
|
const char *argv[256];
|
2004-04-22 08:10:48 +08:00
|
|
|
/* don't want to clobber the original */
|
|
|
|
char *bptr;
|
2007-10-27 03:01:16 +08:00
|
|
|
const char *curarg;
|
2004-12-12 19:45:10 +08:00
|
|
|
int c, i, ret;
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
DEBUG_CALL("fork_exec");
|
|
|
|
DEBUG_ARG("so = %lx", (long)so);
|
|
|
|
DEBUG_ARG("ex = %lx", (long)ex);
|
|
|
|
DEBUG_ARG("do_pty = %lx", (long)do_pty);
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
if (do_pty == 2) {
|
2007-11-13 09:56:12 +08:00
|
|
|
return 0;
|
2004-04-22 08:10:48 +08:00
|
|
|
} else {
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = 0;
|
|
|
|
addr.sin_addr.s_addr = INADDR_ANY;
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2009-12-02 19:24:42 +08:00
|
|
|
if ((s = qemu_socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
|
2004-04-22 08:10:48 +08:00
|
|
|
bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
|
|
|
|
listen(s, 1) < 0) {
|
|
|
|
lprint("Error: inet socket: %s\n", strerror(errno));
|
2004-07-13 06:33:07 +08:00
|
|
|
closesocket(s);
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
switch(fork()) {
|
|
|
|
case -1:
|
|
|
|
lprint("Error: fork failed: %s\n", strerror(errno));
|
|
|
|
close(s);
|
|
|
|
if (do_pty == 2)
|
|
|
|
close(master);
|
|
|
|
return 0;
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
case 0:
|
|
|
|
/* Set the DISPLAY */
|
|
|
|
if (do_pty == 2) {
|
|
|
|
(void) close(master);
|
|
|
|
#ifdef TIOCSCTTY /* XXXXX */
|
|
|
|
(void) setsid();
|
|
|
|
ioctl(s, TIOCSCTTY, (char *)NULL);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
getsockname(s, (struct sockaddr *)&addr, &addrlen);
|
|
|
|
close(s);
|
|
|
|
/*
|
|
|
|
* Connect to the socket
|
|
|
|
* XXX If any of these fail, we're in trouble!
|
|
|
|
*/
|
2009-12-02 19:24:42 +08:00
|
|
|
s = qemu_socket(AF_INET, SOCK_STREAM, 0);
|
2004-04-22 08:10:48 +08:00
|
|
|
addr.sin_addr = loopback_addr;
|
2004-12-12 19:45:10 +08:00
|
|
|
do {
|
|
|
|
ret = connect(s, (struct sockaddr *)&addr, addrlen);
|
|
|
|
} while (ret < 0 && errno == EINTR);
|
2004-04-22 08:10:48 +08:00
|
|
|
}
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
dup2(s, 0);
|
|
|
|
dup2(s, 1);
|
|
|
|
dup2(s, 2);
|
2007-10-27 03:01:16 +08:00
|
|
|
for (s = getdtablesize() - 1; s >= 3; s--)
|
2004-04-22 08:10:48 +08:00
|
|
|
close(s);
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
i = 0;
|
don't dereference NULL after failed strdup
Most of these are obvious NULL-deref bug fixes, for example,
the ones in these files:
block/curl.c
net.c
slirp/misc.c
and the first one in block/vvfat.c.
The others in block/vvfat.c may not lead to an immediate segfault, but I
traced the two schedule_rename(..., strdup(path)) uses, and a failed
strdup would appear to trigger this assertion in handle_renames_and_mkdirs:
assert(commit->path);
The conversion to use qemu_strdup in envlist_to_environ is not technically
needed, but does avoid a theoretical leak in the caller when strdup fails
for one value, but later succeeds in allocating another buffer(plausible,
if one string length is much larger than the others). The caller does
not know the length of the returned list, and as such can only free
pointers until it hits the first NULL. If there are non-NULL pointers
beyond the first, their buffers would be leaked. This one is admittedly
far-fetched.
The two in linux-user/main.c are worth fixing to ensure that an
OOM error is diagnosed up front, rather than letting it provoke some
harder-to-diagnose secondary error, in case of exec failure, or worse, in
case the exec succeeds but with an invalid list of command line options.
However, considering how unlikely it is to encounter a failed strdup early
in main, this isn't a big deal. Note that adding the required uses of
qemu_strdup here and in envlist.c induce link failures because qemu_strdup
is not currently in any library they're linked with. So for now, I've
omitted those changes, as well as the fixes in target-i386/helper.c
and target-sparc/helper.c.
If you'd like to see the above discussion (or anything else)
in the commit log, just let me know and I'll be happy to adjust.
>From 9af42864fd1ea666bd25e2cecfdfae74c20aa8c7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Mon, 8 Feb 2010 18:29:29 +0100
Subject: [PATCH] don't dereference NULL after failed strdup
Handle failing strdup by replacing each use with qemu_strdup,
so as not to dereference NULL or trigger a failing assertion.
* block/curl.c (curl_open): s/\bstrdup\b/qemu_strdup/
* block/vvfat.c (init_directories): Likewise.
(get_cluster_count_for_direntry, check_directory_consistency): Likewise.
* net.c (parse_host_src_port): Likewise.
* slirp/misc.c (fork_exec): Likewise.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-09 02:28:38 +08:00
|
|
|
bptr = qemu_strdup(ex); /* No need to free() this */
|
2004-04-22 08:10:48 +08:00
|
|
|
if (do_pty == 1) {
|
|
|
|
/* Setup "slirp.telnetd -x" */
|
|
|
|
argv[i++] = "slirp.telnetd";
|
|
|
|
argv[i++] = "-x";
|
|
|
|
argv[i++] = bptr;
|
|
|
|
} else
|
|
|
|
do {
|
|
|
|
/* Change the string into argv[] */
|
|
|
|
curarg = bptr;
|
|
|
|
while (*bptr != ' ' && *bptr != (char)0)
|
|
|
|
bptr++;
|
|
|
|
c = *bptr;
|
|
|
|
*bptr++ = (char)0;
|
|
|
|
argv[i++] = strdup(curarg);
|
|
|
|
} while (c);
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2009-03-07 23:32:56 +08:00
|
|
|
argv[i] = NULL;
|
2008-09-14 14:45:34 +08:00
|
|
|
execvp(argv[0], (char **)argv);
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
/* Ooops, failed, let's tell the user why */
|
2009-12-26 02:19:18 +08:00
|
|
|
fprintf(stderr, "Error: execvp of %s failed: %s\n",
|
|
|
|
argv[0], strerror(errno));
|
2004-04-22 08:10:48 +08:00
|
|
|
close(0); close(1); close(2); /* XXX */
|
|
|
|
exit(1);
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
default:
|
|
|
|
if (do_pty == 2) {
|
|
|
|
close(s);
|
|
|
|
so->s = master;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* XXX this could block us...
|
|
|
|
* XXX Should set a timer here, and if accept() doesn't
|
|
|
|
* return after X seconds, declare it a failure
|
|
|
|
* The only reason this will block forever is if socket()
|
|
|
|
* of connect() fail in the child process
|
|
|
|
*/
|
2004-12-12 19:45:10 +08:00
|
|
|
do {
|
|
|
|
so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
|
|
|
|
} while (so->s < 0 && errno == EINTR);
|
|
|
|
closesocket(s);
|
2004-04-22 08:10:48 +08:00
|
|
|
opt = 1;
|
|
|
|
setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
|
|
|
|
opt = 1;
|
|
|
|
setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
|
|
|
|
}
|
|
|
|
fd_nonblock(so->s);
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
/* Append the telnet options now */
|
2009-03-07 23:32:56 +08:00
|
|
|
if (so->so_m != NULL && do_pty == 1) {
|
2004-04-22 08:10:48 +08:00
|
|
|
sbappend(so, so->so_m);
|
2009-03-07 23:32:56 +08:00
|
|
|
so->so_m = NULL;
|
2004-04-22 08:10:48 +08:00
|
|
|
}
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRDUP
|
|
|
|
char *
|
|
|
|
strdup(str)
|
|
|
|
const char *str;
|
|
|
|
{
|
|
|
|
char *bptr;
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
bptr = (char *)malloc(strlen(str)+1);
|
|
|
|
strcpy(bptr, str);
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
return bptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-03-06 07:01:23 +08:00
|
|
|
#include "monitor.h"
|
2007-10-31 07:19:52 +08:00
|
|
|
|
2007-10-27 02:42:59 +08:00
|
|
|
void lprint(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2010-02-18 18:41:55 +08:00
|
|
|
monitor_vprintf(default_mon, format, args);
|
2007-10-27 02:42:59 +08:00
|
|
|
va_end(args);
|
|
|
|
}
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
#ifdef BAD_SPRINTF
|
|
|
|
|
|
|
|
#undef vsprintf
|
|
|
|
#undef sprintf
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some BSD-derived systems have a sprintf which returns char *
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
vsprintf_len(string, format, args)
|
|
|
|
char *string;
|
|
|
|
const char *format;
|
|
|
|
va_list args;
|
|
|
|
{
|
|
|
|
vsprintf(string, format, args);
|
|
|
|
return strlen(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
#ifdef __STDC__
|
|
|
|
sprintf_len(char *string, const char *format, ...)
|
|
|
|
#else
|
|
|
|
sprintf_len(va_alist) va_dcl
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
#ifdef __STDC__
|
|
|
|
va_start(args, format);
|
|
|
|
#else
|
|
|
|
char *string;
|
|
|
|
char *format;
|
|
|
|
va_start(args);
|
|
|
|
string = va_arg(args, char *);
|
|
|
|
format = va_arg(args, char *);
|
|
|
|
#endif
|
|
|
|
vsprintf(string, format, args);
|
|
|
|
return strlen(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2009-03-07 23:32:56 +08:00
|
|
|
u_sleep(int usec)
|
2004-04-22 08:10:48 +08:00
|
|
|
{
|
|
|
|
struct timeval t;
|
|
|
|
fd_set fdset;
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
FD_ZERO(&fdset);
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
t.tv_sec = 0;
|
|
|
|
t.tv_usec = usec * 1000;
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
select(0, &fdset, &fdset, &fdset, &t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set fd blocking and non-blocking
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2009-03-07 23:32:56 +08:00
|
|
|
fd_nonblock(int fd)
|
2004-04-22 08:10:48 +08:00
|
|
|
{
|
|
|
|
#ifdef FIONBIO
|
2009-04-06 02:03:31 +08:00
|
|
|
#ifdef _WIN32
|
2009-06-13 16:44:31 +08:00
|
|
|
unsigned long opt = 1;
|
2009-04-06 02:03:31 +08:00
|
|
|
#else
|
|
|
|
int opt = 1;
|
|
|
|
#endif
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-07-13 06:33:07 +08:00
|
|
|
ioctlsocket(fd, FIONBIO, &opt);
|
2004-04-22 08:10:48 +08:00
|
|
|
#else
|
|
|
|
int opt;
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
opt = fcntl(fd, F_GETFL, 0);
|
|
|
|
opt |= O_NONBLOCK;
|
|
|
|
fcntl(fd, F_SETFL, opt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-07 23:32:56 +08:00
|
|
|
fd_block(int fd)
|
2004-04-22 08:10:48 +08:00
|
|
|
{
|
|
|
|
#ifdef FIONBIO
|
2009-06-13 16:44:31 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
unsigned long opt = 0;
|
|
|
|
#else
|
2004-04-22 08:10:48 +08:00
|
|
|
int opt = 0;
|
2009-06-13 16:44:31 +08:00
|
|
|
#endif
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-07-13 06:33:07 +08:00
|
|
|
ioctlsocket(fd, FIONBIO, &opt);
|
2004-04-22 08:10:48 +08:00
|
|
|
#else
|
|
|
|
int opt;
|
2007-09-17 05:08:06 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
opt = fcntl(fd, F_GETFL, 0);
|
|
|
|
opt &= ~O_NONBLOCK;
|
|
|
|
fcntl(fd, F_SETFL, opt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
void slirp_connection_info(Slirp *slirp, Monitor *mon)
|
2009-06-24 20:42:29 +08:00
|
|
|
{
|
|
|
|
const char * const tcpstates[] = {
|
|
|
|
[TCPS_CLOSED] = "CLOSED",
|
|
|
|
[TCPS_LISTEN] = "LISTEN",
|
|
|
|
[TCPS_SYN_SENT] = "SYN_SENT",
|
|
|
|
[TCPS_SYN_RECEIVED] = "SYN_RCVD",
|
|
|
|
[TCPS_ESTABLISHED] = "ESTABLISHED",
|
|
|
|
[TCPS_CLOSE_WAIT] = "CLOSE_WAIT",
|
|
|
|
[TCPS_FIN_WAIT_1] = "FIN_WAIT_1",
|
|
|
|
[TCPS_CLOSING] = "CLOSING",
|
|
|
|
[TCPS_LAST_ACK] = "LAST_ACK",
|
|
|
|
[TCPS_FIN_WAIT_2] = "FIN_WAIT_2",
|
|
|
|
[TCPS_TIME_WAIT] = "TIME_WAIT",
|
|
|
|
};
|
|
|
|
struct in_addr dst_addr;
|
|
|
|
struct sockaddr_in src;
|
|
|
|
socklen_t src_len;
|
|
|
|
uint16_t dst_port;
|
|
|
|
struct socket *so;
|
|
|
|
const char *state;
|
|
|
|
char buf[20];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
monitor_printf(mon, " Protocol[State] FD Source Address Port "
|
|
|
|
"Dest. Address Port RecvQ SendQ\n");
|
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so->so_next) {
|
2009-06-24 20:42:29 +08:00
|
|
|
if (so->so_state & SS_HOSTFWD) {
|
|
|
|
state = "HOST_FORWARD";
|
|
|
|
} else if (so->so_tcpcb) {
|
|
|
|
state = tcpstates[so->so_tcpcb->t_state];
|
|
|
|
} else {
|
|
|
|
state = "NONE";
|
|
|
|
}
|
|
|
|
if (so->so_state & (SS_HOSTFWD | SS_INCOMING)) {
|
|
|
|
src_len = sizeof(src);
|
|
|
|
getsockname(so->s, (struct sockaddr *)&src, &src_len);
|
|
|
|
dst_addr = so->so_laddr;
|
|
|
|
dst_port = so->so_lport;
|
|
|
|
} else {
|
|
|
|
src.sin_addr = so->so_laddr;
|
|
|
|
src.sin_port = so->so_lport;
|
|
|
|
dst_addr = so->so_faddr;
|
|
|
|
dst_port = so->so_fport;
|
|
|
|
}
|
|
|
|
n = snprintf(buf, sizeof(buf), " TCP[%s]", state);
|
|
|
|
memset(&buf[n], ' ', 19 - n);
|
|
|
|
buf[19] = 0;
|
|
|
|
monitor_printf(mon, "%s %3d %15s %5d ", buf, so->s,
|
|
|
|
src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*",
|
|
|
|
ntohs(src.sin_port));
|
|
|
|
monitor_printf(mon, "%15s %5d %5d %5d\n",
|
|
|
|
inet_ntoa(dst_addr), ntohs(dst_port),
|
|
|
|
so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
|
|
|
}
|
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
for (so = slirp->udb.so_next; so != &slirp->udb; so = so->so_next) {
|
2009-06-24 20:42:29 +08:00
|
|
|
if (so->so_state & SS_HOSTFWD) {
|
|
|
|
n = snprintf(buf, sizeof(buf), " UDP[HOST_FORWARD]");
|
|
|
|
src_len = sizeof(src);
|
|
|
|
getsockname(so->s, (struct sockaddr *)&src, &src_len);
|
|
|
|
dst_addr = so->so_laddr;
|
|
|
|
dst_port = so->so_lport;
|
|
|
|
} else {
|
|
|
|
n = snprintf(buf, sizeof(buf), " UDP[%d sec]",
|
|
|
|
(so->so_expire - curtime) / 1000);
|
|
|
|
src.sin_addr = so->so_laddr;
|
|
|
|
src.sin_port = so->so_lport;
|
|
|
|
dst_addr = so->so_faddr;
|
|
|
|
dst_port = so->so_fport;
|
|
|
|
}
|
|
|
|
memset(&buf[n], ' ', 19 - n);
|
|
|
|
buf[19] = 0;
|
|
|
|
monitor_printf(mon, "%s %3d %15s %5d ", buf, so->s,
|
|
|
|
src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*",
|
|
|
|
ntohs(src.sin_port));
|
|
|
|
monitor_printf(mon, "%15s %5d %5d %5d\n",
|
|
|
|
inet_ntoa(dst_addr), ntohs(dst_port),
|
|
|
|
so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
|
|
|
}
|
|
|
|
}
|