Modify bb_lookup_port to allow the protocol to be specified, allowing

/etc/services support for inetd, netcat and tftp.
This commit is contained in:
Glenn L McGrath
2004-01-17 05:03:31 +00:00
parent b03be7f567
commit 036dbaa082
8 changed files with 22 additions and 31 deletions

View File

@@ -61,7 +61,7 @@ int nc_main(int argc, char **argv)
do_listen++;
break;
case 'p':
lport = atoi(optarg);
lport = bb_lookup_port(optarg, "tcp", 0);
break;
case 'i':
delay = atoi(optarg);
@@ -96,7 +96,7 @@ int nc_main(int argc, char **argv)
if (lport != 0) {
memset(&address.sin_addr, 0, sizeof(address.sin_addr));
address.sin_port = htons(lport);
address.sin_port = lport;
if (bind(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
bb_perror_msg_and_die("bind");
@@ -117,7 +117,7 @@ int nc_main(int argc, char **argv)
hostinfo = xgethostbyname(argv[optind]);
address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
address.sin_port = htons(atoi(argv[optind+1]));
address.sin_port = bb_lookup_port(argv[optind+1], "tcp", 0);
if (connect(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
bb_perror_msg_and_die("connect");