// things like prototype "nbd-client_main" which isn't a valid symbol. So
// we hide the underscore name and OLDTOY the name we want.
USE_NBD_CLIENT(NEWTOY(nbd_client, "<3>3ns", 0))
-USE_NBD_CLIENT(OLDTOY(nbd-client, nbd_client, OPTSTR_nbd_client, TOYFLAG_USR|TOYFLAG_BIN))
+USE_NBD_CLIENT(OLDTOY(nbd-client, nbd_client, TOYFLAG_USR|TOYFLAG_BIN))
config NBD_CLIENT
bool "nbd-client"
+ depends on TOYBOX_FORK
default y
help
usage: nbd-client [-ns] HOST PORT DEVICE
{
int sock = -1, nbd, flags;
unsigned long timeout = 0;
- struct addrinfo *addr, *p;
char *host=toys.optargs[0], *port=toys.optargs[1], *device=toys.optargs[2];
uint64_t devsize;
nbd = xopen(device, O_RDWR);
for (;;) {
int temp;
- struct addrinfo hints;
// Find and connect to server
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- if (getaddrinfo(host, port, &hints, &addr)) addr = 0;
- for (p = addr; p; p = p->ai_next) {
- sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
- if (-1 != connect(sock, p->ai_addr, p->ai_addrlen)) break;
- close(sock);
- }
- freeaddrinfo(addr);
-
- if (!p) perror_exit("%s:%s", host, port);
-
+ sock = xconnect(host, port, AF_UNSPEC, SOCK_STREAM, 0, 0);
temp = 1;
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &temp, sizeof(int));