#include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { u_short port; /* user specified port number */ char addr[1023]; /* will be a copy of address entered by u */ struct sockaddr_in address; /* the libc network address data structure */ short int sock = -1; /* file descriptor for the network socket */ port = atoi(argv[1]); /* addr = strncpy(addr, argv[2], 1023); */ strncpy(addr, argv[2], 1023); bzero((char *) &address, sizeof(address)); /* init addr struct */ address.sin_addr.s_addr = inet_addr(addr); /* assign the address */ address.sin_port = htons(port); /* translate int2port num */ sock = socket(AF_INET, SOCK_STREAM, 0); if (connect(sock, (struct sockaddr *) &address, sizeof(address)) == 0) printf("%i is open on %s\n", port, argv[2]); if (errno == 113) fprintf(stderr, "F*^k - no route to host\n"); close(sock); return 0; }