Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Side by Side Diff: runtime/bin/socket_android.cc

Issue 10917064: Throw an error if the ServerSocket host argument is invalid. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use in_addr_t as s_addr type. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return buffer; 170 return buffer;
171 } 171 }
172 172
173 173
174 intptr_t ServerSocket::CreateBindListen(const char* host, 174 intptr_t ServerSocket::CreateBindListen(const char* host,
175 intptr_t port, 175 intptr_t port,
176 intptr_t backlog) { 176 intptr_t backlog) {
177 intptr_t fd; 177 intptr_t fd;
178 struct sockaddr_in server_address; 178 struct sockaddr_in server_address;
179 179
180 in_addr_t s_addr = TEMP_FAILURE_RETRY(inet_addr(host));
181 if (s_addr == INADDR_NONE) {
182 return -5;
183 }
184
180 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); 185 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0));
181 if (fd < 0) { 186 if (fd < 0) {
182 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno)); 187 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno));
183 return -1; 188 return -1;
184 } 189 }
185 190
186 int optval = 1; 191 int optval = 1;
187 TEMP_FAILURE_RETRY( 192 TEMP_FAILURE_RETRY(
188 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); 193 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
189 194
190 server_address.sin_family = AF_INET; 195 server_address.sin_family = AF_INET;
191 server_address.sin_port = htons(port); 196 server_address.sin_port = htons(port);
192 server_address.sin_addr.s_addr = inet_addr(host); 197 server_address.sin_addr.s_addr = s_addr;
193 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); 198 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero));
194 199
195 if (TEMP_FAILURE_RETRY( 200 if (TEMP_FAILURE_RETRY(
196 bind(fd, 201 bind(fd,
197 reinterpret_cast<struct sockaddr *>(&server_address), 202 reinterpret_cast<struct sockaddr *>(&server_address),
198 sizeof(server_address))) < 0) { 203 sizeof(server_address))) < 0) {
199 TEMP_FAILURE_RETRY(close(fd)); 204 TEMP_FAILURE_RETRY(close(fd));
200 fprintf(stderr, "Error Bind: %s\n", strerror(errno)); 205 fprintf(stderr, "Error Bind: %s\n", strerror(errno));
201 return -1; 206 return -1;
202 } 207 }
(...skipping 29 matching lines...) Expand all
232 // error. We got woken up from the poll on the listening socket, 237 // error. We got woken up from the poll on the listening socket,
233 // but there is no connection ready to be accepted. 238 // but there is no connection ready to be accepted.
234 ASSERT(kTemporaryFailure != -1); 239 ASSERT(kTemporaryFailure != -1);
235 socket = kTemporaryFailure; 240 socket = kTemporaryFailure;
236 } 241 }
237 } else { 242 } else {
238 FDUtils::SetNonBlocking(socket); 243 FDUtils::SetNonBlocking(socket);
239 } 244 }
240 return socket; 245 return socket;
241 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698