mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Call WSAStartup and WSACleanup.
svn path=/trunk/; revision=12995
This commit is contained in:
parent
f68079aff3
commit
40847c3fd3
1 changed files with 29 additions and 1 deletions
|
@ -425,6 +425,14 @@ main(argc, argv)
|
||||||
struct protoent *pe;
|
struct protoent *pe;
|
||||||
struct sockaddr_in from, *to;
|
struct sockaddr_in from, *to;
|
||||||
int ch, i, on, probe, seq, tos, ttl;
|
int ch, i, on, probe, seq, tos, ttl;
|
||||||
|
WSADATA wsadata;
|
||||||
|
INT status;
|
||||||
|
|
||||||
|
status = WSAStartup(MAKEWORD(2, 2), &wsadata);
|
||||||
|
if (status != 0) {
|
||||||
|
printf("Could not initialize winsock dll.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
on = 1;
|
on = 1;
|
||||||
seq = tos = 0;
|
seq = tos = 0;
|
||||||
|
@ -439,6 +447,7 @@ main(argc, argv)
|
||||||
if (max_ttl <= 1) {
|
if (max_ttl <= 1) {
|
||||||
Fprintf(stderr,
|
Fprintf(stderr,
|
||||||
"traceroute: max ttl must be >1.\n");
|
"traceroute: max ttl must be >1.\n");
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -450,6 +459,7 @@ main(argc, argv)
|
||||||
if (port < 1) {
|
if (port < 1) {
|
||||||
Fprintf(stderr,
|
Fprintf(stderr,
|
||||||
"traceroute: port must be >0.\n");
|
"traceroute: port must be >0.\n");
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -458,6 +468,7 @@ main(argc, argv)
|
||||||
if (nprobes < 1) {
|
if (nprobes < 1) {
|
||||||
Fprintf(stderr,
|
Fprintf(stderr,
|
||||||
"traceroute: nprobes must be >0.\n");
|
"traceroute: nprobes must be >0.\n");
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -476,6 +487,7 @@ main(argc, argv)
|
||||||
if (tos < 0 || tos > 255) {
|
if (tos < 0 || tos > 255) {
|
||||||
Fprintf(stderr,
|
Fprintf(stderr,
|
||||||
"traceroute: tos must be 0 to 255.\n");
|
"traceroute: tos must be 0 to 255.\n");
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -487,6 +499,7 @@ main(argc, argv)
|
||||||
if (waittime <= 1) {
|
if (waittime <= 1) {
|
||||||
Fprintf(stderr,
|
Fprintf(stderr,
|
||||||
"traceroute: wait must be >1 sec.\n");
|
"traceroute: wait must be >1 sec.\n");
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -515,6 +528,7 @@ main(argc, argv)
|
||||||
} else {
|
} else {
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"traceroute: unknown host %s\n", *argv);
|
"traceroute: unknown host %s\n", *argv);
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,12 +538,14 @@ main(argc, argv)
|
||||||
Fprintf(stderr,
|
Fprintf(stderr,
|
||||||
"traceroute: packet size must be 0 <= s < %ld.\n",
|
"traceroute: packet size must be 0 <= s < %ld.\n",
|
||||||
MAXPACKET - sizeof(struct opacket));
|
MAXPACKET - sizeof(struct opacket));
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
datalen += sizeof(struct opacket);
|
datalen += sizeof(struct opacket);
|
||||||
outpacket = (struct opacket *)malloc((unsigned)datalen);
|
outpacket = (struct opacket *)malloc((unsigned)datalen);
|
||||||
if (! outpacket) {
|
if (! outpacket) {
|
||||||
perror("traceroute: malloc");
|
perror("traceroute: malloc");
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
(void) bzero((char *)outpacket, datalen);
|
(void) bzero((char *)outpacket, datalen);
|
||||||
|
@ -542,10 +558,12 @@ main(argc, argv)
|
||||||
|
|
||||||
if ((pe = getprotobyname("icmp")) == NULL) {
|
if ((pe = getprotobyname("icmp")) == NULL) {
|
||||||
Fprintf(stderr, "icmp: unknown protocol\n");
|
Fprintf(stderr, "icmp: unknown protocol\n");
|
||||||
|
WSACleanup();
|
||||||
exit(10);
|
exit(10);
|
||||||
}
|
}
|
||||||
if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) {
|
if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) {
|
||||||
perror("traceroute: icmp socket");
|
perror("traceroute: icmp socket");
|
||||||
|
WSACleanup();
|
||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
if (options & SO_DEBUG)
|
if (options & SO_DEBUG)
|
||||||
|
@ -557,12 +575,14 @@ main(argc, argv)
|
||||||
|
|
||||||
if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
|
if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
|
||||||
perror("traceroute: raw socket");
|
perror("traceroute: raw socket");
|
||||||
|
WSACleanup();
|
||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
#ifdef SO_SNDBUF
|
#ifdef SO_SNDBUF
|
||||||
if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&datalen,
|
if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&datalen,
|
||||||
sizeof(datalen)) < 0) {
|
sizeof(datalen)) < 0) {
|
||||||
perror("traceroute: SO_SNDBUF");
|
perror("traceroute: SO_SNDBUF");
|
||||||
|
WSACleanup();
|
||||||
exit(6);
|
exit(6);
|
||||||
}
|
}
|
||||||
#endif /* SO_SNDBUF */
|
#endif /* SO_SNDBUF */
|
||||||
|
@ -570,6 +590,7 @@ main(argc, argv)
|
||||||
if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, (char *)&on,
|
if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, (char *)&on,
|
||||||
sizeof(on)) < 0) {
|
sizeof(on)) < 0) {
|
||||||
perror("traceroute: IP_HDRINCL");
|
perror("traceroute: IP_HDRINCL");
|
||||||
|
WSACleanup();
|
||||||
exit(6);
|
exit(6);
|
||||||
}
|
}
|
||||||
#endif /* IP_HDRINCL */
|
#endif /* IP_HDRINCL */
|
||||||
|
@ -586,12 +607,14 @@ main(argc, argv)
|
||||||
from.sin_addr.s_addr = inet_addr(source);
|
from.sin_addr.s_addr = inet_addr(source);
|
||||||
if (from.sin_addr.s_addr == -1) {
|
if (from.sin_addr.s_addr == -1) {
|
||||||
Printf("traceroute: unknown host %s\n", source);
|
Printf("traceroute: unknown host %s\n", source);
|
||||||
|
WSACleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
outpacket->ip.ip_src = from.sin_addr;
|
outpacket->ip.ip_src = from.sin_addr;
|
||||||
#ifndef IP_HDRINCL
|
#ifndef IP_HDRINCL
|
||||||
if (bind(sndsock, (struct sockaddr *)&from, sizeof(from)) < 0) {
|
if (bind(sndsock, (struct sockaddr *)&from, sizeof(from)) < 0) {
|
||||||
perror ("traceroute: bind:");
|
perror ("traceroute: bind:");
|
||||||
|
WSACleanup();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
#endif /* IP_HDRINCL */
|
#endif /* IP_HDRINCL */
|
||||||
|
@ -664,11 +687,16 @@ main(argc, argv)
|
||||||
(void) fflush(stdout);
|
(void) fflush(stdout);
|
||||||
}
|
}
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
if (got_there || unreachable >= nprobes-1)
|
if (got_there || unreachable >= nprobes-1) {
|
||||||
|
WSACleanup();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WSACleanup();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
wait_for_reply(sock, from)
|
wait_for_reply(sock, from)
|
||||||
int sock;
|
int sock;
|
||||||
|
|
Loading…
Reference in a new issue