[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC 3/4] slirp: add helpers for ipv6 hostfwd man
From: |
Samuel Thibault |
Subject: |
Re: [Qemu-devel] [PATCH RFC 3/4] slirp: add helpers for ipv6 hostfwd manipulation |
Date: |
Sat, 27 Oct 2018 13:23:26 +0200 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
Hello,
Maxim Samoylov, le ven. 26 oct. 2018 03:03:42 +0300, a ecrit:
> +int slirp_remove_ipv6_hostfwd(Slirp *slirp, int is_udp,
> + struct in6_addr host_addr, int host_port)
Similarly, we'd rather share the code than duplicate it :)
Better put the existing slirp_remove_hostfwd code into a
slirp_remove_x_hostfwd(Slirp *slirp, int is_udp, struct sockaddr *addr)
by replacing the explicit ipv4 comparison with a call to a helper
which compares two struct sockaddr (starting with the so_family field,
then testing fields depending the family, and you can put it in
slirp/socket.h)
and then slirp_remove_hostfwd can be rewritten as putting its
parameters into a sockaddr_in and colling slirp_remove_x_hostfwd, and
slirp_remove_ipv6_hostfwd implemented similarly for ipv6.
> +int slirp_add_ipv6_hostfwd(Slirp *slirp, int is_udp,
> + struct in6_addr host_addr, int host_port,
> + struct in6_addr guest_addr, int guest_port)
> +{
> + if (is_udp) {
> + if (!udp6_listen(slirp, host_addr, htons(host_port),
> + guest_addr, htons(guest_port), SS_HOSTFWD))
> + return -1;
> + } else {
> + if (!tcp6_listen(slirp, host_addr, htons(host_port),
> + guest_addr, htons(guest_port), SS_HOSTFWD))
> + return -1;
> + }
> +
> + return 0;
> +}
That one can remains so :)
Samuel