version 1.80, 2005/05/27 04:55:28 |
version 1.81, 2005/05/28 16:57:48 |
|
|
int udptest(int); |
int udptest(int); |
int unix_connect(char *); |
int unix_connect(char *); |
int unix_listen(char *); |
int unix_listen(char *); |
|
int set_common_sockopts(int); |
void usage(int); |
void usage(int); |
|
|
int |
int |
|
|
remote_connect(const char *host, const char *port, struct addrinfo hints) |
remote_connect(const char *host, const char *port, struct addrinfo hints) |
{ |
{ |
struct addrinfo *res, *res0; |
struct addrinfo *res, *res0; |
int s, error, x = 1; |
int s, error; |
|
|
if ((error = getaddrinfo(host, port, &hints, &res))) |
if ((error = getaddrinfo(host, port, &hints, &res))) |
errx(1, "getaddrinfo: %s", gai_strerror(error)); |
errx(1, "getaddrinfo: %s", gai_strerror(error)); |
|
|
errx(1, "bind failed: %s", strerror(errno)); |
errx(1, "bind failed: %s", strerror(errno)); |
freeaddrinfo(ares); |
freeaddrinfo(ares); |
} |
} |
if (Sflag) { |
|
if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, |
|
&x, sizeof(x)) == -1) |
|
err(1, NULL); |
|
} |
|
if (Dflag) { |
|
if (setsockopt(s, SOL_SOCKET, SO_DEBUG, |
|
&x, sizeof(x)) == -1) |
|
err(1, NULL); |
|
} |
|
if (jflag) { |
|
if (setsockopt(s, SOL_SOCKET, SO_JUMBO, |
|
&x, sizeof(x)) == -1) |
|
err(1, NULL); |
|
} |
|
|
|
|
set_common_sockopts(s); |
|
|
if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) |
if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) |
break; |
break; |
else if (vflag) |
else if (vflag) |
|
|
ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); |
ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); |
if (ret == -1) |
if (ret == -1) |
err(1, NULL); |
err(1, NULL); |
if (Sflag) { |
|
ret = setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, |
|
&x, sizeof(x)); |
|
if (ret == -1) |
|
err(1, NULL); |
|
} |
|
if (Dflag) { |
|
if (setsockopt(s, SOL_SOCKET, SO_DEBUG, |
|
&x, sizeof(x)) == -1) |
|
err(1, NULL); |
|
} |
|
|
|
|
set_common_sockopts(s); |
|
|
if (bind(s, (struct sockaddr *)res0->ai_addr, |
if (bind(s, (struct sockaddr *)res0->ai_addr, |
res0->ai_addrlen) == 0) |
res0->ai_addrlen) == 0) |
break; |
break; |
|
|
ret = -1; |
ret = -1; |
} |
} |
return (ret); |
return (ret); |
|
} |
|
|
|
int |
|
set_common_sockopts(int s) |
|
{ |
|
int x = 1; |
|
|
|
if (Sflag) { |
|
if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, |
|
&x, sizeof(x)) == -1) |
|
err(1, NULL); |
|
} |
|
if (Dflag) { |
|
if (setsockopt(s, SOL_SOCKET, SO_DEBUG, |
|
&x, sizeof(x)) == -1) |
|
err(1, NULL); |
|
} |
|
if (jflag) { |
|
if (setsockopt(s, SOL_SOCKET, SO_JUMBO, |
|
&x, sizeof(x)) == -1) |
|
err(1, NULL); |
|
} |
} |
} |
|
|
void |
void |