Skip to content

Commit

Permalink
Checking in trout files
Browse files Browse the repository at this point in the history
  • Loading branch information
maalvikabhat authored Feb 28, 2020
1 parent 7818afe commit 9cc1b03
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions exercises/ex04/trout/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "trout.h"

int main (int argc, char **argv)
{
int c;
struct addrinfo *ai;
char *host;

opterr = 0;
while ( (c = getopt (argc, argv, "m:")) != -1) {
switch (c) {
case 'm':
if ( (max_ttl = atoi(optarg)) <= 1) {
err_quit ("invalid -m value");
}
break;
default:
err_quit ("unrecognizd option: %c", c);
}
}

if (optind != argc - 1) {
err_quit ("usage: trout [ -m <maxttl>] <hostname>");
}
host = argv[optind];
ai = Host_serv (host, NULL, 0, 0);

printf ("trout to %s (%s): %d hops max, %d data bytes\n",
ai->ai_canonname,
Sock_ntop_host (ai->ai_addr, ai->ai_addrlen),
max_ttl, datalen);

if (ai->ai_family != AF_INET) {
err_quit ("unknown address family %d", ai->ai_family);
}

sasend = ai->ai_addr;
salen = ai->ai_addrlen;
sarecv = Calloc (1, salen);
salast = Calloc (1, salen);
sabind = Calloc (1, salen);

loop_ttl ();
exit (0);
}

0 comments on commit 9cc1b03

Please sign in to comment.