Thread: Router Information

  1. #1
    Registered User
    Join Date
    May 2007

    Router Information

    Hello everyone,

    I have made this function to determine if the user has a router or not, is this a good method for retrieving IP, any feedback is appreciated.

    	BYTE r = RouterCheck();
    	if(r == 10 || r == 192) {
           //Found Router IP, Retrieve IP via or some other online website for retrieving IP.
    BYTE RouterCheck() {
    	WORD wVersionRequested;
    	WSADATA wsaData;
    	char name[255];
    	char ip[16], fip[4];
    	PHOSTENT hostinfo;
    	wVersionRequested = MAKEWORD( 2, 0 );
    	if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) {
    		if( gethostname ( name, sizeof(name)) == 0) {
    			if((hostinfo = gethostbyname(name)) != NULL) {
    				strcpy(ip, inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list));
    		else {
    			return NULL;
    	else return NULL;
    	char *p;
    	p = strchr(ip, '.');
    	if(p == NULL) return NULL; //p-ip
    	strncpy(fip, ip, p-ip);
    	return (BYTE)atoi(fip);

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    The strncpy function copies the initial count characters of strSource to strDest and returns strDest. If count is less than or equal to the length of strSource, a null character is not appended automatically to the copied string.
    and you pass its result as is to atoi. You have no crash yet? Lucky you...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    and you assume they dont have a static IP....

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Banks of the River Styx
    To the original poster: Not quite. A valid internet IP is - you must check for both 192 and the 168. However, just checking for a leading 10 is OK. ( The ranges are 10.* and 192.168.* ) There are actually two other ranges of private IPs, which you should probably be checking for. See the wikipedia article: IPv4 - Private Networks. Also, be aware that sites such as "what's my ip" may not like automated hits. (And future changes in page layout could break your application.) Some of these sites, however, do provide an interface for bots/programs, but limit the number of hits per day. You could also run a simple server yourself to report back IPs.
    Quote Originally Posted by
    We are currently processing over 500,000 client requests per day and are not interested in serving up the full page to those requests. Something about an extra 30+ GB of bandwidth a month is not appealing to us. If you would like to utilize our site's service for automated lookups we are willing to work with you.
    Quote Originally Posted by abachler
    and you assume they dont have a static IP....
    How/where does he make this assumption? If an ISP assigns static IPs, they shouldn't be in the private address ranges he's checking for.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    he is checking if they HAVE a router by assuming that anyone with an IP in the private address ranges has a router, btu his unstated counter assumption is that anyone that doesnt have a private IP doesnt have a router, which is not necessarily the case.

    Just because my IP isnt in 192.168.x.x or one of the other private networks, doesnt mean I dont have a router/switch/bridge.

    and just because my IP IS in one of the private networks doesnt mean I DO have a router, since it could be a truly private network.
    Last edited by abachler; 05-31-2007 at 02:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. fsckin router
    By RoD in forum Tech Board
    Replies: 8
    Last Post: 01-23-2005, 12:42 PM
  3. Damn router
    By RoD in forum Tech Board
    Replies: 7
    Last Post: 05-04-2004, 02:27 PM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM