1: /*
   2: ** A small test program. If run without any arguments, it should
   3: ** return *your* user name if the machine it is run on has a correctly
   4: ** installed and running Ident server.
   5: **
   6: ** Last modified: 11 August 1993 by Michael Kuch
   7: **
   8: ** Author: Peter Eriksson <pen@lysator.liu.se>
   9: */
  10: 
  11: #include <stdio.h>
  12: #include <sys/time.h>
  13: #include <sys/types.h>
  14: #include <sys/socket.h>
  15: #include <netinet/in.h>
  16: #include <arpa/inet.h>
  17: #include <ctype.h>
  18: 
  19: 
  20: int Toupper(c)
  21:   int c;
  22: {
  23:   if (islower(c))
  24:     return toupper(c);
  25:   else
  26:     return c;
  27: }
  28: 
  29: 
  30: /*
  31: ** Compare two strings, case insensitive
  32: */
  33: int Stricmp(s1, s2)
  34:   char *s1, *s2;
  35: {
  36:   int diff;
  37: 
  38: 
  39:   while (!(diff = Toupper(*s1) - Toupper(*s2)) && *s1)
  40:     s1++, s2++;
  41: 
  42:   return diff;
  43: }
  44: 
  45: 
  46: Perror(str)
  47:   char *str;
  48: {
  49:   perror(str);
  50:   exit(1);
  51: }
  52: 
  53: 
  54: main(argc,argv)
  55:   int argc;
  56:   char *argv[];
  57: {
  58:   int fd;
  59:   struct sockaddr_in addr;
  60:   int addrlen;
  61:   int port;
  62:   FILE *fp_in, *fp_out;
  63:   int lport, fport;
  64:   char buffer[8192];
  65:   char *cp;
  66:   char reply_type[81];
  67:   char opsys_or_error[81];
  68:   char identifier[1024];
  69: 
  70: 
  71:   if (argc > 3)
  72:   {
  73:     printf("usage: %s [{host-ip-number} [{port number}]]", argv[0]);
  74:     exit(1);
  75:   }
  76: 
  77:   fd = socket(AF_INET, SOCK_STREAM, 0);
  78:   if (fd == -1)
  79:     Perror("socket");
  80: 
  81:   addr.sin_family = AF_INET;
  82:   if(argc > 1)
  83:     addr.sin_addr.s_addr = inet_addr(argv[1]);
  84:   else
  85:     addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  86: 
  87:   if (argc > 2)
  88:     port = atoi(argv[2]);
  89:   else
  90:     port = 113;
  91: 
  92:   addr.sin_port = htons(port);
  93:   addrlen = sizeof(addr);
  94: 
  95:   if (connect(fd, &addr, addrlen) == -1)
  96:     Perror("connect");
  97: 
  98:   addrlen = sizeof(addr);
  99:   if (getsockname(fd, &addr, &addrlen) == -1)
 100:     Perror("getsockname");
 101: 
 102:   fp_in  = fdopen(fd, "r");
 103:   fp_out = fdopen(fd, "w");
 104:   if (!fp_in || !fp_out)
 105:     Perror("fdopen");
 106: 
 107:   fprintf(fp_out, "%d , %d\n", ntohs(addr.sin_port), port);
 108:   fflush(fp_out);
 109: 
 110:   if (fgets(buffer, sizeof(buffer)-1, fp_in) == NULL)
 111:     Perror("fgets");
 112: 
 113:   shutdown(fd, 1);
 114: 
 115:   cp = buffer;
 116:   while (*cp != 0 && (*cp < ' ' || isspace(*cp)))
 117:       ++cp;
 118: 
 119:   argc = sscanf(cp, "%d , %d : %[^ \t\n\r:] : %[^\t\n\r:] : %[^\n\r]",
 120:         &lport, &fport, reply_type, opsys_or_error, identifier);
 121:   if (argc < 3)
 122:   {
 123:     fprintf(stderr, "sscanf: too few arguments (%d)\n", argc);
 124:     exit(1);
 125:   }
 126:   if (Stricmp(reply_type, "ERROR") == 0)
 127:   {
 128:     printf("Ident error: error code: %s\n", opsys_or_error);
 129:     exit(1);
 130:   }
 131:   else if (Stricmp(reply_type, "USERID") != 0)
 132:   {
 133:     printf("Ident error: illegal reply type: %s\n", reply_type);
 134:     exit(1);
 135:   }
 136:   else
 137:     printf("Ident returned:\n");
 138:     printf("\tOpsys and Charset (if -c specified for identd) = %s\n",
 139:                  opsys_or_error);
 140:     printf("\tIdentifier: %s\n", identifier);
 141: 
 142:   fclose(fp_out);
 143:   fclose(fp_in);
 144: 
 145:   exit(0);
 146: }

Defined functions

Perror defined in line 46; used 5 times
Stricmp defined in line 33; used 2 times
Toupper defined in line 20; used 2 times
  • in line 39(2)
main defined in line 54; never used
Last modified: 1995-06-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3187
Valid CSS Valid XHTML 1.0 Strict