~ubuntu-branches/ubuntu/trusty/haproxy/trusty-updates

« back to all changes in this revision

Viewing changes to tests/reset.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Cornet
  • Date: 2010-04-15 20:00:34 UTC
  • mfrom: (1.2.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20100415200034-mtlky4sy39tk0dfi
Tags: upstream-1.4.4
ImportĀ upstreamĀ versionĀ 1.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <unistd.h>
 
5
#include <netinet/in.h>
 
6
#include <arpa/inet.h>
 
7
#include <sys/types.h>
 
8
#include <sys/socket.h>
 
9
#include <fcntl.h>
 
10
 
 
11
int main(int argc, char **argv) {
 
12
        char *addr;
 
13
        int port;
 
14
        int sock;
 
15
        struct sockaddr_in saddr;
 
16
        const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
 
17
 
 
18
        if (argc < 4) {
 
19
                fprintf(stderr,
 
20
                        "usage : %s <addr> <port> <string>\n"
 
21
                        "        This will connect to TCP port <addr>:<port> and send string <string>\n"
 
22
                        "        then immediately reset.\n",
 
23
                        argv[0]);
 
24
                exit(1);
 
25
        }
 
26
 
 
27
        addr = argv[1];
 
28
        port = atoi(argv[2]);
 
29
 
 
30
        sock = socket(AF_INET, SOCK_STREAM, 0);
 
31
        bzero(&saddr, sizeof(saddr));
 
32
        saddr.sin_addr.s_addr = inet_addr(addr);
 
33
        saddr.sin_port = htons(port);
 
34
        saddr.sin_family = AF_INET;
 
35
 
 
36
        if (connect(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
 
37
                perror("connect");
 
38
                exit(1);
 
39
        }
 
40
 
 
41
        send(sock, argv[3], strlen(argv[3]), MSG_DONTWAIT | MSG_NOSIGNAL);
 
42
        setsockopt(sock, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger));
 
43
        close(sock);
 
44
        exit(0);
 
45
}