1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/win/sandbox_poc/pocdll/exports.h"
6 #include "sandbox/win/sandbox_poc/pocdll/utils.h"
8 // This file contains the tests used to verify the security of the network.
10 void POCDLL_API
TestNetworkListen(HANDLE log
) {
11 HandleToFile handle2file
;
12 FILE *output
= handle2file
.Translate(log
, "w");
13 #if DONT_WANT_INTERCEPTIONS_JUST_WANT_NETWORK
16 int result
= ::WSAStartup(MAKEWORD(2, 2), &wsa_data
);
17 if (result
!= NO_ERROR
) {
18 fprintf(output
, "[ERROR] Cannot initialize winsock. Error%d\r\n", result
);
22 // Create a SOCKET for listening for
23 // incoming connection requests.
25 listen_socket
= socket(AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
26 if (listen_socket
== INVALID_SOCKET
) {
27 fprintf(output
, "[ERROR] Failed to create socket. Error %ld\r\n",
33 // The sockaddr_in structure specifies the address family,
34 // IP address, and port for the socket that is being bound.
36 service
.sin_family
= AF_INET
;
37 service
.sin_addr
.s_addr
= inet_addr("127.0.0.1");
38 service
.sin_port
= htons(88);
40 if (bind(listen_socket
, reinterpret_cast<SOCKADDR
*>(&service
),
41 sizeof(service
)) == SOCKET_ERROR
) {
42 fprintf(output
, "[BLOCKED] Bind socket on port 88. Error %ld\r\n",
44 closesocket(listen_socket
);
49 // Listen for incoming connection requests
50 // on the created socket
51 if (listen(listen_socket
, SOMAXCONN
) == SOCKET_ERROR
) {
52 fprintf(output
, "[BLOCKED] Listen socket on port 88. Error %ld\r\n",
56 fprintf(output
, "[GRANTED] Listen socket on port 88.\r\n",
62 #else // DONT_WANT_INTERCEPTIONS_JUST_WANT_NETWORK
63 // Just print out that this test is not running.
64 fprintf(output
, "[ERROR] No network tests.\r\n");
65 #endif // DONT_WANT_INTERCEPTIONS_JUST_WANT_NETWORK