Skip to content

Commit afb0369

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
NLM: Add helper to handle IPv4 addresses
Clean up: introduce a helper function to generate IPv4 addresses using the same style as the IPv6 helper function we just added. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
1 parent bc99580 commit afb0369

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎fs/lockd/host.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ static void nlm_clear_port(struct sockaddr *sap)
105105
}
106106
}
107107

108+
static void nlm_display_ipv4_address(const struct sockaddr *sap, char *buf,
109+
const size_t len)
110+
{
111+
const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
112+
snprintf(buf, len, "%pI4", &sin->sin_addr.s_addr);
113+
}
114+
108115
static void nlm_display_ipv6_address(const struct sockaddr *sap, char *buf,
109116
const size_t len)
110117
{
@@ -122,11 +129,9 @@ static void nlm_display_ipv6_address(const struct sockaddr *sap, char *buf,
122129
static void nlm_display_address(const struct sockaddr *sap,
123130
char *buf, const size_t len)
124131
{
125-
const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
126-
127132
switch (sap->sa_family) {
128133
case AF_INET:
129-
snprintf(buf, len, "%pI4", &sin->sin_addr.s_addr);
134+
nlm_display_ipv4_address(sap, buf, len);
130135
break;
131136
case AF_INET6:
132137
nlm_display_ipv6_address(sap, buf, len);

0 commit comments

Comments
 (0)