Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright 2009, Oracle.  All rights reserved.
  4 *
  5 * Convert socket addresses to presentation addresses and universal
  6 * addresses, and vice versa.
  7 *
  8 * Universal addresses are introduced by RFC 1833 and further refined by
  9 * recent RFCs describing NFSv4.  The universal address format is part
 10 * of the external (network) interface provided by rpcbind version 3
 11 * and 4, and by NFSv4.  Such an address is a string containing a
 12 * presentation format IP address followed by a port number in
 13 * "hibyte.lobyte" format.
 14 *
 15 * IPv6 addresses can also include a scope ID, typically denoted by
 16 * a '%' followed by a device name or a non-negative integer.  Refer to
 17 * RFC 4291, Section 2.2 for details on IPv6 presentation formats.
 18 */
 19
 20#include <net/ipv6.h>
 21#include <linux/sunrpc/addr.h>
 22#include <linux/sunrpc/msg_prot.h>
 23#include <linux/slab.h>
 24#include <linux/export.h>
 25
 26#if IS_ENABLED(CONFIG_IPV6)
 27
 28static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
 29				  char *buf, const int buflen)
 30{
 31	const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
 32	const struct in6_addr *addr = &sin6->sin6_addr;
 33
 34	/*
 35	 * RFC 4291, Section 2.2.2
 36	 *
 37	 * Shorthanded ANY address
 38	 */
 39	if (ipv6_addr_any(addr))
 40		return snprintf(buf, buflen, "::");
 41
 42	/*
 43	 * RFC 4291, Section 2.2.2
 44	 *
 45	 * Shorthanded loopback address
 46	 */
 47	if (ipv6_addr_loopback(addr))
 48		return snprintf(buf, buflen, "::1");
 49
 50	/*
 51	 * RFC 4291, Section 2.2.3
 52	 *
 53	 * Special presentation address format for mapped v4
 54	 * addresses.
 55	 */
 56	if (ipv6_addr_v4mapped(addr))
 57		return snprintf(buf, buflen, "::ffff:%pI4",
 58					&addr->s6_addr32[3]);
 59
 60	/*
 61	 * RFC 4291, Section 2.2.1
 62	 */
 63	return snprintf(buf, buflen, "%pI6c", addr);
 64}
 65
 66static size_t rpc_ntop6(const struct sockaddr *sap,
 67			char *buf, const size_t buflen)
 68{
 69	const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
 70	char scopebuf[IPV6_SCOPE_ID_LEN];
 71	size_t len;
 72	int rc;
 73
 74	len = rpc_ntop6_noscopeid(sap, buf, buflen);
 75	if (unlikely(len == 0))
 76		return len;
 77
 78	if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
 79		return len;
 80	if (sin6->sin6_scope_id == 0)
 81		return len;
 82
 83	rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u",
 84			IPV6_SCOPE_DELIMITER, sin6->sin6_scope_id);
 85	if (unlikely((size_t)rc >= sizeof(scopebuf)))
 86		return 0;
 87
 88	len += rc;
 89	if (unlikely(len >= buflen))
 90		return 0;
 91
 92	strcat(buf, scopebuf);
 93	return len;
 94}
 95
 96#else	/* !IS_ENABLED(CONFIG_IPV6) */
 97
 98static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
 99				  char *buf, const int buflen)
100{
101	return 0;
102}
103
104static size_t rpc_ntop6(const struct sockaddr *sap,
105			char *buf, const size_t buflen)
106{
107	return 0;
108}
109
110#endif	/* !IS_ENABLED(CONFIG_IPV6) */
111
112static int rpc_ntop4(const struct sockaddr *sap,
113		     char *buf, const size_t buflen)
114{
115	const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
116
117	return snprintf(buf, buflen, "%pI4", &sin->sin_addr);
118}
119
120/**
121 * rpc_ntop - construct a presentation address in @buf
122 * @sap: socket address
123 * @buf: construction area
124 * @buflen: size of @buf, in bytes
125 *
126 * Plants a %NUL-terminated string in @buf and returns the length
127 * of the string, excluding the %NUL.  Otherwise zero is returned.
128 */
129size_t rpc_ntop(const struct sockaddr *sap, char *buf, const size_t buflen)
130{
131	switch (sap->sa_family) {
132	case AF_INET:
133		return rpc_ntop4(sap, buf, buflen);
134	case AF_INET6:
135		return rpc_ntop6(sap, buf, buflen);
136	}
137
138	return 0;
139}
140EXPORT_SYMBOL_GPL(rpc_ntop);
141
142static size_t rpc_pton4(const char *buf, const size_t buflen,
143			struct sockaddr *sap, const size_t salen)
144{
145	struct sockaddr_in *sin = (struct sockaddr_in *)sap;
146	u8 *addr = (u8 *)&sin->sin_addr.s_addr;
147
148	if (buflen > INET_ADDRSTRLEN || salen < sizeof(struct sockaddr_in))
149		return 0;
150
151	memset(sap, 0, sizeof(struct sockaddr_in));
152
153	if (in4_pton(buf, buflen, addr, '\0', NULL) == 0)
154		return 0;
155
156	sin->sin_family = AF_INET;
157	return sizeof(struct sockaddr_in);
158}
159
160#if IS_ENABLED(CONFIG_IPV6)
161static int rpc_parse_scope_id(struct net *net, const char *buf,
162			      const size_t buflen, const char *delim,
163			      struct sockaddr_in6 *sin6)
164{
165	char *p;
166	size_t len;
167
168	if ((buf + buflen) == delim)
169		return 1;
170
171	if (*delim != IPV6_SCOPE_DELIMITER)
172		return 0;
173
174	if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
175		return 0;
176
177	len = (buf + buflen) - delim - 1;
178	p = kmemdup_nul(delim + 1, len, GFP_KERNEL);
179	if (p) {
180		u32 scope_id = 0;
181		struct net_device *dev;
182
183		dev = dev_get_by_name(net, p);
184		if (dev != NULL) {
185			scope_id = dev->ifindex;
186			dev_put(dev);
187		} else {
188			if (kstrtou32(p, 10, &scope_id) == 0) {
189				kfree(p);
190				return 0;
191			}
192		}
193
194		kfree(p);
195
196		sin6->sin6_scope_id = scope_id;
197		return 1;
198	}
199
200	return 0;
201}
202
203static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,
204			struct sockaddr *sap, const size_t salen)
205{
206	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
207	u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
208	const char *delim;
209
210	if (buflen > (INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN) ||
211	    salen < sizeof(struct sockaddr_in6))
212		return 0;
213
214	memset(sap, 0, sizeof(struct sockaddr_in6));
215
216	if (in6_pton(buf, buflen, addr, IPV6_SCOPE_DELIMITER, &delim) == 0)
217		return 0;
218
219	if (!rpc_parse_scope_id(net, buf, buflen, delim, sin6))
220		return 0;
221
222	sin6->sin6_family = AF_INET6;
223	return sizeof(struct sockaddr_in6);
224}
225#else
226static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,
227			struct sockaddr *sap, const size_t salen)
228{
229	return 0;
230}
231#endif
232
233/**
234 * rpc_pton - Construct a sockaddr in @sap
235 * @net: applicable network namespace
236 * @buf: C string containing presentation format IP address
237 * @buflen: length of presentation address in bytes
238 * @sap: buffer into which to plant socket address
239 * @salen: size of buffer in bytes
240 *
241 * Returns the size of the socket address if successful; otherwise
242 * zero is returned.
243 *
244 * Plants a socket address in @sap and returns the size of the
245 * socket address, if successful.  Returns zero if an error
246 * occurred.
247 */
248size_t rpc_pton(struct net *net, const char *buf, const size_t buflen,
249		struct sockaddr *sap, const size_t salen)
250{
251	unsigned int i;
252
253	for (i = 0; i < buflen; i++)
254		if (buf[i] == ':')
255			return rpc_pton6(net, buf, buflen, sap, salen);
256	return rpc_pton4(buf, buflen, sap, salen);
257}
258EXPORT_SYMBOL_GPL(rpc_pton);
259
260/**
261 * rpc_sockaddr2uaddr - Construct a universal address string from @sap.
262 * @sap: socket address
263 * @gfp_flags: allocation mode
264 *
265 * Returns a %NUL-terminated string in dynamically allocated memory;
266 * otherwise NULL is returned if an error occurred.  Caller must
267 * free the returned string.
268 */
269char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags)
270{
271	char portbuf[RPCBIND_MAXUADDRPLEN];
272	char addrbuf[RPCBIND_MAXUADDRLEN];
273	unsigned short port;
274
275	switch (sap->sa_family) {
276	case AF_INET:
277		if (rpc_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0)
278			return NULL;
279		port = ntohs(((struct sockaddr_in *)sap)->sin_port);
280		break;
281	case AF_INET6:
282		if (rpc_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0)
283			return NULL;
284		port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
285		break;
286	default:
287		return NULL;
288	}
289
290	if (snprintf(portbuf, sizeof(portbuf),
291		     ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf))
292		return NULL;
293
294	if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf))
295		return NULL;
296
297	return kstrdup(addrbuf, gfp_flags);
298}
299
300/**
301 * rpc_uaddr2sockaddr - convert a universal address to a socket address.
302 * @net: applicable network namespace
303 * @uaddr: C string containing universal address to convert
304 * @uaddr_len: length of universal address string
305 * @sap: buffer into which to plant socket address
306 * @salen: size of buffer
307 *
308 * @uaddr does not have to be '\0'-terminated, but kstrtou8() and
309 * rpc_pton() require proper string termination to be successful.
310 *
311 * Returns the size of the socket address if successful; otherwise
312 * zero is returned.
313 */
314size_t rpc_uaddr2sockaddr(struct net *net, const char *uaddr,
315			  const size_t uaddr_len, struct sockaddr *sap,
316			  const size_t salen)
317{
318	char *c, buf[RPCBIND_MAXUADDRLEN + sizeof('\0')];
319	u8 portlo, porthi;
320	unsigned short port;
321
322	if (uaddr_len > RPCBIND_MAXUADDRLEN)
323		return 0;
324
325	memcpy(buf, uaddr, uaddr_len);
326
327	buf[uaddr_len] = '\0';
328	c = strrchr(buf, '.');
329	if (unlikely(c == NULL))
330		return 0;
331	if (unlikely(kstrtou8(c + 1, 10, &portlo) != 0))
 
 
332		return 0;
333
334	*c = '\0';
335	c = strrchr(buf, '.');
336	if (unlikely(c == NULL))
337		return 0;
338	if (unlikely(kstrtou8(c + 1, 10, &porthi) != 0))
 
 
339		return 0;
340
341	port = (unsigned short)((porthi << 8) | portlo);
342
343	*c = '\0';
344	if (rpc_pton(net, buf, strlen(buf), sap, salen) == 0)
345		return 0;
346
347	switch (sap->sa_family) {
348	case AF_INET:
349		((struct sockaddr_in *)sap)->sin_port = htons(port);
350		return sizeof(struct sockaddr_in);
351	case AF_INET6:
352		((struct sockaddr_in6 *)sap)->sin6_port = htons(port);
353		return sizeof(struct sockaddr_in6);
354	}
355
356	return 0;
357}
358EXPORT_SYMBOL_GPL(rpc_uaddr2sockaddr);
v3.5.6
 
  1/*
  2 * Copyright 2009, Oracle.  All rights reserved.
  3 *
  4 * Convert socket addresses to presentation addresses and universal
  5 * addresses, and vice versa.
  6 *
  7 * Universal addresses are introduced by RFC 1833 and further refined by
  8 * recent RFCs describing NFSv4.  The universal address format is part
  9 * of the external (network) interface provided by rpcbind version 3
 10 * and 4, and by NFSv4.  Such an address is a string containing a
 11 * presentation format IP address followed by a port number in
 12 * "hibyte.lobyte" format.
 13 *
 14 * IPv6 addresses can also include a scope ID, typically denoted by
 15 * a '%' followed by a device name or a non-negative integer.  Refer to
 16 * RFC 4291, Section 2.2 for details on IPv6 presentation formats.
 17 */
 18
 19#include <net/ipv6.h>
 20#include <linux/sunrpc/clnt.h>
 
 21#include <linux/slab.h>
 22#include <linux/export.h>
 23
 24#if IS_ENABLED(CONFIG_IPV6)
 25
 26static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
 27				  char *buf, const int buflen)
 28{
 29	const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
 30	const struct in6_addr *addr = &sin6->sin6_addr;
 31
 32	/*
 33	 * RFC 4291, Section 2.2.2
 34	 *
 35	 * Shorthanded ANY address
 36	 */
 37	if (ipv6_addr_any(addr))
 38		return snprintf(buf, buflen, "::");
 39
 40	/*
 41	 * RFC 4291, Section 2.2.2
 42	 *
 43	 * Shorthanded loopback address
 44	 */
 45	if (ipv6_addr_loopback(addr))
 46		return snprintf(buf, buflen, "::1");
 47
 48	/*
 49	 * RFC 4291, Section 2.2.3
 50	 *
 51	 * Special presentation address format for mapped v4
 52	 * addresses.
 53	 */
 54	if (ipv6_addr_v4mapped(addr))
 55		return snprintf(buf, buflen, "::ffff:%pI4",
 56					&addr->s6_addr32[3]);
 57
 58	/*
 59	 * RFC 4291, Section 2.2.1
 60	 */
 61	return snprintf(buf, buflen, "%pI6c", addr);
 62}
 63
 64static size_t rpc_ntop6(const struct sockaddr *sap,
 65			char *buf, const size_t buflen)
 66{
 67	const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
 68	char scopebuf[IPV6_SCOPE_ID_LEN];
 69	size_t len;
 70	int rc;
 71
 72	len = rpc_ntop6_noscopeid(sap, buf, buflen);
 73	if (unlikely(len == 0))
 74		return len;
 75
 76	if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
 77		return len;
 78	if (sin6->sin6_scope_id == 0)
 79		return len;
 80
 81	rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u",
 82			IPV6_SCOPE_DELIMITER, sin6->sin6_scope_id);
 83	if (unlikely((size_t)rc > sizeof(scopebuf)))
 84		return 0;
 85
 86	len += rc;
 87	if (unlikely(len > buflen))
 88		return 0;
 89
 90	strcat(buf, scopebuf);
 91	return len;
 92}
 93
 94#else	/* !IS_ENABLED(CONFIG_IPV6) */
 95
 96static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
 97				  char *buf, const int buflen)
 98{
 99	return 0;
100}
101
102static size_t rpc_ntop6(const struct sockaddr *sap,
103			char *buf, const size_t buflen)
104{
105	return 0;
106}
107
108#endif	/* !IS_ENABLED(CONFIG_IPV6) */
109
110static int rpc_ntop4(const struct sockaddr *sap,
111		     char *buf, const size_t buflen)
112{
113	const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
114
115	return snprintf(buf, buflen, "%pI4", &sin->sin_addr);
116}
117
118/**
119 * rpc_ntop - construct a presentation address in @buf
120 * @sap: socket address
121 * @buf: construction area
122 * @buflen: size of @buf, in bytes
123 *
124 * Plants a %NUL-terminated string in @buf and returns the length
125 * of the string, excluding the %NUL.  Otherwise zero is returned.
126 */
127size_t rpc_ntop(const struct sockaddr *sap, char *buf, const size_t buflen)
128{
129	switch (sap->sa_family) {
130	case AF_INET:
131		return rpc_ntop4(sap, buf, buflen);
132	case AF_INET6:
133		return rpc_ntop6(sap, buf, buflen);
134	}
135
136	return 0;
137}
138EXPORT_SYMBOL_GPL(rpc_ntop);
139
140static size_t rpc_pton4(const char *buf, const size_t buflen,
141			struct sockaddr *sap, const size_t salen)
142{
143	struct sockaddr_in *sin = (struct sockaddr_in *)sap;
144	u8 *addr = (u8 *)&sin->sin_addr.s_addr;
145
146	if (buflen > INET_ADDRSTRLEN || salen < sizeof(struct sockaddr_in))
147		return 0;
148
149	memset(sap, 0, sizeof(struct sockaddr_in));
150
151	if (in4_pton(buf, buflen, addr, '\0', NULL) == 0)
152		return 0;
153
154	sin->sin_family = AF_INET;
155	return sizeof(struct sockaddr_in);
156}
157
158#if IS_ENABLED(CONFIG_IPV6)
159static int rpc_parse_scope_id(struct net *net, const char *buf,
160			      const size_t buflen, const char *delim,
161			      struct sockaddr_in6 *sin6)
162{
163	char *p;
164	size_t len;
165
166	if ((buf + buflen) == delim)
167		return 1;
168
169	if (*delim != IPV6_SCOPE_DELIMITER)
170		return 0;
171
172	if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
173		return 0;
174
175	len = (buf + buflen) - delim - 1;
176	p = kstrndup(delim + 1, len, GFP_KERNEL);
177	if (p) {
178		unsigned long scope_id = 0;
179		struct net_device *dev;
180
181		dev = dev_get_by_name(net, p);
182		if (dev != NULL) {
183			scope_id = dev->ifindex;
184			dev_put(dev);
185		} else {
186			if (strict_strtoul(p, 10, &scope_id) == 0) {
187				kfree(p);
188				return 0;
189			}
190		}
191
192		kfree(p);
193
194		sin6->sin6_scope_id = scope_id;
195		return 1;
196	}
197
198	return 0;
199}
200
201static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,
202			struct sockaddr *sap, const size_t salen)
203{
204	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
205	u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
206	const char *delim;
207
208	if (buflen > (INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN) ||
209	    salen < sizeof(struct sockaddr_in6))
210		return 0;
211
212	memset(sap, 0, sizeof(struct sockaddr_in6));
213
214	if (in6_pton(buf, buflen, addr, IPV6_SCOPE_DELIMITER, &delim) == 0)
215		return 0;
216
217	if (!rpc_parse_scope_id(net, buf, buflen, delim, sin6))
218		return 0;
219
220	sin6->sin6_family = AF_INET6;
221	return sizeof(struct sockaddr_in6);
222}
223#else
224static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,
225			struct sockaddr *sap, const size_t salen)
226{
227	return 0;
228}
229#endif
230
231/**
232 * rpc_pton - Construct a sockaddr in @sap
233 * @net: applicable network namespace
234 * @buf: C string containing presentation format IP address
235 * @buflen: length of presentation address in bytes
236 * @sap: buffer into which to plant socket address
237 * @salen: size of buffer in bytes
238 *
239 * Returns the size of the socket address if successful; otherwise
240 * zero is returned.
241 *
242 * Plants a socket address in @sap and returns the size of the
243 * socket address, if successful.  Returns zero if an error
244 * occurred.
245 */
246size_t rpc_pton(struct net *net, const char *buf, const size_t buflen,
247		struct sockaddr *sap, const size_t salen)
248{
249	unsigned int i;
250
251	for (i = 0; i < buflen; i++)
252		if (buf[i] == ':')
253			return rpc_pton6(net, buf, buflen, sap, salen);
254	return rpc_pton4(buf, buflen, sap, salen);
255}
256EXPORT_SYMBOL_GPL(rpc_pton);
257
258/**
259 * rpc_sockaddr2uaddr - Construct a universal address string from @sap.
260 * @sap: socket address
261 * @gfp_flags: allocation mode
262 *
263 * Returns a %NUL-terminated string in dynamically allocated memory;
264 * otherwise NULL is returned if an error occurred.  Caller must
265 * free the returned string.
266 */
267char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags)
268{
269	char portbuf[RPCBIND_MAXUADDRPLEN];
270	char addrbuf[RPCBIND_MAXUADDRLEN];
271	unsigned short port;
272
273	switch (sap->sa_family) {
274	case AF_INET:
275		if (rpc_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0)
276			return NULL;
277		port = ntohs(((struct sockaddr_in *)sap)->sin_port);
278		break;
279	case AF_INET6:
280		if (rpc_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0)
281			return NULL;
282		port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
283		break;
284	default:
285		return NULL;
286	}
287
288	if (snprintf(portbuf, sizeof(portbuf),
289		     ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf))
290		return NULL;
291
292	if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf))
293		return NULL;
294
295	return kstrdup(addrbuf, gfp_flags);
296}
297
298/**
299 * rpc_uaddr2sockaddr - convert a universal address to a socket address.
300 * @net: applicable network namespace
301 * @uaddr: C string containing universal address to convert
302 * @uaddr_len: length of universal address string
303 * @sap: buffer into which to plant socket address
304 * @salen: size of buffer
305 *
306 * @uaddr does not have to be '\0'-terminated, but strict_strtoul() and
307 * rpc_pton() require proper string termination to be successful.
308 *
309 * Returns the size of the socket address if successful; otherwise
310 * zero is returned.
311 */
312size_t rpc_uaddr2sockaddr(struct net *net, const char *uaddr,
313			  const size_t uaddr_len, struct sockaddr *sap,
314			  const size_t salen)
315{
316	char *c, buf[RPCBIND_MAXUADDRLEN + sizeof('\0')];
317	unsigned long portlo, porthi;
318	unsigned short port;
319
320	if (uaddr_len > RPCBIND_MAXUADDRLEN)
321		return 0;
322
323	memcpy(buf, uaddr, uaddr_len);
324
325	buf[uaddr_len] = '\0';
326	c = strrchr(buf, '.');
327	if (unlikely(c == NULL))
328		return 0;
329	if (unlikely(strict_strtoul(c + 1, 10, &portlo) != 0))
330		return 0;
331	if (unlikely(portlo > 255))
332		return 0;
333
334	*c = '\0';
335	c = strrchr(buf, '.');
336	if (unlikely(c == NULL))
337		return 0;
338	if (unlikely(strict_strtoul(c + 1, 10, &porthi) != 0))
339		return 0;
340	if (unlikely(porthi > 255))
341		return 0;
342
343	port = (unsigned short)((porthi << 8) | portlo);
344
345	*c = '\0';
346	if (rpc_pton(net, buf, strlen(buf), sap, salen) == 0)
347		return 0;
348
349	switch (sap->sa_family) {
350	case AF_INET:
351		((struct sockaddr_in *)sap)->sin_port = htons(port);
352		return sizeof(struct sockaddr_in);
353	case AF_INET6:
354		((struct sockaddr_in6 *)sap)->sin6_port = htons(port);
355		return sizeof(struct sockaddr_in6);
356	}
357
358	return 0;
359}
360EXPORT_SYMBOL_GPL(rpc_uaddr2sockaddr);