aboutsummaryrefslogtreecommitdiff
path: root/slirp/socket.h
diff options
context:
space:
mode:
authorGuillaume Subiron <maethor@subiron.org>2015-12-19 22:25:01 +0100
committerJason Wang <jasowang@redhat.com>2016-02-04 13:22:06 +0800
commit8a87f121ca82fbb34877ec843dfc50b327baef9d (patch)
tree2e13bcac23ec476d279b31e742711b264ad4ca6d /slirp/socket.h
parenta5fd24aa6d0f26aeb9f15b24daa2d68427631c40 (diff)
downloadqemu-arm-8a87f121ca82fbb34877ec843dfc50b327baef9d.tar.gz
slirp: Add sockaddr_equal, make solookup family-agnostic
This patch makes solookup() compatible with varying address families, by using a new sockaddr_equal() function that compares two sockaddr_storage. This prepares for IPv6 support. Signed-off-by: Guillaume Subiron <maethor@subiron.org> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'slirp/socket.h')
-rw-r--r--slirp/socket.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/slirp/socket.h b/slirp/socket.h
index 1c8c24c16b..c4afc9494f 100644
--- a/slirp/socket.h
+++ b/slirp/socket.h
@@ -87,8 +87,30 @@ struct socket {
#define SS_HOSTFWD 0x1000 /* Socket describes host->guest forwarding */
#define SS_INCOMING 0x2000 /* Connection was initiated by a host on the internet */
+static inline int sockaddr_equal(struct sockaddr_storage *a,
+ struct sockaddr_storage *b)
+{
+ if (a->ss_family != b->ss_family) {
+ return 0;
+ }
+
+ switch (a->ss_family) {
+ case AF_INET:
+ {
+ struct sockaddr_in *a4 = (struct sockaddr_in *) a;
+ struct sockaddr_in *b4 = (struct sockaddr_in *) b;
+ return a4->sin_addr.s_addr == b4->sin_addr.s_addr
+ && a4->sin_port == b4->sin_port;
+ }
+ default:
+ g_assert_not_reached();
+ }
+
+ return 0;
+}
+
struct socket *solookup(struct socket **, struct socket *,
- struct in_addr, u_int, struct in_addr, u_int);
+ struct sockaddr_storage *, struct sockaddr_storage *);
struct socket *socreate(Slirp *);
void sofree(struct socket *);
int soread(struct socket *);