OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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. |
| 4 |
| 5 #include <stdio.h> |
| 6 #include <stdlib.h> |
| 7 #include <string.h> |
| 8 |
| 9 #include <netinet/in.h> |
| 10 #include <unistd.h> |
| 11 |
| 12 #include "web2socket.h" |
| 13 |
| 14 static void bailout() { |
| 15 fprintf(stderr, |
| 16 "Options:\n" |
| 17 " -p port\tSpecifies port (in 1-65535 range) to listen. Mandatory.\n" |
| 18 " -L\tListens loopback network interface.\n"); |
| 19 exit(1); |
| 20 } |
| 21 |
| 22 int main(int ac, char *av[]) { |
| 23 int c; |
| 24 int port = 0; |
| 25 bool loopback = false; |
| 26 if (ac <= 0) |
| 27 bailout(); |
| 28 while ((c = getopt(ac, av, "p:L")) != -1) { |
| 29 switch(c) { |
| 30 case 'p': { |
| 31 port = atoi(optarg); |
| 32 break; |
| 33 } |
| 34 case 'L': { |
| 35 loopback = true; |
| 36 break; |
| 37 } |
| 38 default: { |
| 39 bailout(); |
| 40 } |
| 41 } |
| 42 } |
| 43 if (port < 1 || port >= 1 << 16) |
| 44 bailout(); |
| 45 |
| 46 struct sockaddr_in sa; |
| 47 memset(&sa, 0, sizeof(sa)); |
| 48 sa.sin_family = AF_INET; |
| 49 sa.sin_port = htons(port); |
| 50 sa.sin_addr.s_addr = loopback ? htonl(INADDR_LOOPBACK) : htonl(INADDR_ANY); |
| 51 |
| 52 RunWeb2SocketServer(std::string(), |
| 53 static_cast<sockaddr*>(static_cast<void*>(&sa)), |
| 54 sizeof(sa)); |
| 55 return 1; |
| 56 } |
OLD | NEW |