Re: [PATCH 2/5] nfs-utils: store the address given in the upcall for later use

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Apr 6, 2009, at 12:31 PM, Jeff Layton wrote:
On Mon, 6 Apr 2009 11:35:50 -0400
Chuck Lever <chuck.lever@xxxxxxxxxx> wrote:
On Apr 5, 2009, at 9:43 AM, Jeff Layton wrote:
+ */
+static int
+addrstr_to_sockaddr(struct sockaddr *sa, const char *addr, const
int port)
+{
+	struct sockaddr_in	*s4 = (struct sockaddr_in *) sa;
+
+	if (inet_pton(AF_INET, addr, &s4->sin_addr)) {
+		s4->sin_family = AF_INET;
+		s4->sin_port = htons(port);
+	} else {
+		printerr(0, "ERROR: unable to convert %s to address\n", addr);
+		return 0;
+	}

I've handled these with a switch statement, as you do later in
populate_port().  It's merely a question about consistent coding
style, but any reason not to take that approach here?


Yes. switch statements are really only suitable when you have a simple
value to compare against. We're not comparing the address family here
because it's not yet known. We have to try and convert this opaque
string to an address first.

In the last patch, I add an "else if" where we try to convert it to an
ipv6 addr, but we can't really do "try this and if that fails then try
this" in the context of a switch.

Just avoid doing the "break;" if inet_ntop(AF_INET6) fails. Just a suggestion. Some might feel that's too clever.

In other places I try to use switches where it's suitable...

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux