* THE SOFTWARE.
*/
#include "qemu-common.h"
+#include "qemu-char.h"
#include "slirp.h"
#include "hw/hw.h"
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;
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);
#endif
link_up = 1;
- slirp_restrict = restrict;
+ slirp_restrict = restricted;
if_init();
ip_init();
#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;
* 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;
/* 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 ||
}
}
+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)
{
if (!so)
return;
- ret = soreadbuf(so, buf, size);
+ ret = soreadbuf(so, (const char *)buf, size);
if (ret > 0)
tcp_output(sototcpcb(so));
if (!ex_ptr)
return -EINVAL;
- so->extra = ex_ptr->ex_exec;
+ so->extra = (void *)ex_ptr->ex_exec;
}
return 0;