![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to read the data from an excel sheet and use those data as variable in the unix c | Anne Grace | UNIX for Advanced & Expert Users | 1 | 03-03-2008 04:21 AM |
| how to verify that copied data to remote system is identical with local data. | ynilesh | Shell Programming and Scripting | 3 | 01-31-2008 05:55 AM |
| Howto capture data from rs232port andpull data into oracle database-9i automatically | boss | UNIX for Dummies Questions & Answers | 1 | 09-22-2007 11:35 PM |
| Using loop reading a file,retrieving data from data base. | Sonu4lov | Shell Programming and Scripting | 1 | 01-19-2007 12:38 AM |
| Convert Binary data to ascii data | krishna | UNIX for Advanced & Expert Users | 4 | 11-05-2004 01:12 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to Get the hostent data
Hi,
I am trying to write a program, to find the open port on any system. Rightnow, my programm is working fine on the same system ip. Now, i want to enhanced it to get any IP address and perform the task. Problem is that, i have only IP address, like "111:111:111:111". From this how to get the struct hostent *he; I have tried with the following code //he = gethostbyname( compName ); unsigned int addr = inet_addr("111:111:111:111"); hostent *he = gethostbyaddr((char *) &addr, 4, AF_INET); But getgostbyaddress is returning NULL. Any body help me. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
111:111:111:111 is not a valid IPv4 address. Try 127.0.0.1 instead, for a start. (That's localhost so it will connect to your own box anyway.)
|
|
#3
|
|||
|
|||
|
That IP addess is as exapmle. i am giving my IP address which given by ipconfig command. Assume it 72.14.253.125 .
|
|
#4
|
|||
|
|||
|
Seems you should put the return value from inet_addr in addr.s_addr.
./ettercap-0.5.0/src/ec_inet.c - Google Code Search |
|
#5
|
|||
|
|||
|
I tried the code fromm link.
struct in_addr addr; addr.s_addr = inet_addr( "121.243.2231.133" ); he = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET); Again he is NULL>\. |
|
#6
|
|||
|
|||
|
Again, that is not a valid IP address.
I wrote a quick test program and got it to run successfully. Code:
vnix$ ./a.out 72.14.253.125 in_addr: 72.14.253.125 po-in-f125.google.com Code:
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <errno.h>
int main (int argc, char *argv[])
{
struct in_addr addr;
struct hostent *he;
/* printf ("sizeof struct in_addr: %i\n", sizeof(struct in_addr)); */
printf ("in_addr: %s\n", argv[1]);
addr.s_addr = inet_addr(argv[1]);
if (addr.s_addr == 0 || addr.s_addr == -1)
{
perror ("inet_addr");
return 1;
}
/* else */
he = gethostbyaddr (&addr, 4, AF_INET);
if (he == NULL)
{
perror ("gethostbyaddr");
switch (h_errno)
{
case HOST_NOT_FOUND: printf ("HOST_NOT_FOUND\n"); break;
case NO_ADDRESS: printf ("NO_ADDRESS\n"); break;
/* case NO_DATA: print ("NO_DATA\n"); break; */
case NO_RECOVERY: printf ("NO_RECOVERY\n"); break;
case TRY_AGAIN: printf ("TRY_AGAIN\n"); break;
}
return 1;
}
/* else */
printf ("%s\n", he->h_name);
return 0;
}
|
|
#7
|
|||
|
|||
|
yes, u are right. It was a typo. Thanks to point out it.
Now it's working fine... |
|||
| Google The UNIX and Linux Forums |