aboutsummaryrefslogtreecommitdiff
path: root/slirp/misc.c
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-09-16 21:08:06 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-09-16 21:08:06 +0000
commit5fafdf24ef2c090c164d4dc89684b3f379dbdd87 (patch)
treec0654ee63b6dac76d98b427e92ef16850a90c652 /slirp/misc.c
parentbd494f4cbd4187dda8cc8f4739763f24a31a4c8b (diff)
find -type f | xargs sed -i 's/[\t ]$//g' # on most files
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3173 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'slirp/misc.c')
-rw-r--r--slirp/misc.c172
1 files changed, 86 insertions, 86 deletions
diff --git a/slirp/misc.c b/slirp/misc.c
index 2c42fd15b0..db4444ef3a 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1995 Danny Gasparovski.
- *
+ *
* Please read the file COPYRIGHT for the
* terms and conditions of the copyright.
*/
@@ -31,7 +31,7 @@ show_x(buff, inso)
if (x_display)
lprint("X Redir: Redirecting to display %d\r\n", x_display);
}
-
+
return CFG_OK;
}
@@ -47,7 +47,7 @@ redir_x(inaddr, start_port, display, screen)
int screen;
{
int i;
-
+
if (x_port >= 0) {
lprint("X Redir: X already being redirected.\r\n");
show_x(0, 0);
@@ -89,7 +89,7 @@ getouraddr()
{
char buff[256];
struct hostent *he = NULL;
-
+
if (gethostname(buff,256) == 0)
he = gethostbyname(buff);
if (he)
@@ -172,13 +172,13 @@ add_exec(ex_ptr, do_pty, exec, addr, port)
int port;
{
struct ex_list *tmp_ptr;
-
+
/* First, check if the port is "bound" */
for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
if (port == tmp_ptr->ex_fport && addr == tmp_ptr->ex_addr)
return -1;
}
-
+
tmp_ptr = *ex_ptr;
*ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
(*ex_ptr)->ex_fport = port;
@@ -233,7 +233,7 @@ slirp_openpty(amaster, aslave)
#ifdef HAVE_GRANTPT
char *ptr;
-
+
if ((master = open("/dev/ptmx", O_RDWR)) < 0 ||
grantpt(master) < 0 ||
unlockpt(master) < 0 ||
@@ -241,7 +241,7 @@ slirp_openpty(amaster, aslave)
close(master);
return -1;
}
-
+
if ((slave = open(ptr, O_RDWR)) < 0 ||
ioctl(slave, I_PUSH, "ptem") < 0 ||
ioctl(slave, I_PUSH, "ldterm") < 0 ||
@@ -250,16 +250,16 @@ slirp_openpty(amaster, aslave)
close(slave);
return -1;
}
-
+
*amaster = master;
*aslave = slave;
return 0;
-
+
#else
-
+
static char line[] = "/dev/ptyXX";
register const char *cp1, *cp2;
-
+
for (cp1 = "pqrsPQRS"; *cp1; cp1++) {
line[8] = *cp1;
for (cp2 = "0123456789abcdefghijklmnopqrstuv"; *cp2; cp2++) {
@@ -296,7 +296,7 @@ slirp_openpty(amaster, aslave)
* process, which connects to this socket, after which we
* exec the wanted program. If something (strange) happens,
* the accept() call could block us forever.
- *
+ *
* do_pty = 0 Fork/exec inetd style
* do_pty = 1 Fork/exec using slirp.telnetd
* do_ptr = 2 Fork/exec using pty
@@ -320,12 +320,12 @@ fork_exec(so, ex, do_pty)
char *bptr;
char *curarg;
int c, i, ret;
-
+
DEBUG_CALL("fork_exec");
DEBUG_ARG("so = %lx", (long)so);
DEBUG_ARG("ex = %lx", (long)ex);
DEBUG_ARG("do_pty = %lx", (long)do_pty);
-
+
if (do_pty == 2) {
if (slirp_openpty(&master, &s) == -1) {
lprint("Error: openpty failed: %s\n", strerror(errno));
@@ -335,17 +335,17 @@ fork_exec(so, ex, do_pty)
addr.sin_family = AF_INET;
addr.sin_port = 0;
addr.sin_addr.s_addr = INADDR_ANY;
-
+
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
listen(s, 1) < 0) {
lprint("Error: inet socket: %s\n", strerror(errno));
closesocket(s);
-
+
return 0;
}
}
-
+
switch(fork()) {
case -1:
lprint("Error: fork failed: %s\n", strerror(errno));
@@ -353,7 +353,7 @@ fork_exec(so, ex, do_pty)
if (do_pty == 2)
close(master);
return 0;
-
+
case 0:
/* Set the DISPLAY */
if (do_pty == 2) {
@@ -375,7 +375,7 @@ fork_exec(so, ex, do_pty)
ret = connect(s, (struct sockaddr *)&addr, addrlen);
} while (ret < 0 && errno == EINTR);
}
-
+
#if 0
if (x_port >= 0) {
#ifdef HAVE_SETENV
@@ -386,13 +386,13 @@ fork_exec(so, ex, do_pty)
putenv(buff);
#endif
}
-#endif
+#endif
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
for (s = 3; s <= 255; s++)
close(s);
-
+
i = 0;
bptr = strdup(ex); /* No need to free() this */
if (do_pty == 1) {
@@ -410,21 +410,21 @@ fork_exec(so, ex, do_pty)
*bptr++ = (char)0;
argv[i++] = strdup(curarg);
} while (c);
-
+
argv[i] = 0;
execvp(argv[0], argv);
-
+
/* Ooops, failed, let's tell the user why */
{
char buff[256];
-
- sprintf(buff, "Error: execvp of %s failed: %s\n",
+
+ sprintf(buff, "Error: execvp of %s failed: %s\n",
argv[0], strerror(errno));
write(2, buff, strlen(buff)+1);
}
close(0); close(1); close(2); /* XXX */
exit(1);
-
+
default:
if (do_pty == 2) {
close(s);
@@ -447,13 +447,13 @@ fork_exec(so, ex, do_pty)
setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
}
fd_nonblock(so->s);
-
+
/* Append the telnet options now */
if (so->so_m != 0 && do_pty == 1) {
sbappend(so, so->so_m);
so->so_m = 0;
}
-
+
return 1;
}
}
@@ -465,10 +465,10 @@ strdup(str)
const char *str;
{
char *bptr;
-
+
bptr = (char *)malloc(strlen(str)+1);
strcpy(bptr, str);
-
+
return bptr;
}
#endif
@@ -484,7 +484,7 @@ snooze_hup(num)
#endif
struct sockaddr_in sock_in;
char buff[256];
-
+
ret = -1;
if (slirp_socket_passwd) {
s = socket(AF_INET, SOCK_STREAM, 0);
@@ -514,29 +514,29 @@ snooze_hup(num)
#endif
slirp_exit(0);
}
-
-
+
+
void
snooze()
{
sigset_t s;
int i;
-
+
/* Don't need our data anymore */
/* XXX This makes SunOS barf */
/* brk(0); */
-
+
/* Close all fd's */
for (i = 255; i >= 0; i--)
close(i);
-
+
signal(SIGQUIT, slirp_exit);
signal(SIGHUP, snooze_hup);
sigemptyset(&s);
-
+
/* Wait for any signal */
sigsuspend(&s);
-
+
/* Just in case ... */
exit(255);
}
@@ -549,16 +549,16 @@ relay(s)
int n;
fd_set readfds;
struct ttys *ttyp;
-
+
/* Don't need our data anymore */
/* XXX This makes SunOS barf */
/* brk(0); */
-
+
signal(SIGQUIT, slirp_exit);
signal(SIGHUP, slirp_exit);
signal(SIGINT, slirp_exit);
signal(SIGTERM, slirp_exit);
-
+
/* Fudge to get term_raw and term_restore to work */
if (NULL == (ttyp = tty_attach (0, slirp_tty))) {
lprint ("Error: tty_attach failed in misc.c:relay()\r\n");
@@ -567,18 +567,18 @@ relay(s)
ttyp->fd = 0;
ttyp->flags |= TTY_CTTY;
term_raw(ttyp);
-
+
while (1) {
FD_ZERO(&readfds);
-
+
FD_SET(0, &readfds);
FD_SET(s, &readfds);
-
+
n = select(s+1, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0);
-
+
if (n <= 0)
slirp_exit(0);
-
+
if (FD_ISSET(0, &readfds)) {
n = read(0, buf, 8192);
if (n <= 0)
@@ -587,7 +587,7 @@ relay(s)
if (n <= 0)
slirp_exit(0);
}
-
+
if (FD_ISSET(s, &readfds)) {
n = read(s, buf, 8192);
if (n <= 0)
@@ -597,7 +597,7 @@ relay(s)
slirp_exit(0);
}
}
-
+
/* Just in case.... */
exit(1);
}
@@ -614,7 +614,7 @@ lprint(va_alist) va_dcl
#endif
{
va_list args;
-
+
#ifdef __STDC__
va_start(args, format);
#else
@@ -631,33 +631,33 @@ lprint(va_alist) va_dcl
int deltaw = lprint_sb->sb_wptr - lprint_sb->sb_data;
int deltar = lprint_sb->sb_rptr - lprint_sb->sb_data;
int deltap = lprint_ptr - lprint_sb->sb_data;
-
+
lprint_sb->sb_data = (char *)realloc(lprint_sb->sb_data,
lprint_sb->sb_datalen + TCP_SNDSPACE);
-
+
/* Adjust all values */
lprint_sb->sb_wptr = lprint_sb->sb_data + deltaw;
lprint_sb->sb_rptr = lprint_sb->sb_data + deltar;
lprint_ptr = lprint_sb->sb_data + deltap;
-
+
lprint_sb->sb_datalen += TCP_SNDSPACE;
}
}
-#endif
+#endif
if (lprint_print)
lprint_ptr += (*lprint_print)(*lprint_arg, format, args);
-
+
/* Check if they want output to be logged to file as well */
if (lfd) {
- /*
+ /*
* Remove \r's
* otherwise you'll get ^M all over the file
*/
int len = strlen(format);
char *bptr1, *bptr2;
-
+
bptr1 = bptr2 = strdup(format);
-
+
while (len--) {
if (*bptr1 == '\r')
memcpy(bptr1, bptr1+1, len+1);
@@ -680,12 +680,12 @@ add_emu(buff)
char *buff3 = buff4;
struct emu_t *emup;
struct socket *so;
-
+
if (sscanf(buff, "%256s %256s", buff2, buff1) != 2) {
lprint("Error: Bad arguments\r\n");
return;
}
-
+
if (sscanf(buff1, "%d:%d", &lport, &fport) != 2) {
lport = 0;
if (sscanf(buff1, "%d", &fport) != 1) {
@@ -693,7 +693,7 @@ add_emu(buff)
return;
}
}
-
+
if (sscanf(buff2, "%128[^:]:%128s", buff1, buff3) != 2) {
buff3 = 0;
if (sscanf(buff2, "%256s", buff1) != 1) {
@@ -701,7 +701,7 @@ add_emu(buff)
return;
}
}
-
+
if (buff3) {
if (strcmp(buff3, "lowdelay") == 0)
tos = IPTOS_LOWDELAY;
@@ -712,7 +712,7 @@ add_emu(buff)
return;
}
}
-
+
if (strcmp(buff1, "ftp") == 0)
emu = EMU_FTP;
else if (strcmp(buff1, "irc") == 0)
@@ -723,7 +723,7 @@ add_emu(buff)
lprint("Error: Unknown service\r\n");
return;
}
-
+
/* First, check that it isn't already emulated */
for (emup = tcpemu; emup; emup = emup->next) {
if (emup->lport == lport && emup->fport == fport) {
@@ -731,7 +731,7 @@ add_emu(buff)
return;
}
}
-
+
/* link it */
emup = (struct emu_t *)malloc(sizeof (struct emu_t));
emup->lport = (u_int16_t)lport;
@@ -740,7 +740,7 @@ add_emu(buff)
emup->emu = emu;
emup->next = tcpemu;
tcpemu = emup;
-
+
/* And finally, mark all current sessions, if any, as being emulated */
for (so = tcb.so_next; so != &tcb; so = so->so_next) {
if ((lport && lport == ntohs(so->so_lport)) ||
@@ -751,7 +751,7 @@ add_emu(buff)
so->so_iptos = tos;
}
}
-
+
lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport);
}
@@ -803,12 +803,12 @@ u_sleep(usec)
{
struct timeval t;
fd_set fdset;
-
+
FD_ZERO(&fdset);
-
+
t.tv_sec = 0;
t.tv_usec = usec * 1000;
-
+
select(0, &fdset, &fdset, &fdset, &t);
}
@@ -822,11 +822,11 @@ fd_nonblock(fd)
{
#ifdef FIONBIO
int opt = 1;
-
+
ioctlsocket(fd, FIONBIO, &opt);
#else
int opt;
-
+
opt = fcntl(fd, F_GETFL, 0);
opt |= O_NONBLOCK;
fcntl(fd, F_SETFL, opt);
@@ -839,11 +839,11 @@ fd_block(fd)
{
#ifdef FIONBIO
int opt = 0;
-
+
ioctlsocket(fd, FIONBIO, &opt);
#else
int opt;
-
+
opt = fcntl(fd, F_GETFL, 0);
opt &= ~O_NONBLOCK;
fcntl(fd, F_SETFL, opt);
@@ -867,10 +867,10 @@ rsh_exec(so,ns, user, host, args)
int fd0[2];
int s;
char buff[256];
-
+
DEBUG_CALL("rsh_exec");
DEBUG_ARG("so = %lx", (long)so);
-
+
if (pipe(fd)<0) {
lprint("Error: pipe failed: %s\n", strerror(errno));
return 0;
@@ -891,7 +891,7 @@ rsh_exec(so,ns, user, host, args)
return 0;
}
#endif
-
+
switch(fork()) {
case -1:
lprint("Error: fork failed: %s\n", strerror(errno));
@@ -900,11 +900,11 @@ rsh_exec(so,ns, user, host, args)
close(fd0[0]);
close(fd0[1]);
return 0;
-
+
case 0:
close(fd[0]);
close(fd0[0]);
-
+
/* Set the DISPLAY */
if (x_port >= 0) {
#ifdef HAVE_SETENV
@@ -915,29 +915,29 @@ rsh_exec(so,ns, user, host, args)
putenv(buff);
#endif
}
-
+
dup2(fd0[1], 0);
dup2(fd0[1], 1);
dup2(fd[1], 2);
for (s = 3; s <= 255; s++)
close(s);
-
+
execlp("rsh","rsh","-l", user, host, args, NULL);
-
+
/* Ooops, failed, let's tell the user why */
-
- sprintf(buff, "Error: execlp of %s failed: %s\n",
+
+ sprintf(buff, "Error: execlp of %s failed: %s\n",
"rsh", strerror(errno));
write(2, buff, strlen(buff)+1);
close(0); close(1); close(2); /* XXX */
exit(1);
-
+
default:
close(fd[1]);
close(fd0[1]);
ns->s=fd[0];
so->s=fd0[0];
-
+
return 1;
}
}