Made the protocol implementation better. Lots of code clean up
Этот коммит содержится в:
родитель
8a0b5a5d18
Коммит
66ce7ad49d
@ -118,15 +118,14 @@ struct protocol {
|
||||
struct iperf_test
|
||||
{
|
||||
char role; /* c' lient or 's' erver */
|
||||
int protocol;
|
||||
struct protocol *protocol;
|
||||
char state;
|
||||
char *server_hostname; /* -c option */
|
||||
int server_port;
|
||||
int duration; /* total duration of test (-t flag) */
|
||||
|
||||
int ctrl_sck;
|
||||
int listener_tcp;
|
||||
int listener_udp;
|
||||
int listener;
|
||||
int prot_listener;
|
||||
|
||||
/* boolen variables for Options */
|
||||
@ -146,7 +145,6 @@ struct iperf_test
|
||||
fd_set write_set; /* set of write sockets */
|
||||
|
||||
int (*accept) (struct iperf_test *);
|
||||
struct iperf_stream *(*new_stream) (struct iperf_test *);
|
||||
|
||||
/* Interval related members */
|
||||
int stats_interval;
|
||||
|
210
src/iperf_api.c
210
src/iperf_api.c
@ -52,6 +52,7 @@ usage()
|
||||
fprintf(stderr, usage_short);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
usage_long()
|
||||
{
|
||||
@ -59,6 +60,41 @@ usage_long()
|
||||
fprintf(stderr, usage_long2);
|
||||
}
|
||||
|
||||
|
||||
struct protocol *
|
||||
get_protocol(struct iperf_test *test, int prot_id)
|
||||
{
|
||||
struct protocol *prot;
|
||||
|
||||
SLIST_FOREACH(prot, &test->protocols, protocols) {
|
||||
if (prot->id == prot_id)
|
||||
break;
|
||||
}
|
||||
|
||||
if (prot == NULL)
|
||||
i_errno = IEPROTOCOL;
|
||||
|
||||
return (prot);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
set_protocol(struct iperf_test *test, int prot_id)
|
||||
{
|
||||
struct protocol *prot = NULL;
|
||||
|
||||
SLIST_FOREACH(prot, &test->protocols, protocols) {
|
||||
if (prot->id == prot_id) {
|
||||
test->protocol = prot;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
i_errno = IEPROTOCOL;
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
|
||||
{
|
||||
@ -137,9 +173,8 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
|
||||
i_errno = IECLIENTONLY;
|
||||
return (-1);
|
||||
}
|
||||
test->protocol = Pudp;
|
||||
set_protocol(test, Pudp);
|
||||
test->default_settings->blksize = DEFAULT_UDP_BLKSIZE;
|
||||
test->new_stream = iperf_new_udp_stream;
|
||||
break;
|
||||
case 'P':
|
||||
if (test->role == 's') {
|
||||
@ -346,17 +381,10 @@ int
|
||||
iperf_init_test(struct iperf_test *test)
|
||||
{
|
||||
struct iperf_stream *sp;
|
||||
struct protocol *prot;
|
||||
int64_t dtargus;
|
||||
|
||||
SLIST_FOREACH(prot, &test->protocols, protocols) {
|
||||
if (test->protocol == prot->id) {
|
||||
if (prot->init) {
|
||||
if (prot->init(test) < 0)
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (test->protocol->init) {
|
||||
if (test->protocol->init(test) < 0)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set timers */
|
||||
@ -364,10 +392,10 @@ iperf_init_test(struct iperf_test *test)
|
||||
test->timer = new_timer(test->duration, 0);
|
||||
if (test->timer == NULL)
|
||||
return (-1);
|
||||
printf(test_start_time, prot->name, test->num_streams, test->default_settings->blksize,
|
||||
printf(test_start_time, test->protocol->name, test->num_streams, test->default_settings->blksize,
|
||||
test->duration);
|
||||
} else {
|
||||
printf(test_start_bytes, prot->name, test->num_streams, test->default_settings->blksize,
|
||||
printf(test_start_bytes, test->protocol->name, test->num_streams, test->default_settings->blksize,
|
||||
test->default_settings->bytes);
|
||||
}
|
||||
|
||||
@ -405,9 +433,9 @@ package_parameters(struct iperf_test *test)
|
||||
|
||||
*pstring = ' ';
|
||||
|
||||
if (test->protocol == Ptcp) {
|
||||
if (test->protocol->id == Ptcp) {
|
||||
strncat(pstring, "-p ", sizeof(pstring));
|
||||
} else if (test->protocol == Pudp) {
|
||||
} else if (test->protocol->id == Pudp) {
|
||||
strncat(pstring, "-u ", sizeof(pstring));
|
||||
}
|
||||
|
||||
@ -496,7 +524,7 @@ parse_parameters(struct iperf_test *test)
|
||||
while ((ch = getopt(n, params, "pt:n:m:uNP:Rw:l:b:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'p':
|
||||
test->protocol = Ptcp;
|
||||
set_protocol(test, Ptcp);
|
||||
break;
|
||||
case 't':
|
||||
test->duration = atoi(optarg);
|
||||
@ -508,8 +536,7 @@ parse_parameters(struct iperf_test *test)
|
||||
test->default_settings->mss = atoi(optarg);
|
||||
break;
|
||||
case 'u':
|
||||
test->protocol = Pudp;
|
||||
test->new_stream = iperf_new_udp_stream;
|
||||
set_protocol(test, Pudp);
|
||||
break;
|
||||
case 'N':
|
||||
test->no_delay = 1;
|
||||
@ -550,28 +577,20 @@ int
|
||||
iperf_exchange_parameters(struct iperf_test * test)
|
||||
{
|
||||
int s;
|
||||
struct protocol *prot;
|
||||
/*
|
||||
int s, opt, len;
|
||||
struct sockaddr_in sa;
|
||||
*/
|
||||
|
||||
if (test->role == 'c') {
|
||||
|
||||
if (package_parameters(test) < 0)
|
||||
return (-1);
|
||||
|
||||
} else {
|
||||
|
||||
if (parse_parameters(test) < 0)
|
||||
return (-1);
|
||||
|
||||
printf(" cookie: %s\n", test->default_settings->cookie);
|
||||
|
||||
SLIST_FOREACH(prot, &test->protocols, protocols) {
|
||||
if (prot->id == test->protocol)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((s = prot->listen(test)) < 0)
|
||||
if ((s = test->protocol->listen(test)) < 0)
|
||||
return (-1);
|
||||
FD_SET(s, &test->read_set);
|
||||
test->max_fd = (s > test->max_fd) ? s : test->max_fd;
|
||||
@ -765,25 +784,6 @@ add_to_interval_list(struct iperf_stream_result * rp, struct iperf_interval_resu
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
/* for debugging only */
|
||||
void
|
||||
display_interval_list(struct iperf_stream_result * rp, int tflag)
|
||||
{
|
||||
struct iperf_interval_results *n;
|
||||
float gb = 0.;
|
||||
|
||||
n = rp->interval_results;
|
||||
|
||||
printf("----------------------------------------\n");
|
||||
while (n != NULL) {
|
||||
gb = (float) n->bytes_transferred / (1024. * 1024. * 1024.);
|
||||
printf("Interval = %f\tGBytes transferred = %.3f\n", n->interval_duration, gb);
|
||||
if (tflag)
|
||||
print_tcpinfo(n);
|
||||
n = n->next;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
|
||||
@ -807,36 +807,6 @@ connect_msg(struct iperf_stream * sp)
|
||||
ipr, ntohs(((struct sockaddr_in *) & sp->remote_addr)->sin_port));
|
||||
}
|
||||
|
||||
/*************************************************************/
|
||||
/**
|
||||
* Display -- Displays results for test
|
||||
* Mainly for DEBUG purpose
|
||||
*
|
||||
*/
|
||||
|
||||
void
|
||||
Display(struct iperf_test * test)
|
||||
{
|
||||
int count = 1;
|
||||
struct iperf_stream *n;
|
||||
|
||||
n = test->streams;
|
||||
|
||||
printf("===============DISPLAY==================\n");
|
||||
|
||||
while (n != NULL) {
|
||||
if (test->role == 'c') {
|
||||
printf("position-%d\tsp=%llu\tsocket=%d\tMbytes sent=%u\n",
|
||||
count++, (uint64_t) n, n->socket, (unsigned int) (n->result->bytes_sent / (float) MB));
|
||||
} else {
|
||||
printf("position-%d\tsp=%llu\tsocket=%d\tMbytes received=%u\n",
|
||||
count++, (uint64_t) n, n->socket, (unsigned int) (n->result->bytes_received / (float) MB));
|
||||
}
|
||||
n = n->next;
|
||||
}
|
||||
printf("=================END====================\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@ -860,16 +830,14 @@ iperf_new_test()
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
void
|
||||
int
|
||||
iperf_defaults(struct iperf_test * testp)
|
||||
{
|
||||
testp->protocol = Ptcp;
|
||||
testp->duration = DURATION;
|
||||
testp->server_port = PORT;
|
||||
testp->ctrl_sck = -1;
|
||||
testp->prot_listener = -1;
|
||||
|
||||
testp->new_stream = iperf_new_tcp_stream;
|
||||
testp->stats_callback = iperf_stats_callback;
|
||||
testp->reporter_callback = iperf_reporter_callback;
|
||||
|
||||
@ -917,7 +885,11 @@ iperf_defaults(struct iperf_test * testp)
|
||||
udp->send = iperf_udp_send;
|
||||
udp->recv = iperf_udp_recv;
|
||||
udp->init = iperf_udp_init;
|
||||
SLIST_INSERT_AFTER(tcp, udp, protocols);
|
||||
SLIST_INSERT_AFTER(tcp, udp, protocols);
|
||||
|
||||
set_protocol(testp, Ptcp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
@ -926,17 +898,11 @@ int
|
||||
iperf_create_streams(struct iperf_test *test)
|
||||
{
|
||||
int i, s;
|
||||
struct protocol *prot;
|
||||
struct iperf_stream *sp;
|
||||
|
||||
for (i = 0; i < test->num_streams; ++i) {
|
||||
|
||||
SLIST_FOREACH(prot, &test->protocols, protocols) {
|
||||
if (prot->id == test->protocol)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((s = prot->connect(test)) < 0)
|
||||
if ((s = test->protocol->connect(test)) < 0)
|
||||
return (-1);
|
||||
|
||||
FD_SET(s, &test->read_set);
|
||||
@ -944,13 +910,9 @@ iperf_create_streams(struct iperf_test *test)
|
||||
test->max_fd = (test->max_fd < s) ? s : test->max_fd;
|
||||
|
||||
// XXX: This doesn't fit our API model!
|
||||
sp = test->new_stream(test);
|
||||
sp = iperf_new_stream(test, s);
|
||||
if (!sp)
|
||||
return (-1);
|
||||
sp->socket = s;
|
||||
if (iperf_init_stream(sp, test) < 0)
|
||||
return (-1);
|
||||
iperf_add_stream(test, sp);
|
||||
|
||||
connect_msg(sp);
|
||||
}
|
||||
@ -1065,7 +1027,6 @@ iperf_free_test(struct iperf_test * test)
|
||||
test->accept = NULL;
|
||||
test->stats_callback = NULL;
|
||||
test->reporter_callback = NULL;
|
||||
test->new_stream = NULL;
|
||||
free(test);
|
||||
}
|
||||
|
||||
@ -1178,7 +1139,7 @@ iperf_reporter_callback(struct iperf_test * test)
|
||||
total_sent += bytes_sent;
|
||||
total_received += bytes_received;
|
||||
|
||||
if (test->protocol == Pudp) {
|
||||
if (test->protocol->id == Pudp) {
|
||||
total_packets += sp->packet_count;
|
||||
lost_packets += sp->cnt_error;
|
||||
avg_jitter += sp->jitter;
|
||||
@ -1187,7 +1148,7 @@ iperf_reporter_callback(struct iperf_test * test)
|
||||
if (bytes_sent > 0) {
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) (bytes_sent), 'A');
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) (bytes_sent / end_time), test->default_settings->unit_format);
|
||||
if (test->protocol == Ptcp) {
|
||||
if (test->protocol->id == Ptcp) {
|
||||
printf(" Sent\n");
|
||||
printf(report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
||||
|
||||
@ -1211,7 +1172,7 @@ iperf_reporter_callback(struct iperf_test * test)
|
||||
if (bytes_received > 0) {
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) bytes_received, 'A');
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) (bytes_received / end_time), test->default_settings->unit_format);
|
||||
if (test->protocol == Ptcp) {
|
||||
if (test->protocol->id == Ptcp) {
|
||||
printf(" Received\n");
|
||||
printf(report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
||||
}
|
||||
@ -1221,7 +1182,7 @@ iperf_reporter_callback(struct iperf_test * test)
|
||||
if (test->num_streams > 1) {
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) total_sent, 'A');
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) total_sent / end_time, test->default_settings->unit_format);
|
||||
if (test->protocol == Ptcp) {
|
||||
if (test->protocol->id == Ptcp) {
|
||||
printf(" Total sent\n");
|
||||
printf(report_sum_bw_format, start_time, end_time, ubuf, nbuf);
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) total_received, 'A');
|
||||
@ -1297,7 +1258,7 @@ iperf_free_stream(struct iperf_stream * sp)
|
||||
|
||||
/**************************************************************************/
|
||||
struct iperf_stream *
|
||||
iperf_new_stream(struct iperf_test *testp)
|
||||
iperf_new_stream(struct iperf_test *test, int s)
|
||||
{
|
||||
int i;
|
||||
struct iperf_stream *sp;
|
||||
@ -1307,12 +1268,14 @@ iperf_new_stream(struct iperf_test *testp)
|
||||
i_errno = IECREATESTREAM;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
memset(sp, 0, sizeof(struct iperf_stream));
|
||||
|
||||
sp->buffer = (char *) malloc(testp->default_settings->blksize);
|
||||
sp->buffer = (char *) malloc(test->default_settings->blksize);
|
||||
sp->settings = (struct iperf_settings *) malloc(sizeof(struct iperf_settings));
|
||||
sp->result = (struct iperf_stream_result *) malloc(sizeof(struct iperf_stream_result));
|
||||
|
||||
|
||||
if (!sp->buffer) {
|
||||
i_errno = IECREATESTREAM;
|
||||
return (NULL);
|
||||
@ -1325,37 +1288,30 @@ iperf_new_stream(struct iperf_test *testp)
|
||||
i_errno = IECREATESTREAM;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
memset(sp->result, 0, sizeof(struct iperf_stream_result));
|
||||
|
||||
/* Make a per stream copy of default_settings in each stream structure */
|
||||
// XXX: These settings need to be moved to the test struct
|
||||
memcpy(sp->settings, testp->default_settings, sizeof(struct iperf_settings));
|
||||
memcpy(sp->settings, test->default_settings, sizeof(struct iperf_settings));
|
||||
|
||||
/* Randomize the buffer */
|
||||
srandom(time(0));
|
||||
for (i = 0; i < testp->default_settings->blksize; ++i)
|
||||
srandom(time(NULL));
|
||||
for (i = 0; i < test->default_settings->blksize; ++i)
|
||||
sp->buffer[i] = random();
|
||||
|
||||
sp->socket = -1;
|
||||
/* Set socket */
|
||||
sp->socket = s;
|
||||
|
||||
// XXX: Some of this code is needed, even though everything is already zero.
|
||||
sp->packet_count = 0;
|
||||
sp->jitter = 0.0;
|
||||
sp->prev_transit = 0.0;
|
||||
sp->outoforder_packets = 0;
|
||||
sp->cnt_error = 0;
|
||||
sp->snd = test->protocol->send;
|
||||
sp->rcv = test->protocol->recv;
|
||||
|
||||
sp->send_timer = NULL;
|
||||
sp->next = NULL;
|
||||
/* Initialize stream */
|
||||
if (iperf_init_stream(sp, test) < 0)
|
||||
return (NULL);
|
||||
iperf_add_stream(test, sp);
|
||||
|
||||
sp->result->interval_results = NULL;
|
||||
sp->result->last_interval_results = NULL;
|
||||
sp->result->bytes_received = 0;
|
||||
sp->result->bytes_sent = 0;
|
||||
sp->result->bytes_received_this_interval = 0;
|
||||
sp->result->bytes_sent_this_interval = 0;
|
||||
|
||||
sp->settings->state = STREAM_BEGIN;
|
||||
return sp;
|
||||
return (sp);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
@ -1374,17 +1330,13 @@ iperf_init_stream(struct iperf_stream * sp, struct iperf_test * testp)
|
||||
i_errno = IEINITSTREAM;
|
||||
return (-1);
|
||||
}
|
||||
if (testp->protocol == Ptcp) {
|
||||
if (testp->protocol->id == Ptcp) {
|
||||
// XXX: This property is for all sockets, not just TCP
|
||||
if (set_tcp_windowsize(sp->socket, testp->default_settings->socket_bufsize,
|
||||
testp->role == 's' ? SO_RCVBUF : SO_SNDBUF) < 0) {
|
||||
i_errno = IESETWINDOWSIZE;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* set TCP_NODELAY and TCP_MAXSEG if requested */
|
||||
// XXX: This has been moved
|
||||
// set_tcp_options(sp->socket, testp->no_delay, testp->default_settings->mss);
|
||||
}
|
||||
|
||||
return (0);
|
||||
@ -1518,5 +1470,5 @@ iperf_run_client(struct iperf_test * test)
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#ifndef __IPERF_API_H
|
||||
#define __IPERF_API_H
|
||||
|
||||
#include <setjmp.h>
|
||||
#include "iperf.h"
|
||||
|
||||
/**
|
||||
@ -22,13 +23,6 @@ int iperf_exchange_parameters(struct iperf_test * test);
|
||||
*/
|
||||
void add_to_interval_list(struct iperf_stream_result * rp, struct iperf_interval_results *temp);
|
||||
|
||||
/**
|
||||
* Display -- Displays interval results for test
|
||||
* Mainly for DEBUG purpose
|
||||
*
|
||||
*/
|
||||
void display_interval_list(struct iperf_stream_result * rp, int tflag);
|
||||
|
||||
/**
|
||||
* connect_msg -- displays connection message
|
||||
* denoting senfer/receiver details
|
||||
@ -36,16 +30,6 @@ void display_interval_list(struct iperf_stream_result * rp, int tflag);
|
||||
*/
|
||||
void connect_msg(struct iperf_stream * sp);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Display -- Displays streams in a test
|
||||
* Mainly for DEBUG purpose
|
||||
*
|
||||
*/
|
||||
void Display(struct iperf_test * test);
|
||||
|
||||
|
||||
/**
|
||||
* iperf_stats_callback -- handles the statistic gathering
|
||||
*
|
||||
@ -74,7 +58,7 @@ int iperf_run_client(struct iperf_test * test);
|
||||
*/
|
||||
struct iperf_test *iperf_new_test();
|
||||
|
||||
void iperf_defaults(struct iperf_test * testp);
|
||||
int iperf_defaults(struct iperf_test * testp);
|
||||
|
||||
|
||||
/**
|
||||
@ -91,9 +75,7 @@ void iperf_free_test(struct iperf_test * testp);
|
||||
* returns NULL on failure
|
||||
*
|
||||
*/
|
||||
struct iperf_stream *iperf_new_stream(struct iperf_test * testp);
|
||||
|
||||
struct iperf_stream *iperf_new_udp_stream(struct iperf_test * testp);
|
||||
struct iperf_stream *iperf_new_stream(struct iperf_test *, int);
|
||||
|
||||
/**
|
||||
* iperf_add_stream -- add a stream to a test
|
||||
@ -116,6 +98,7 @@ void iperf_free_stream(struct iperf_stream * sp);
|
||||
void get_tcpinfo(struct iperf_test *test, struct iperf_interval_results *rp);
|
||||
void print_tcpinfo(struct iperf_interval_results *);
|
||||
void build_tcpinfo_message(struct iperf_interval_results *r, char *message);
|
||||
|
||||
void print_interval_results(struct iperf_test * test, struct iperf_stream *sp);
|
||||
int iperf_connect(struct iperf_test *);
|
||||
int iperf_client_end(struct iperf_test *);
|
||||
@ -134,5 +117,10 @@ int parse_results(struct iperf_test *, char *);
|
||||
int iperf_init_test(struct iperf_test *);
|
||||
int iperf_parse_arguments(struct iperf_test *, int, char **);
|
||||
|
||||
struct protocol *get_protocol(struct iperf_test *, int);
|
||||
int set_protocol(struct iperf_test *, int);
|
||||
|
||||
extern jmp_buf env;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -125,6 +125,9 @@ iperf_strerror(int i_errno)
|
||||
case IESETWINDOWSIZE:
|
||||
snprintf(errstr, len, "unable to set socket window size");
|
||||
break;
|
||||
case IEPROTOCOL:
|
||||
snprintf(errstr, len, "protocol does not exist");
|
||||
break;
|
||||
case IECREATESTREAM:
|
||||
snprintf(errstr, len, "unable to create a new stream");
|
||||
break;
|
||||
|
@ -52,21 +52,22 @@ enum {
|
||||
IEREUSEADDR = 33, // Unable to set reuse address on socket (check perror)
|
||||
IENONBLOCKING = 34, // Unable to set socket to non-blocking (check perror)
|
||||
IESETWINDOWSIZE = 35, // Unable to set socket window size (check perror)
|
||||
IEPROTOCOL = 36, // Protocol does not exist
|
||||
|
||||
/* Stream errors */
|
||||
IECREATESTREAM = 36, // Unable to create a new stream (check herror/perror)
|
||||
IEINITSTREAM = 37, // Unable to initialize stream (check herror/perror)
|
||||
IESTREAMLISTEN = 38, // Unable to start stream listener (check perror)
|
||||
IESTREAMCONNECT = 39, // Unable to connect stream (check herror/perror)
|
||||
IESTREAMACCEPT = 40, // Unable to accepte stream connection (check perror)
|
||||
IESTREAMWRITE = 41, // Unable to write to stream socket (check perror)
|
||||
IESTREAMREAD = 42, // Unable to read from stream (check perror)
|
||||
IESTREAMCLOSE = 43, // Stream has closed unexpectedly
|
||||
IESTREAMID = 44, // Stream has invalid ID
|
||||
IECREATESTREAM = 37, // Unable to create a new stream (check herror/perror)
|
||||
IEINITSTREAM = 38, // Unable to initialize stream (check herror/perror)
|
||||
IESTREAMLISTEN = 39, // Unable to start stream listener (check perror)
|
||||
IESTREAMCONNECT = 40, // Unable to connect stream (check herror/perror)
|
||||
IESTREAMACCEPT = 41, // Unable to accepte stream connection (check perror)
|
||||
IESTREAMWRITE = 42, // Unable to write to stream socket (check perror)
|
||||
IESTREAMREAD = 43, // Unable to read from stream (check perror)
|
||||
IESTREAMCLOSE = 44, // Stream has closed unexpectedly
|
||||
IESTREAMID = 45, // Stream has invalid ID
|
||||
|
||||
/* Timer errors */
|
||||
IENEWTIMER = 45, // Unable to create new timer (check perror)
|
||||
IEUPDATETIMER = 46, // Unable to update timer (check perror)
|
||||
IENEWTIMER = 46, // Unable to create new timer (check perror)
|
||||
IEUPDATETIMER = 47, // Unable to update timer (check perror)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "iperf_util.h"
|
||||
#include "locale.h"
|
||||
|
||||
jmp_buf env;
|
||||
|
||||
int
|
||||
iperf_server_listen(struct iperf_test *test)
|
||||
@ -53,7 +52,7 @@ iperf_server_listen(struct iperf_test *test)
|
||||
char ubuf[UNIT_LEN];
|
||||
int x;
|
||||
|
||||
if((test->listener_tcp = netannounce(Ptcp, NULL, test->server_port)) < 0) {
|
||||
if((test->listener = netannounce(Ptcp, NULL, test->server_port)) < 0) {
|
||||
i_errno = IELISTEN;
|
||||
return (-1);
|
||||
}
|
||||
@ -64,7 +63,7 @@ iperf_server_listen(struct iperf_test *test)
|
||||
// This needs to be changed to reflect if client has different window size
|
||||
// make sure we got what we asked for
|
||||
/* XXX: This needs to be moved to the stream listener
|
||||
if ((x = get_tcp_windowsize(test->listener_tcp, SO_RCVBUF)) < 0) {
|
||||
if ((x = get_tcp_windowsize(test->listener, SO_RCVBUF)) < 0) {
|
||||
// Needs to set some sort of error number/message
|
||||
perror("SO_RCVBUF");
|
||||
return -1;
|
||||
@ -73,7 +72,7 @@ iperf_server_listen(struct iperf_test *test)
|
||||
|
||||
// XXX: This code needs to be moved to after parameter exhange
|
||||
/*
|
||||
if (test->protocol == Ptcp) {
|
||||
if (test->protocol->id == Ptcp) {
|
||||
if (test->default_settings->socket_bufsize > 0) {
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) x, 'A');
|
||||
printf("TCP window size: %s\n", ubuf);
|
||||
@ -86,8 +85,8 @@ iperf_server_listen(struct iperf_test *test)
|
||||
|
||||
FD_ZERO(&test->read_set);
|
||||
FD_ZERO(&test->write_set);
|
||||
FD_SET(test->listener_tcp, &test->read_set);
|
||||
test->max_fd = (test->listener_tcp > test->max_fd) ? test->listener_tcp : test->max_fd;
|
||||
FD_SET(test->listener, &test->read_set);
|
||||
test->max_fd = (test->listener > test->max_fd) ? test->listener : test->max_fd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -104,7 +103,7 @@ iperf_accept(struct iperf_test *test)
|
||||
struct sockaddr_in temp1, temp2;
|
||||
|
||||
len = sizeof(addr);
|
||||
if ((s = accept(test->listener_tcp, (struct sockaddr *) &addr, &len)) < 0) {
|
||||
if ((s = accept(test->listener, (struct sockaddr *) &addr, &len)) < 0) {
|
||||
i_errno = IEACCEPT;
|
||||
return (-1);
|
||||
}
|
||||
@ -162,51 +161,6 @@ iperf_accept(struct iperf_test *test)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
iperf_accept_tcp_stream(struct iperf_test *test)
|
||||
{
|
||||
int s;
|
||||
int rbuf = ACCESS_DENIED;
|
||||
char cookie[COOKIE_SIZE];
|
||||
socklen_t len;
|
||||
struct sockaddr_in addr;
|
||||
struct iperf_stream *sp;
|
||||
|
||||
len = sizeof(addr);
|
||||
if ((s = accept(test->listener_tcp, (struct sockaddr *) &addr, &len)) < 0) {
|
||||
i_errno = IESTREAMCONNECT;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (Nread(s, cookie, COOKIE_SIZE, Ptcp) < 0) {
|
||||
i_errno = IERECVCOOKIE;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (strcmp(test->default_settings->cookie, cookie) == 0) {
|
||||
// XXX: CANNOT USE iperf_tcp_accept since stream is already accepted at this point. New model needed!
|
||||
sp = test->new_stream(test);
|
||||
if (!sp)
|
||||
return (-1);
|
||||
sp->socket = s;
|
||||
if (iperf_init_stream(sp, test) < 0)
|
||||
return (-1);
|
||||
iperf_add_stream(test, sp);
|
||||
FD_SET(s, &test->read_set);
|
||||
FD_SET(s, &test->write_set);
|
||||
test->max_fd = (s > test->max_fd) ? s : test->max_fd;
|
||||
test->streams_accepted++;
|
||||
connect_msg(sp);
|
||||
} else {
|
||||
if (Nwrite(s, &rbuf, sizeof(char), Ptcp) < 0) {
|
||||
i_errno = IESENDMESSAGE;
|
||||
return (-1);
|
||||
}
|
||||
close(s);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
int
|
||||
iperf_handle_message_server(struct iperf_test *test)
|
||||
@ -292,23 +246,23 @@ iperf_test_reset(struct iperf_test *test)
|
||||
test->streams = NULL;
|
||||
|
||||
test->role = 's';
|
||||
test->protocol = Ptcp;
|
||||
set_protocol(test, Ptcp);
|
||||
test->duration = DURATION;
|
||||
test->state = 0;
|
||||
test->server_hostname = NULL;
|
||||
|
||||
test->ctrl_sck = -1;
|
||||
test->prot_listener = -1;
|
||||
|
||||
test->bytes_sent = 0;
|
||||
test->new_stream = iperf_new_tcp_stream;
|
||||
|
||||
test->reverse = 0;
|
||||
test->no_delay = 0;
|
||||
|
||||
FD_ZERO(&test->read_set);
|
||||
FD_ZERO(&test->write_set);
|
||||
FD_SET(test->listener_tcp, &test->read_set);
|
||||
test->max_fd = test->listener_tcp;
|
||||
FD_SET(test->listener, &test->read_set);
|
||||
test->max_fd = test->listener;
|
||||
|
||||
test->num_streams = 1;
|
||||
test->streams_accepted = 0;
|
||||
@ -325,7 +279,6 @@ iperf_run_server(struct iperf_test *test)
|
||||
int result, s;
|
||||
fd_set temp_read_set, temp_write_set;
|
||||
struct iperf_stream *sp;
|
||||
struct protocol *prot;
|
||||
struct timeval tv;
|
||||
|
||||
// Open socket and listen
|
||||
@ -342,7 +295,7 @@ iperf_run_server(struct iperf_test *test)
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
for ( ; ; ) {
|
||||
@ -361,12 +314,12 @@ iperf_run_server(struct iperf_test *test)
|
||||
i_errno = IESELECT;
|
||||
return (-1);
|
||||
} else if (result > 0) {
|
||||
if (FD_ISSET(test->listener_tcp, &temp_read_set)) {
|
||||
if (FD_ISSET(test->listener, &temp_read_set)) {
|
||||
if (test->state != CREATE_STREAMS) {
|
||||
if (iperf_accept(test) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
FD_CLR(test->listener_tcp, &temp_read_set);
|
||||
FD_CLR(test->listener, &temp_read_set);
|
||||
}
|
||||
}
|
||||
if (FD_ISSET(test->ctrl_sck, &temp_read_set)) {
|
||||
@ -378,25 +331,18 @@ iperf_run_server(struct iperf_test *test)
|
||||
if (test->state == CREATE_STREAMS) {
|
||||
if (FD_ISSET(test->prot_listener, &temp_read_set)) {
|
||||
|
||||
SLIST_FOREACH(prot, &test->protocols, protocols) {
|
||||
if (prot->id == test->protocol)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((s = prot->accept(test)) < 0)
|
||||
if ((s = test->protocol->accept(test)) < 0)
|
||||
return (-1);
|
||||
|
||||
if (!is_closed(s)) {
|
||||
sp = test->new_stream(test);
|
||||
sp = iperf_new_stream(test, s);
|
||||
if (!sp)
|
||||
return (-1);
|
||||
sp->socket = s;
|
||||
if (iperf_init_stream(sp, test) < 0)
|
||||
return (-1);
|
||||
iperf_add_stream(test, sp);
|
||||
|
||||
FD_SET(s, &test->read_set);
|
||||
FD_SET(s, &test->write_set);
|
||||
test->max_fd = (s > test->max_fd) ? s : test->max_fd;
|
||||
|
||||
test->streams_accepted++;
|
||||
connect_msg(sp);
|
||||
}
|
||||
@ -404,20 +350,20 @@ iperf_run_server(struct iperf_test *test)
|
||||
}
|
||||
|
||||
if (test->streams_accepted == test->num_streams) {
|
||||
if (test->protocol != Ptcp) {
|
||||
if (test->protocol->id != Ptcp) {
|
||||
FD_CLR(test->prot_listener, &test->read_set);
|
||||
close(test->prot_listener);
|
||||
} else if (test->protocol == Ptcp) {
|
||||
} else {
|
||||
if (test->no_delay || test->default_settings->mss) {
|
||||
FD_CLR(test->listener_tcp, &test->read_set);
|
||||
close(test->listener_tcp);
|
||||
FD_CLR(test->listener, &test->read_set);
|
||||
close(test->listener);
|
||||
if ((s = netannounce(Ptcp, NULL, test->server_port)) < 0) {
|
||||
i_errno = IELISTEN;
|
||||
return (-1);
|
||||
}
|
||||
test->listener_tcp = s;
|
||||
test->listener = s;
|
||||
test->max_fd = (s > test->max_fd ? s : test->max_fd);
|
||||
FD_SET(test->listener_tcp, &test->read_set);
|
||||
FD_SET(test->listener, &test->read_set);
|
||||
}
|
||||
}
|
||||
test->prot_listener = -1;
|
||||
|
@ -9,10 +9,6 @@ int iperf_server_listen(struct iperf_test *);
|
||||
|
||||
int iperf_accept(struct iperf_test *);
|
||||
|
||||
int iperf_accept_tcp_stream(struct iperf_test *);
|
||||
|
||||
int iperf_accept_udp_stream(struct iperf_test *);
|
||||
|
||||
int iperf_handle_message_server(struct iperf_test *);
|
||||
|
||||
void iperf_test_reset(struct iperf_test *);
|
||||
|
@ -5,43 +5,24 @@
|
||||
* approvals from the U.S. Dept. of Energy). All rights reserved.
|
||||
*/
|
||||
|
||||
// XXX: Surely we do not need all these headers!
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "iperf.h"
|
||||
#include "iperf_api.h"
|
||||
#include "iperf_error.h"
|
||||
#include "iperf_server_api.h"
|
||||
#include "iperf_tcp.h"
|
||||
#include "timer.h"
|
||||
#include "iperf_error.h"
|
||||
#include "net.h"
|
||||
#include "tcp_window_size.h"
|
||||
#include "iperf_util.h"
|
||||
#include "locale.h"
|
||||
|
||||
// XXX: Does this belong here? We should probably declare this in iperf_api.c then put an extern in the header
|
||||
jmp_buf env; /* to handle longjmp on signal */
|
||||
|
||||
|
||||
/* iperf_tcp_recv
|
||||
@ -49,7 +30,7 @@ jmp_buf env; /* to handle longjmp on signal */
|
||||
* receives the data for TCP
|
||||
*/
|
||||
int
|
||||
iperf_tcp_recv(struct iperf_stream * sp)
|
||||
iperf_tcp_recv(struct iperf_stream *sp)
|
||||
{
|
||||
int result = 0;
|
||||
int size = sp->settings->blksize;
|
||||
@ -72,7 +53,7 @@ iperf_tcp_recv(struct iperf_stream * sp)
|
||||
* sends the data for TCP
|
||||
*/
|
||||
int
|
||||
iperf_tcp_send(struct iperf_stream * sp)
|
||||
iperf_tcp_send(struct iperf_stream *sp)
|
||||
{
|
||||
int result;
|
||||
int size = sp->settings->blksize;
|
||||
@ -90,24 +71,6 @@ iperf_tcp_send(struct iperf_stream * sp)
|
||||
}
|
||||
|
||||
|
||||
// XXX: This function is now deprecated
|
||||
/**************************************************************************/
|
||||
struct iperf_stream *
|
||||
iperf_new_tcp_stream(struct iperf_test * testp)
|
||||
{
|
||||
struct iperf_stream *sp;
|
||||
|
||||
sp = (struct iperf_stream *) iperf_new_stream(testp);
|
||||
if (!sp) {
|
||||
return (NULL);
|
||||
}
|
||||
sp->rcv = iperf_tcp_recv; /* pointer to receive function */
|
||||
sp->snd = iperf_tcp_send; /* pointer to send function */
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
|
||||
/* iperf_tcp_accept
|
||||
*
|
||||
* accept a new TCP stream connection
|
||||
@ -122,7 +85,7 @@ iperf_tcp_accept(struct iperf_test * test)
|
||||
struct sockaddr_in addr;
|
||||
|
||||
len = sizeof(addr);
|
||||
if ((s = accept(test->listener_tcp, (struct sockaddr *) &addr, &len)) < 0) {
|
||||
if ((s = accept(test->listener, (struct sockaddr *) &addr, &len)) < 0) {
|
||||
i_errno = IESTREAMCONNECT;
|
||||
return (-1);
|
||||
}
|
||||
@ -153,7 +116,7 @@ iperf_tcp_listen(struct iperf_test *test)
|
||||
{
|
||||
int s, opt;
|
||||
struct sockaddr_in sa;
|
||||
s = test->listener_tcp;
|
||||
s = test->listener;
|
||||
|
||||
if (test->no_delay || test->default_settings->mss) {
|
||||
FD_CLR(s, &test->read_set);
|
||||
@ -200,11 +163,7 @@ iperf_tcp_listen(struct iperf_test *test)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
test->listener_tcp = s;
|
||||
/*
|
||||
test->max_fd = (s > test->max_fd) ? s : test->max_fd;
|
||||
FD_SET(test->listener_tcp, &test->read_set);
|
||||
*/
|
||||
test->listener = s;
|
||||
}
|
||||
|
||||
return (s);
|
||||
@ -244,7 +203,7 @@ iperf_tcp_connect(struct iperf_test *test)
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
if (opt = test->default_settings->mss) {
|
||||
if ((opt = test->default_settings->mss)) {
|
||||
if (setsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, sizeof(opt)) < 0) {
|
||||
i_errno = IESETMSS;
|
||||
return (-1);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#ifndef IPERF_TCP_H
|
||||
#define IPERF_TCP_H
|
||||
|
||||
|
||||
/**
|
||||
* iperf_tcp_accept -- accepts a new TCP connection
|
||||
* on tcp_listener_socket for TCP data and param/result
|
||||
@ -14,7 +15,7 @@
|
||||
*returns 0 on success
|
||||
*
|
||||
*/
|
||||
int iperf_tcp_accept(struct iperf_test *);
|
||||
int iperf_tcp_accept(struct iperf_test *);
|
||||
|
||||
/**
|
||||
* iperf_tcp_recv -- receives the data for TCP
|
||||
@ -22,7 +23,7 @@ int iperf_tcp_accept(struct iperf_test *);
|
||||
*returns state of packet received
|
||||
*
|
||||
*/
|
||||
int iperf_tcp_recv(struct iperf_stream *);
|
||||
int iperf_tcp_recv(struct iperf_stream *);
|
||||
|
||||
|
||||
/**
|
||||
@ -31,7 +32,7 @@ int iperf_tcp_recv(struct iperf_stream *);
|
||||
* returns: bytes sent
|
||||
*
|
||||
*/
|
||||
int iperf_tcp_send(struct iperf_stream *);
|
||||
int iperf_tcp_send(struct iperf_stream *);
|
||||
|
||||
|
||||
int iperf_tcp_listen(struct iperf_test *);
|
||||
@ -39,7 +40,5 @@ int iperf_tcp_listen(struct iperf_test *);
|
||||
int iperf_tcp_connect(struct iperf_test *);
|
||||
|
||||
|
||||
struct iperf_stream *iperf_new_tcp_stream(struct iperf_test * testp);
|
||||
|
||||
#endif /* IPERF_TCP_H */
|
||||
#endif
|
||||
|
||||
|
@ -5,34 +5,19 @@
|
||||
* approvals from the U.S. Dept. of Energy). All rights reserved.
|
||||
*/
|
||||
|
||||
/* iperf_udp.c: UDP specific routines for iperf
|
||||
*
|
||||
* NOTE: not yet finished / working
|
||||
*/
|
||||
|
||||
// XXX: Do we really need all these headers?
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "iperf.h"
|
||||
#include "iperf_api.h"
|
||||
@ -40,7 +25,6 @@
|
||||
#include "iperf_error.h"
|
||||
#include "timer.h"
|
||||
#include "net.h"
|
||||
#include "locale.h"
|
||||
|
||||
|
||||
/* iperf_udp_recv
|
||||
@ -158,22 +142,6 @@ iperf_udp_send(struct iperf_stream *sp)
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
// XXX: This function is deprecated
|
||||
struct iperf_stream *
|
||||
iperf_new_udp_stream(struct iperf_test * testp)
|
||||
{
|
||||
struct iperf_stream *sp;
|
||||
|
||||
sp = (struct iperf_stream *) iperf_new_stream(testp);
|
||||
if (!sp) {
|
||||
return (NULL);
|
||||
}
|
||||
sp->rcv = iperf_udp_recv;
|
||||
sp->snd = iperf_udp_send;
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@ -184,7 +152,6 @@ iperf_new_udp_stream(struct iperf_test * testp)
|
||||
int
|
||||
iperf_udp_accept(struct iperf_test *test)
|
||||
{
|
||||
struct iperf_stream *sp;
|
||||
struct sockaddr_in sa_peer;
|
||||
int buf;
|
||||
socklen_t len;
|
||||
@ -202,18 +169,6 @@ iperf_udp_accept(struct iperf_test *test)
|
||||
i_errno = IESTREAMACCEPT;
|
||||
return (-1);
|
||||
}
|
||||
/*
|
||||
sp = test->new_stream(test);
|
||||
if (!sp)
|
||||
return (-1);
|
||||
sp->socket = s;
|
||||
if (iperf_init_stream(sp, test) < 0)
|
||||
return (-1);
|
||||
iperf_add_stream(test, sp);
|
||||
FD_SET(s, &test->read_set);
|
||||
FD_SET(s, &test->write_set);
|
||||
test->max_fd = (s > test->max_fd) ? s : test->max_fd;
|
||||
*/
|
||||
|
||||
test->prot_listener = netannounce(Pudp, NULL, test->server_port);
|
||||
if (test->prot_listener < 0) {
|
||||
|
@ -9,22 +9,13 @@
|
||||
#define __IPERF_UDP_H
|
||||
|
||||
|
||||
/**
|
||||
* iperf_udp_accept -- accepts a new UDP connection
|
||||
* on udp_listener_socket
|
||||
*returns 0 on success
|
||||
*
|
||||
*/
|
||||
int iperf_udp_accept(struct iperf_test *);
|
||||
|
||||
|
||||
/**
|
||||
* iperf_udp_recv -- receives the client data for UDP
|
||||
*
|
||||
*returns state of packet received
|
||||
*
|
||||
*/
|
||||
int iperf_udp_recv(struct iperf_stream *);
|
||||
int iperf_udp_recv(struct iperf_stream *);
|
||||
|
||||
/**
|
||||
* iperf_udp_send -- sends the client data for UDP
|
||||
@ -32,7 +23,7 @@ int iperf_udp_recv(struct iperf_stream *);
|
||||
* returns: bytes sent
|
||||
*
|
||||
*/
|
||||
int iperf_udp_send(struct iperf_stream *);
|
||||
int iperf_udp_send(struct iperf_stream *);
|
||||
|
||||
|
||||
/**
|
||||
@ -41,7 +32,7 @@ int iperf_udp_send(struct iperf_stream *);
|
||||
*returns 0 on success
|
||||
*
|
||||
*/
|
||||
int iperf_udp_accept(struct iperf_test *);
|
||||
int iperf_udp_accept(struct iperf_test *);
|
||||
|
||||
|
||||
int iperf_udp_listen(struct iperf_test *);
|
||||
@ -50,8 +41,6 @@ int iperf_udp_connect(struct iperf_test *);
|
||||
|
||||
int iperf_udp_init(struct iperf_test *);
|
||||
|
||||
struct iperf_stream *iperf_new_udp_stream(struct iperf_test * testp);
|
||||
|
||||
|
||||
#endif /* IPERF_UDP_H */
|
||||
#endif
|
||||
|
||||
|
@ -38,9 +38,7 @@ int iperf_run(struct iperf_test *);
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char ch, role;
|
||||
struct iperf_test *test;
|
||||
int port = PORT;
|
||||
|
||||
// XXX: Setting the process affinity requires root on most systems.
|
||||
// Is this a feature we really need?
|
||||
|
10
src/net.c
10
src/net.c
@ -25,7 +25,6 @@ netdial(int proto, char *client, int port)
|
||||
int s;
|
||||
struct hostent *hent;
|
||||
struct sockaddr_in sa;
|
||||
socklen_t sn;
|
||||
|
||||
/* XXX: This is not working for non-fully qualified host names use getaddrinfo() instead? */
|
||||
if ((hent = gethostbyname(client)) == 0) {
|
||||
@ -46,15 +45,6 @@ netdial(int proto, char *client, int port)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* XXX: Consider deleting
|
||||
sn = sizeof sa;
|
||||
|
||||
// XXX: Is there a reason to call getpeername() if none of the return values are used?
|
||||
if (getpeername(s, (struct sockaddr *) & sa, &sn) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
*/
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user