]> Git Repo - qemu.git/blobdiff - slirp/slirp.c
slirp: Reorder initialization
[qemu.git] / slirp / slirp.c
index c1361ab108d56efdd31f6a2456183bb5cde09aad..30d4ee2d2658260d3a7167450b5d392a27863593 100644 (file)
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
+#include "qemu-char.h"
 #include "slirp.h"
 #include "hw/hw.h"
 
@@ -47,9 +48,9 @@ static struct in_addr client_ipaddr;
 
 static const uint8_t zero_ethaddr[6] = { 0, 0, 0, 0, 0, 0 };
 
-char *slirp_special_ip = CTL_SPECIAL;
+const char *slirp_special_ip = CTL_SPECIAL;
 int slirp_restrict;
-int do_slowtimo;
+static int do_slowtimo;
 int link_up;
 struct timeval tt;
 FILE *lfd;
@@ -170,7 +171,7 @@ static void slirp_cleanup(void)
 static void slirp_state_save(QEMUFile *f, void *opaque);
 static int slirp_state_load(QEMUFile *f, void *opaque, int version_id);
 
-void slirp_init(int restrict, char *special_ip)
+void slirp_init(int restricted, const char *special_ip)
 {
     //    debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
 
@@ -183,7 +184,7 @@ void slirp_init(int restrict, char *special_ip)
 #endif
 
     link_up = 1;
-    slirp_restrict = restrict;
+    slirp_restrict = restricted;
 
     if_init();
     ip_init();
@@ -227,7 +228,7 @@ static void updtime(void)
 #else
 static void updtime(void)
 {
-       gettimeofday(&tt, 0);
+        gettimeofday(&tt, NULL);
 
        curtime = (u_int)tt.tv_sec * (u_int)1000;
        curtime += (u_int)tt.tv_usec / (u_int)1000;
@@ -261,7 +262,7 @@ void slirp_select_fill(int *pnfds,
                 * in the fragment queue, or there are TCP connections active
                 */
                do_slowtimo = ((tcb.so_next != &tcb) ||
-                              ((struct ipasfrag *)&ipq != (struct ipasfrag *)ipq.next));
+                (&ipq.ip_link != ipq.ip_link.next));
 
                for (so = tcb.so_next; so != &tcb; so = so_next) {
                        so_next = so->so_next;
@@ -467,7 +468,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
                            /* Connected */
                            so->so_state &= ~SS_ISFCONNECTING;
 
-                           ret = send(so->s, &ret, 0, 0);
+                           ret = send(so->s, (const void *) &ret, 0, 0);
                            if (ret < 0) {
                              /* XXXXX Must fix, zero bytes is a NOP */
                              if (errno == EAGAIN || errno == EWOULDBLOCK ||
@@ -733,6 +734,53 @@ void if_encap(const uint8_t *ip_data, int ip_data_len)
     }
 }
 
+static void _slirp_redir_loop(void (*func)(void *opaque, int is_udp,
+                                           struct in_addr *laddr, u_int lport,
+                                           struct in_addr *faddr, u_int fport),
+                              void *opaque, int is_udp)
+{
+    struct socket *head = (is_udp ? &udb : &tcb);
+    struct socket *so;
+
+    for (so = head->so_next; so != head; so = so->so_next) {
+        func(opaque, is_udp,
+             &so->so_laddr, ntohs(so->so_lport),
+             &so->so_faddr, ntohs(so->so_fport));
+    }
+}
+
+void slirp_redir_loop(void (*func)(void *opaque, int is_udp,
+                                  struct in_addr *laddr, u_int lport,
+                                  struct in_addr *faddr, u_int fport),
+                     void *opaque)
+{
+    _slirp_redir_loop(func, opaque, 0);
+    _slirp_redir_loop(func, opaque, 1);
+}
+
+/* Unlistens a redirection
+ *
+ * Return value: number of redirs removed */
+int slirp_redir_rm(int is_udp, int host_port)
+{
+    struct socket *so;
+    struct socket *head = (is_udp ? &udb : &tcb);
+    int fport = htons(host_port);
+    int n = 0;
+
+ loop_again:
+    for (so = head->so_next; so != head; so = so->so_next) {
+        if (so->so_fport == fport) {
+            close(so->s);
+            sofree(so);
+            n++;
+            goto loop_again;
+        }
+    }
+
+    return n;
+}
+
 int slirp_redir(int is_udp, int host_port,
                 struct in_addr guest_addr, int guest_port)
 {
@@ -809,7 +857,7 @@ void slirp_socket_recv(int addr_low_byte, int guest_port, const uint8_t *buf,
     if (!so)
         return;
 
-    ret = soreadbuf(so, buf, size);
+    ret = soreadbuf(so, (const char *)buf, size);
 
     if (ret > 0)
         tcp_output(sototcpcb(so));
@@ -1031,7 +1079,7 @@ static int slirp_state_load(QEMUFile *f, void *opaque, int version_id)
         if (!ex_ptr)
             return -EINVAL;
 
-        so->extra = ex_ptr->ex_exec;
+        so->extra = (void *)ex_ptr->ex_exec;
     }
 
     return 0;
This page took 0.028616 seconds and 4 git commands to generate.