exit().
Note that calling perror() after gethostbyname() will most likely return
"No such file or directory" which is quite confusing, so I decided to use
fatalError instead.
Regards,
Pavel Roskin
hostinfo = (struct hostent *) gethostbyname(*argv);
if (!hostinfo) {
- exit(1);
+ fatalError("nc: cannot resolve %s\n", *argv);
}
address.sin_family = AF_INET;
result = connect(sfd, (struct sockaddr *) &address, len);
if (result < 0) {
+ perror("nc: connect");
exit(2);
}
(struct timeval *) 0);
if (result < 1) {
+ perror("nc: select");
exit(3);
}
hostinfo = (struct hostent *) gethostbyname(*argv);
if (!hostinfo) {
- exit(1);
+ fatalError("nc: cannot resolve %s\n", *argv);
}
address.sin_family = AF_INET;
result = connect(sfd, (struct sockaddr *) &address, len);
if (result < 0) {
+ perror("nc: connect");
exit(2);
}
(struct timeval *) 0);
if (result < 1) {
+ perror("nc: select");
exit(3);
}