*/
-#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/time.h>
#include <sys/ioctl.h>
+#include "busybox.h"
int nc_main(int argc, char **argv)
{
lport = atoi(optarg);
break;
default:
- usage(nc_usage);
+ show_usage();
}
}
if ((do_listen && optind != argc) || (!do_listen && optind + 2 != argc))
- usage(nc_usage);
+ show_usage();
if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
perror_msg_and_die("socket");
}
if (do_listen) {
+ socklen_t addrlen = sizeof(address);
+
if (listen(sfd, 1) < 0)
perror_msg_and_die("listen");
- if ((tmpfd = accept(sfd, (struct sockaddr *) &address, &opt)) < 0)
+ if ((tmpfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0)
perror_msg_and_die("accept");
close(sfd);
sfd = tmpfd;
} else {
- if ((hostinfo = gethostbyname(argv[optind])) == NULL)
- error_msg_and_die("cannot resolve %s\n", argv[optind]);
+ hostinfo = xgethostbyname(argv[optind]);
address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
address.sin_port = htons(atoi(argv[optind+1]));