Permit specification of hostname in test1, test3
This commit is contained in:
parent
449c59abed
commit
4400f8e5bb
18
test1.c
18
test1.c
|
@ -25,9 +25,21 @@ int main(int argc, char *argv[]) {
|
|||
struct timeval start_time;
|
||||
long bytecount = -1;
|
||||
|
||||
s.sin_family = AF_INET;
|
||||
s.sin_addr.s_addr = htonl(0x7f000001);
|
||||
s.sin_port = htons(5671);
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: test1 <serverhostname>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
{
|
||||
struct hostent *h = gethostbyname(argv[1]);
|
||||
if (h == NULL) {
|
||||
fprintf(stderr, "serverhostname lookup: %d\n", h_errno);
|
||||
exit(1);
|
||||
}
|
||||
s.sin_family = AF_INET;
|
||||
s.sin_addr.s_addr = * (uint32_t *) h->h_addr_list[0];
|
||||
s.sin_port = htons(5671);
|
||||
}
|
||||
|
||||
if (connect(fd, (struct sockaddr *) &s, sizeof(s)) < 0) return 1;
|
||||
|
||||
|
|
18
test3.c
18
test3.c
|
@ -28,9 +28,21 @@ int main(int argc, char *argv[]) {
|
|||
size_t msglen = strlen(msg);
|
||||
int i;
|
||||
|
||||
s.sin_family = AF_INET;
|
||||
s.sin_addr.s_addr = htonl(0x7f000001);
|
||||
s.sin_port = htons(5671);
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: test1 <serverhostname>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
{
|
||||
struct hostent *h = gethostbyname(argv[1]);
|
||||
if (h == NULL) {
|
||||
fprintf(stderr, "serverhostname lookup: %d\n", h_errno);
|
||||
exit(1);
|
||||
}
|
||||
s.sin_family = AF_INET;
|
||||
s.sin_addr.s_addr = * (uint32_t *) h->h_addr_list[0];
|
||||
s.sin_port = htons(5671);
|
||||
}
|
||||
|
||||
if (connect(fd, (struct sockaddr *) &s, sizeof(s)) < 0) return 1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue