diff options
Diffstat (limited to 'fs/cifs/netmisc.c')
-rw-r--r-- | fs/cifs/netmisc.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c index 32d6baa0a54f..00e6e357ae88 100644 --- a/fs/cifs/netmisc.c +++ b/fs/cifs/netmisc.c | |||
@@ -133,10 +133,12 @@ static const struct smb_to_posix_error mapping_table_ERRHRD[] = { | |||
133 | {0, 0} | 133 | {0, 0} |
134 | }; | 134 | }; |
135 | 135 | ||
136 | /* Convert string containing dotted ip address to binary form */ | 136 | /* |
137 | /* returns 0 if invalid address */ | 137 | * Convert a string containing text IPv4 or IPv6 address to binary form. |
138 | 138 | * | |
139 | int | 139 | * Returns 0 on failure. |
140 | */ | ||
141 | static int | ||
140 | cifs_inet_pton(const int address_family, const char *cp, void *dst) | 142 | cifs_inet_pton(const int address_family, const char *cp, void *dst) |
141 | { | 143 | { |
142 | int ret = 0; | 144 | int ret = 0; |
@@ -153,6 +155,30 @@ cifs_inet_pton(const int address_family, const char *cp, void *dst) | |||
153 | return ret; | 155 | return ret; |
154 | } | 156 | } |
155 | 157 | ||
158 | /* | ||
159 | * Try to convert a string to an IPv4 address and then attempt to convert | ||
160 | * it to an IPv6 address if that fails. Set the family field if either | ||
161 | * succeeds. | ||
162 | * | ||
163 | * Returns 0 on failure. | ||
164 | */ | ||
165 | int | ||
166 | cifs_convert_address(char *src, void *dst) | ||
167 | { | ||
168 | struct sockaddr_in *s4 = (struct sockaddr_in *) dst; | ||
169 | struct sockaddr_in6 *s6 = (Struct sockaddr_in6 *) dst; | ||
170 | |||
171 | if (cifs_inet_pton(AF_INET, src, &s4->sin_addr.s_addr)) { | ||
172 | s4->sin_family = AF_INET; | ||
173 | return 1; | ||
174 | } else if (cifs_inet_pton(AF_INET6, src, &s6->sin6_addr.s6_addr)) { | ||
175 | s6->sin6_family = AF_INET6; | ||
176 | return 1; | ||
177 | } | ||
178 | |||
179 | return 0; | ||
180 | } | ||
181 | |||
156 | /***************************************************************************** | 182 | /***************************************************************************** |
157 | convert a NT status code to a dos class/code | 183 | convert a NT status code to a dos class/code |
158 | *****************************************************************************/ | 184 | *****************************************************************************/ |