home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE2.TAR / udp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-02  |  2.2 KB  |  82 lines

  1. /*
  2.  * udp - Check if UDP traffic is allowed on this host; we open port 1527 on
  3.  *       a system (default of cs.widener.edu), which is expecting it; the
  4.  *       date is output (e.g. very similar to the daytime service).  This
  5.  *       will conclusively tell us if UDP traffic on ports > 1000 is allowed.
  6.  *
  7.  *    It should print out the date if UDP traffic's not blocked on your
  8.  *    system.  If it just hangs, try these tests too:
  9.  *      a. run it with -d  (e.g. "udp -d"); that goes to the normal UDP port
  10.  *         to print the date.  If it works, then you can be sure that any
  11.  *         UDP traffic > port 1000 is blocked on your system.
  12.  *      b. if it hangs too, try "telnet 147.31.254.130 13" and see if
  13.  *         _that_ prints the date; if it doesn't, it's another problem (your
  14.  *         network can't get to me, e.g.).
  15.  *
  16.  * Compile by: cc -o udp udp.c
  17.  *
  18.  * Brendan Kehoe, brendan@cs.widener.edu, Oct 1991.
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include <sys/types.h>
  23. #include <sys/socket.h>
  24. #include <netinet/in.h>
  25. #include <arpa/inet.h>
  26.  
  27. #define    SIZE    2048
  28. #define    HOST    "147.31.254.130"    /* cs.widener.edu */
  29. #define PORT    1527
  30.  
  31. main (argc, argv)
  32.      int argc;
  33.      char **argv;
  34. {
  35.   int s, len;
  36.   struct sockaddr_in server, sa;
  37.   char buf[SIZE];
  38.  
  39.   if ((s = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
  40.     {
  41.       perror ("socket()");
  42.       exit (1);
  43.     }
  44.  
  45.   bzero ((char *) &sa, sizeof (sa));
  46.   sa.sin_family = AF_INET;
  47.   sa.sin_addr.s_addr = htonl (INADDR_ANY);
  48.   sa.sin_port = htons (0);
  49.  
  50.   if (bind (s, (struct sockaddr *) &sa, sizeof (sa)) < 0)
  51.     {
  52.       perror ("bind()");
  53.       exit (1);
  54.     }
  55.  
  56.   bzero ((char *) &server, sizeof (server));
  57.   server.sin_family = AF_INET;
  58.   server.sin_addr.s_addr = inet_addr (HOST);
  59.   if (argc > 1 && strcmp(*(argv + 1), "-d") == 0)
  60.     server.sin_port = htons ((unsigned short) 13);
  61.   else
  62.     server.sin_port = htons ((unsigned short) PORT);
  63.  
  64.   /* yoo hoo, we're here .. */
  65.   if (sendto (s, "\n", 1, 0, &server, sizeof (server)) < 0)
  66.     {
  67.       perror ("sendto()");
  68.       exit (1);
  69.     }
  70.  
  71.   /* slurp */
  72.   len = sizeof (server);
  73.   if (recvfrom (s, buf, sizeof (buf), 0, &server, &len) < 0)
  74.     {
  75.       perror ("recvfrom");
  76.       exit (1);
  77.     }
  78.  
  79.   printf ("%s", buf);
  80.   close (s);
  81. }
  82.