]> git.proxmox.com Git - mirror_qemu.git/blobdiff - slirp/misc.c
Use #include "..." for our own headers, <...> for others
[mirror_qemu.git] / slirp / misc.c
index 0308a62fac1750de87323e7cd5f60012bf8f1270..88e9d94197a6ae28fabc78918c72b65200858c54 100644 (file)
@@ -5,20 +5,17 @@
  * terms and conditions of the copyright.
  */
 
-#include <slirp.h>
-#include <libslirp.h>
-
-#include "monitor.h"
+#include "qemu/osdep.h"
+#include "slirp.h"
+#include "libslirp.h"
+#include "monitor/monitor.h"
+#include "qemu/error-report.h"
+#include "qemu/main-loop.h"
 
 #ifdef DEBUG
 int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR;
 #endif
 
-struct quehead {
-       struct quehead *qh_link;
-       struct quehead *qh_rlink;
-};
-
 inline void
 insque(void *a, void *b)
 {
@@ -53,36 +50,15 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec,
        }
 
        tmp_ptr = *ex_ptr;
-       *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
+       *ex_ptr = g_new(struct ex_list, 1);
        (*ex_ptr)->ex_fport = port;
        (*ex_ptr)->ex_addr = addr;
        (*ex_ptr)->ex_pty = do_pty;
-       (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
+       (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : g_strdup(exec);
        (*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
-
 
 #ifdef _WIN32
 
@@ -121,9 +97,9 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
        pid_t pid;
 
        DEBUG_CALL("fork_exec");
-       DEBUG_ARG("so = %lx", (long)so);
-       DEBUG_ARG("ex = %lx", (long)ex);
-       DEBUG_ARG("do_pty = %lx", (long)do_pty);
+       DEBUG_ARG("so = %p", so);
+       DEBUG_ARG("ex = %p", ex);
+       DEBUG_ARG("do_pty = %x", do_pty);
 
        if (do_pty == 2) {
                 return 0;
@@ -135,7 +111,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
                if ((s = qemu_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));
+                       error_report("Error: inet socket: %s", strerror(errno));
                        closesocket(s);
 
                        return 0;
@@ -145,7 +121,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
        pid = fork();
        switch(pid) {
         case -1:
-               lprint("Error: fork failed: %s\n", strerror(errno));
+               error_report("Error: fork failed: %s", strerror(errno));
                close(s);
                return 0;
 
@@ -186,7 +162,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
                           bptr++;
                        c = *bptr;
                        *bptr++ = (char)0;
-                       argv[i++] = strdup(curarg);
+                       argv[i++] = g_strdup(curarg);
                   } while (c);
 
                 argv[i] = NULL;
@@ -211,11 +187,10 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
                     so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
                 } while (so->s < 0 && errno == EINTR);
                 closesocket(s);
+                socket_set_fast_reuse(so->s);
                 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);
+                qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+               qemu_set_nonblock(so->s);
 
                /* Append the telnet options now */
                 if (so->so_m != NULL && do_pty == 1)  {
@@ -228,89 +203,6 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 }
 #endif
 
-#ifndef HAVE_STRDUP
-char *
-strdup(str)
-       const char *str;
-{
-       char *bptr;
-
-       bptr = (char *)malloc(strlen(str)+1);
-       strcpy(bptr, str);
-
-       return bptr;
-}
-#endif
-
-#include "monitor.h"
-
-void lprint(const char *format, ...)
-{
-    va_list args;
-
-    va_start(args, format);
-    monitor_vprintf(default_mon, format, args);
-    va_end(args);
-}
-
-void
-u_sleep(int 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);
-}
-
-/*
- * Set fd blocking and non-blocking
- */
-
-void
-fd_nonblock(int fd)
-{
-#ifdef FIONBIO
-#ifdef _WIN32
-        unsigned long opt = 1;
-#else
-        int opt = 1;
-#endif
-
-       ioctlsocket(fd, FIONBIO, &opt);
-#else
-       int opt;
-
-       opt = fcntl(fd, F_GETFL, 0);
-       opt |= O_NONBLOCK;
-       fcntl(fd, F_SETFL, opt);
-#endif
-}
-
-void
-fd_block(int fd)
-{
-#ifdef FIONBIO
-#ifdef _WIN32
-        unsigned long opt = 0;
-#else
-       int opt = 0;
-#endif
-
-       ioctlsocket(fd, FIONBIO, &opt);
-#else
-       int opt;
-
-       opt = fcntl(fd, F_GETFL, 0);
-       opt &= ~O_NONBLOCK;
-       fcntl(fd, F_SETFL, opt);
-#endif
-}
-
 void slirp_connection_info(Slirp *slirp, Monitor *mon)
 {
     const char * const tcpstates[] = {