File jabbertest-ipv6.patch of Package jabbertest
Index: testsuite/conn.c
===================================================================
--- testsuite.orig/conn.c
+++ testsuite/conn.c
@@ -23,51 +23,48 @@
* in addr
*/
-int conn_open(char *ip, char *hostname, int port)
+int conn_open(char *host, char *port)
{
- struct sockaddr_in addr;
- int sockfd;
+ int sockfd = -1;
+ struct addrinfo *res;
- /* specify our server */
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
-
- /* determine 32-bit IP address using either the specified IP
- * string or the hostname */
- if (ip == NULL && hostname != NULL)
- {
- struct hostent *entry;
-
- entry = gethostbyname(hostname);
- if (entry == NULL)
- {
- perror("gethostbyname()");
- return -1;
+ if (host != NULL) {
+ struct addrinfo hints;
+ struct addrinfo *runp;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_ADDRCONFIG;
+
+ int e = getaddrinfo(host, port, &hints, &res);
+
+ if (e != 0) {
+ printf("failure %s\n", gai_strerror(e));
+ return 1;
}
-
- addr.sin_addr.s_addr = *((unsigned long *) entry->h_addr_list[0]);
- }
- else if (ip != NULL && hostname == NULL)
- addr.sin_addr.s_addr = inet_addr(ip);
- else
- return -1;
-
- /* create a new socket */
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0)
- {
- perror("socket()");
- exit(EXIT_FAILURE);
- }
-
- /* connect to the server */
- if ((connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)) < 0))
- {
- close(sockfd);
- return -1;
+ for (runp = res; runp != NULL; runp = runp->ai_next) {
+ /* create a new socket */
+ sockfd = socket(runp->ai_family, runp->ai_socktype,
+ runp->ai_protocol);
+ if (sockfd < 0) {
+ perror("socket()");
+ continue;
+ }
+
+ /* connect to the server */
+ if ((connect(sockfd, runp->ai_addr, runp->ai_addrlen) < 0)) {
+ close(sockfd);
+ continue;
+ }
+ break; /* connection successful */
+ }
+ if (runp == NULL) {
+ perror("connection error");
+ sockfd = -1;
+ }
+ freeaddrinfo(res); /* free dynamically allocated memory */
}
- else
- return sockfd;
+ return sockfd;
}
/*
@@ -110,8 +107,9 @@ int conn_readwait(int sockfd, char *buf,
/* if sec < 0 and usec < 0 then we essentially want a blocking
* read */
- if (sec < 0 && usec < 0)
+ if (sec < 0 && usec < 0) {
return conn_read(sockfd, buf, len);
+ }
FD_ZERO(&fdset);
@@ -121,10 +119,12 @@ int conn_readwait(int sockfd, char *buf,
FD_SET(sockfd, &fdset);
rv = select(sockfd+1, &fdset, NULL, NULL, &timeout);
- if (rv > 0)
+ if (rv > 0) {
return recv(sockfd, buf, len, 0);
- else
+ }
+ else {
return -1;
+ }
}
#ifdef CONN_DRIVER
@@ -136,30 +136,29 @@ int main(int argc, char *argv[])
int sockfd, len;
char buf[BUFSZ+1];
- if (argc != 3)
- {
+ if (argc != 3) {
printf("usage: conn ip port\n");
exit(EXIT_FAILURE);
}
/* open the connection */
sockfd = conn_open(argv[1], atoi(argv[2]));
- if (sockfd < 0)
- {
+ if (sockfd < 0) {
perror("conn_open()");
exit(EXIT_FAILURE);
}
/* do non-blocking reads and print whatever shows up */
- while ((len = conn_readwait(sockfd, buf, BUFSZ, 0, 0)) >= 0)
- {
- if (len > 0)
+ while ((len = conn_readwait(sockfd, buf, BUFSZ, 0, 0)) >= 0) {
+ if (len > 0) {
write(1, buf, len);
+ }
/* do non-blocking read on stdin for data to send */
len = conn_readwait(0, buf, BUFSZ, 0, 0);
- if (len > 0)
+ if (len > 0) {
write(sockfd, buf, len);
+ }
}
conn_close(sockfd);
Index: testsuite/conn.h
===================================================================
--- testsuite.orig/conn.h
+++ testsuite/conn.h
@@ -5,7 +5,7 @@
#ifndef _CONN_H_
#define _CONN_H_
-int conn_open(char *ip, char *hostname, int port);
+int conn_open(char *host, char *port);
int conn_close(int sockfd);
int conn_write(int sockfd, char *buf, int len);
int conn_read(int sockfd, char *buf, int len);
Index: testsuite/msgloadrec.c
===================================================================
--- testsuite.orig/msgloadrec.c
+++ testsuite/msgloadrec.c
@@ -34,7 +34,7 @@ int parse_options(int argc, char *argv[]
void print_usage(void);
int open_session(char *servername,
char *hostname,
- int port,
+ char *port,
char *username,
char *password,
char *resource,
@@ -356,7 +356,7 @@ int parse_options(int argc, char *argv[]
strncpy(options->password, optarg, MAX_BUFSZ);
break;
case 'p':
- options->port = atoi(optarg);
+ options->port = optarg;
break;
case 'x':
options->throttle_secs = atol(optarg);
@@ -440,7 +440,7 @@ void print_usage(void)
int open_session(char *hostname,
char *servername,
- int port,
+ char *port,
char *username,
char *password,
char *resource,
@@ -451,8 +451,8 @@ int open_session(char *hostname,
user_data_t *ud;
/* open a connection with the server */
- DPRINT("opening connection to %s on port %d\n", hostname, port);
- sockfd = conn_open(NULL, hostname, port);
+ DPRINT("opening connection to %s on port %s\n", hostname, port);
+ sockfd = conn_open(hostname, port);
if (sockfd < 0)
{
perror("conn_open()");
Index: testsuite/msgloadrec.h
===================================================================
--- testsuite.orig/msgloadrec.h
+++ testsuite/msgloadrec.h
@@ -33,7 +33,7 @@ typedef struct _options_t
char to_user[MAX_BUFSZ+1]; /* destination user */
char password[MAX_BUFSZ+1]; /* user's jabber password */
char output[MAX_BUFSZ+1]; /* output file name */
- int port; /* jabberd port */
+ char *port; /* jabberd port */
int time_data; /* print out timing data */
int timeout; /* timeout after x seconds */
long throttle_secs; /* throttle time in secs */
Index: testsuite/msgloadsnd.c
===================================================================
--- testsuite.orig/msgloadsnd.c
+++ testsuite/msgloadsnd.c
@@ -30,7 +30,7 @@ int parse_options(int argc, char *argv[]
void print_usage(void);
int open_session(char *servername,
char *hostname,
- int port,
+ char *port,
char *username,
char *password,
char *resource,
@@ -273,7 +273,7 @@ int parse_options(int argc, char *argv[]
strncpy(options->from_user, optarg, MAX_BUFSZ);
break;
case 'p':
- options->port = atoi(optarg);
+ options->port = optarg;
break;
case 'w':
strncpy(options->password, optarg, MAX_BUFSZ);
@@ -363,7 +363,7 @@ void print_usage(void)
int open_session(char *hostname,
char *servername,
- int port,
+ char *port,
char *username,
char *password,
char *resource,
@@ -374,8 +374,8 @@ int open_session(char *hostname,
char *streamid;
/* open a connection with the server */
- DPRINT("opening connection to %s on port %d\n", hostname, port);
- sockfd = conn_open(NULL, hostname, port);
+ DPRINT("opening connection to %s on port %s\n", hostname, port);
+ sockfd = conn_open(hostname, port);
if (sockfd < 0)
{
perror("conn_open()");
Index: testsuite/msgloadsnd.h
===================================================================
--- testsuite.orig/msgloadsnd.h
+++ testsuite/msgloadsnd.h
@@ -20,7 +20,7 @@ typedef struct _options_t
char from_user[MAX_BUFSZ+1];
char to_user[MAX_BUFSZ+1];
char password[MAX_BUFSZ+1];
- int port;
+ char *port;
int messages;
int steady_load;
long throttle_secs;
Index: testsuite/pasvlogin.c
===================================================================
--- testsuite.orig/pasvlogin.c
+++ testsuite/pasvlogin.c
@@ -29,7 +29,7 @@ int parse_options(int argc, char *argv[]
void print_usage(void);
int open_session(char *servername,
char *hostname,
- int port,
+ char *port,
char *username,
char *password,
char *resource,
@@ -250,7 +250,7 @@ int parse_options(int argc, char *argv[]
/* server port */
case 'p':
- options->port = atoi(optarg);
+ options->port = optarg;
break;
/* total users */
@@ -367,7 +367,7 @@ void print_usage(void)
int open_session(char *hostname,
char *servername,
- int port,
+ char *port,
char *username,
char *password,
char *resource,
@@ -379,8 +379,8 @@ int open_session(char *hostname,
user_data_t *ud;
/* open a connection with the server */
- DPRINT("opening connection to %s on port %d\n", hostname, port);
- sockfd = conn_open(NULL, hostname, port);
+ DPRINT("opening connection to %s on port %s\n", hostname, port);
+ sockfd = conn_open(hostname, port);
if (sockfd < 0)
{
perror("conn_open()");
Index: testsuite/pasvlogin.h
===================================================================
--- testsuite.orig/pasvlogin.h
+++ testsuite/pasvlogin.h
@@ -27,7 +27,7 @@ typedef struct _options_t
char hostname[MAX_BUFSZ+1];
char output[MAX_BUFSZ+1];
char msgfile[MAX_BUFSZ+1];
- int port;
+ char *port;
int timeout;
int users;
int method;
Index: testsuite/testsuite.h
===================================================================
--- testsuite.orig/testsuite.h
+++ testsuite/testsuite.h
@@ -47,7 +47,7 @@
#define BANNER "Jabber Test Suite - http://www.sf.net/projects/jabbertest\nThis software is governed by the GPL, read LICENSE for more information."
-#define JABBER_PORT 5222
+#define JABBER_PORT "5222"
#endif /* _TESTSUITE_H_ */
Index: testsuite/userreg.c
===================================================================
--- testsuite.orig/userreg.c
+++ testsuite/userreg.c
@@ -28,7 +28,7 @@ int parse_options(int argc, char *argv[]
void print_usage(void);
int open_stream(char *servername,
char *hostname,
- int port,
+ char *port,
XML_Parser parser);
int close_stream(int sockfd);
int register_user(int sockfd,
@@ -244,7 +244,7 @@ int parse_options(int argc, char *argv[]
/* server port */
case 'p':
- options->port = atoi(optarg);
+ options->port = optarg;
break;
/* total users */
@@ -353,15 +353,15 @@ void print_usage(void)
int open_stream(char *servername,
char *hostname,
- int port,
+ char *port,
XML_Parser parser)
{
int sockfd, len;
char buf[MAX_XML_BUFSZ+1];
/* open a connection with the server */
- DPRINT("opening connection to %s on port %d\n", hostname, port);
- sockfd = conn_open(NULL, hostname, port);
+ DPRINT("opening connection to %s on port %s\n", hostname, port);
+ sockfd = conn_open(hostname, port);
if (sockfd < 0)
{
perror("conn_open()");
Index: testsuite/userreg.h
===================================================================
--- testsuite.orig/userreg.h
+++ testsuite/userreg.h
@@ -20,7 +20,7 @@ typedef struct _options_t
char output[MAX_BUFSZ+1];
char msgfile[MAX_BUFSZ+1];
int mode;
- int port;
+ char *port;
int timeout;
int users;
int start_number;