2008-06-30 22:59:52

by Chuck Lever III

[permalink] [raw]
Subject: [PATCH 04/16] lockd: Add address family-agnostic helper for zeroing the port number

Signed-off-by: Chuck Lever <[email protected]>
---

fs/lockd/host.c | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)


diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 618c631..f87066d 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -39,6 +39,21 @@ static struct nsm_handle * nsm_find(const struct sockaddr_in *sin,
const char *hostname,
unsigned int hostname_len);

+static void nlm_clear_port(struct sockaddr *sap)
+{
+ struct sockaddr_in *sin = (struct sockaddr_in *)sap;
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
+
+ switch (sap->sa_family) {
+ case AF_INET:
+ sin->sin_port = 0;
+ break;
+ case AF_INET6:
+ sin6->sin6_port = 0;
+ break;
+ }
+}
+
static void nlm_display_address(const struct sockaddr *sap,
char *buf, const size_t len)
{
@@ -149,7 +164,7 @@ static struct nlm_host *nlm_lookup_host(int server,
}
host->h_name = nsm->sm_name;
host->h_addr = *sin;
- host->h_addr.sin_port = 0; /* ouch! */
+ nlm_clear_port((struct sockaddr *)&host->h_addr);
host->h_saddr = *ssin;
host->h_version = version;
host->h_proto = proto;