/*-1* Copyright (c) 2015 George V. Neville-Neil2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include <err.h>27#include <errno.h>28#include <stdio.h>29#include <stdlib.h>30#include <strings.h>31#include <sysexits.h>32#include <unistd.h>3334#include <sys/socket.h>35#include <sys/types.h>36#include <netinet/in.h>3738#define PORT 6969 /* Default port */39#define RECV_LIMIT 64 /* When do we move listen to 0? */4041void usage(void);4243void usage()44{45err(EX_USAGE, "connect [-p port]\n");46}4748int main(int argc, char **argv)49{5051int ch, cli_sock, count = 0;52int port = PORT;53struct sockaddr_in remoteaddr;5455while ((ch = getopt(argc, argv, "p:")) != -1) {56switch (ch) {57case 'p':58port = atoi(optarg);59break;60case 'h':61default:62usage();63}64}6566bzero(&remoteaddr, sizeof(remoteaddr));67remoteaddr.sin_len = sizeof(remoteaddr);68remoteaddr.sin_family = AF_INET;69remoteaddr.sin_port = htons(port);70remoteaddr.sin_addr.s_addr = INADDR_ANY;7172cli_sock = socket(AF_INET, SOCK_STREAM, 0);7374while ((cli_sock = connect(cli_sock, (struct sockaddr *)&remoteaddr,75sizeof(remoteaddr))) >= 0) {76count++;77close(cli_sock);78cli_sock = socket(AF_INET, SOCK_STREAM, 0);79}8081printf("Exiting at %d with errno %d\n", count, errno);8283}848586