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

Side by Side Diff: runtime/bin/socket_linux.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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return buffer; 169 return buffer;
170 } 170 }
171 171
172 172
173 intptr_t ServerSocket::CreateBindListen(const char* host, 173 intptr_t ServerSocket::CreateBindListen(const char* host,
174 intptr_t port, 174 intptr_t port,
175 intptr_t backlog) { 175 intptr_t backlog) {
176 intptr_t fd; 176 intptr_t fd;
177 struct sockaddr_in server_address; 177 struct sockaddr_in server_address;
178 178
179 in_addr_t s_addr = TEMP_FAILURE_RETRY(inet_addr(host));
180 if (s_addr == INADDR_NONE) {
181 return -5;
182 }
183
179 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); 184 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0));
180 if (fd < 0) { 185 if (fd < 0) {
181 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno)); 186 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno));
182 return -1; 187 return -1;
183 } 188 }
184 189
185 int optval = 1; 190 int optval = 1;
186 TEMP_FAILURE_RETRY( 191 TEMP_FAILURE_RETRY(
187 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); 192 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
188 193
189 server_address.sin_family = AF_INET; 194 server_address.sin_family = AF_INET;
190 server_address.sin_port = htons(port); 195 server_address.sin_port = htons(port);
191 server_address.sin_addr.s_addr = inet_addr(host); 196 server_address.sin_addr.s_addr = s_addr;
192 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); 197 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero));
193 198
194 if (TEMP_FAILURE_RETRY( 199 if (TEMP_FAILURE_RETRY(
195 bind(fd, 200 bind(fd,
196 reinterpret_cast<struct sockaddr *>(&server_address), 201 reinterpret_cast<struct sockaddr *>(&server_address),
197 sizeof(server_address))) < 0) { 202 sizeof(server_address))) < 0) {
198 TEMP_FAILURE_RETRY(close(fd)); 203 TEMP_FAILURE_RETRY(close(fd));
199 fprintf(stderr, "Error Bind: %s\n", strerror(errno)); 204 fprintf(stderr, "Error Bind: %s\n", strerror(errno));
200 return -1; 205 return -1;
201 } 206 }
(...skipping 29 matching lines...) Expand all
231 // error. We got woken up from the poll on the listening socket, 236 // error. We got woken up from the poll on the listening socket,
232 // but there is no connection ready to be accepted. 237 // but there is no connection ready to be accepted.
233 ASSERT(kTemporaryFailure != -1); 238 ASSERT(kTemporaryFailure != -1);
234 socket = kTemporaryFailure; 239 socket = kTemporaryFailure;
235 } 240 }
236 } else { 241 } else {
237 FDUtils::SetNonBlocking(socket); 242 FDUtils::SetNonBlocking(socket);
238 } 243 }
239 return socket; 244 return socket;
240 } 245 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698