i am experimenting with unix sockets and having some fun. i thought it would be good if i joined these forums to ask some questions....
so my first code sample is this...
now i know your are all laffing at how ugly and poorly coded this is but keep in mind that i aint that advanced. it keeps printf()'ing me that i am connecting on port 56 or 55 or whatever it is it's not argv. any ideas? also you can see i am trying to create a telnet typeof utility so if you could maybe direct me as what to do that'd be great. thx guys
int main(int argc, char *argv)
struct hostent *h;
if (argc != 3)
fprintf(stderr, "Usage: tel [HOST] [IP]\n");
h = gethostbyname(argv);
if (h == NULL)
char *ip = inet_ntoa(*((struct in_addr *)h->h_addr));
int port = *argv;
printf("IP : %s\n", ip);
printf("Port: %d\n", port);
struct sockaddr_in dest_addr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(port);
dest_addr.sin_addr.s_addr = inet_addr( ip);
connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
oh and btw i use linux with g++ to compile and it compiles fine.