diff options
author | Guillaume Subiron <maethor@subiron.org> | 2015-12-19 22:25:01 +0100 |
---|---|---|
committer | Jason Wang <jasowang@redhat.com> | 2016-02-04 13:22:06 +0800 |
commit | 1375f025941f059bea69900ebc285c3dcd1ab64a (patch) | |
tree | 859060ad90aa7cdaa057d0ccee97e29515b015e8 /socket.h | |
parent | 8d3e1d392086bf26b8fe903a23ad9b380cf5e5bf (diff) | |
download | slirp-1375f025941f059bea69900ebc285c3dcd1ab64a.zip slirp-1375f025941f059bea69900ebc285c3dcd1ab64a.tar.gz slirp-1375f025941f059bea69900ebc285c3dcd1ab64a.tar.bz2 |
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 'socket.h')
-rw-r--r-- | socket.h | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -94,8 +94,29 @@ struct socket { #define SS_INCOMING \ 0x2000 /* Connection was initiated by a host on the internet */ -struct socket *solookup(struct socket **, struct socket *, struct in_addr, - u_int, struct in_addr, u_int); +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 sockaddr_storage *, struct sockaddr_storage *); struct socket *socreate(Slirp *); void sofree(struct socket *); int soread(struct socket *); |