home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <process.h>
- #include <string.h>
- #include <winsock.h>
-
- void disp_help()
-
- {
-
- printf("\nHop Check program V 1.0 by L. Kahn (C) 1994\n");
- printf("_____________________________________________\n\n");
- printf("Syntax: hopcheck hostname \n");
- printf("WHERE: hostname is the name or ip address of a host.\n\n");
- printf("This program will get the ip address (if possible) and\n");
- printf("pass this address to (call) the tracert.exe program.\n");
- fflush(stdout);
- }
-
-
-
-
- void main(argc,argv)
-
- int argc;
- char **argv;
-
- {
-
-
- WORD wVersionrequired;
- WSADATA WSData;
- char remotename[80];
- static struct sockaddr_in destination;
- static struct hostent *ptrhostentry;
- struct in_addr *pin_addr;
- int rval = 0;
-
- wVersionrequired = MAKEWORD(1,1);
- if (argc != 2)
- disp_help();
-
- else
- {
- /* ok assume second arg is host name */
-
- rval = WSAStartup(wVersionrequired, &WSData);
- if (rval != 0)
- {
- printf("Startup ERROR: could not find a usable a winsock DLL.\n");
- fflush(stdout);
- exit(1);
- }
-
- if (LOBYTE(WSData.wVersion) != 1 || HIBYTE(WSData.wVersion) != 1)
- {
- printf("Startup ERROR: could not find a winsock DLL version 1.1 or newer.\n");
- fflush(stdout);
- exit(1);
- }
-
- else
- {
- strcpy(remotename,argv[1]);
- memset(&destination,0,sizeof(struct sockaddr));
- destination.sin_family=AF_INET;
-
- destination.sin_addr.s_addr = inet_addr(remotename);
- if(destination.sin_addr.s_addr ==INADDR_NONE)
- {
- ptrhostentry = gethostbyname(remotename);
- if (ptrhostentry == NULL)
- {
- printf("can't get entry for host name: %s\n",remotename);
- fflush(stdout);
- WSACleanup();
- exit(1);
- }
- }
- else
- {
- ptrhostentry = gethostbyaddr((LPSTR)&destination.sin_addr.s_addr,4,PF_INET);
- if (ptrhostentry == NULL)
- {
- printf("can't get ip entry for host name: %s\n",remotename);
- fflush(stdout);
- WSACleanup();
- exit(1);
- }
- }
-
- /* if we get here we have valid entry so do it */
-
- memcpy(&destination.sin_addr,ptrhostentry->h_addr,ptrhostentry->h_length);
- printf("Translated Name is: %s\n",ptrhostentry->h_name);
-
- /* only do trace route on first address returned */
- pin_addr = (struct in_addr *)*(ptrhostentry->h_addr_list);
- if (pin_addr != NULL)
- {
- char ipaddr[20];
- int rv = 0;
- char command_string[100];
- strcpy(ipaddr,inet_ntoa(*pin_addr));
- printf("Calling tracert on IP Address: %s\n",ipaddr);
- /* do the system call */
- strcpy(command_string,"tracert.exe ");
- strcat(command_string,ipaddr);
- rv = system(command_string);
- }
-
- } /* end of ok startup */
- } /* end of ok parameters */
-
- fflush(stdout);
- WSACleanup();
-
- } /* end of main */
-
-
-