04-28-2002
Quote:
Originally posted by S.P.Prasad
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
main ( )
{
char Buf [ 200 ] ;
struct hostent * Host = (struct hostent * ) malloc ( sizeof ( struct hostent ))
;
gethostname ( Buf , 200 ) ;
printf ( "%s\n", Buf ) ;
Host = ( struct hostent * ) gethostbyname ( Buf ) ;
printf ( "The name :: %s\n" , Host->h_name ) ;
printf("IP Address : %s\n", inet_ntoa(*((struct in_addr *)Host->h_addr)));
}
This module correctly prints the address.
------------------------------------------------------------------------
Thank you !!
but, result is incorect.
ha1
The name :: ha1
IP Address : 255.255.255.255
result is same.
9 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
say I have a IP address which is 10.0.0.12, and subnet mask is 255.255.255.240, what is the network address and what is the broadcast address which host lives on?
And could you explain how to get the answer?
thanx in advance! (7 Replies)
Discussion started by: pnxi
7 Replies
2. IP Networking
Hi sir,
i want to make such programe which takes MAC(Ethernet) address of any host & give me its IP address.......
but i'm nt getting that how i can pass the MAC address to Frame........
Please give me an idea for making such program...
Thanks & regards
Krishna (3 Replies)
Discussion started by: krishnacins
3 Replies
3. Shell Programming and Scripting
Trying to do a ksh script that needs to list all ip address between ip address a and b ..
ie.
Ip address A=192.168.1.200
Ip address B=192.168.2.15
So the subnet changes from 1 to 2 but I want to list all possible ip addresses between the 2..
Which would be:
192.168.1.200... (4 Replies)
Discussion started by: frustrated1
4 Replies
4. UNIX for Dummies Questions & Answers
:) Firstly Hi all!!, im NEW!! and on here hoping that someone might be able to offer me some help... i have a server that keeps crashing every few days with the error message:
PANIC KERNAL-MODE ADDRESS FAULT ON USER ADDRESS 0X14
KERNAL PAGE FAULT FROM (CS:EIP)=(100:EF71B5BD)
EAX=EF822000... (10 Replies)
Discussion started by: Twix
10 Replies
5. Solaris
I have following message in my messages file on solaris 10
WARNING: e1000g3712000:3 has duplicate address 010.022.196.011 (in use by 00:50:56:85:25:ef); disabled
Now is there any way i can find which server has 00:50:56:85:25:ef mac address either IP or Hostname ? (6 Replies)
Discussion started by: fugitive
6 Replies
6. UNIX for Dummies Questions & Answers
Hi guys,
I got one problem which I definetily no idea.
What would the physical address be for virtual address?
1) 2ABC
2) 3F4B
Here is the page table:see attached
Thank you sos sososososso much!! (0 Replies)
Discussion started by: lemon_06
0 Replies
7. IP Networking
Hi there
I lost connectivity to one of our remote systems and when I checked the messages log I found the following:
Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s
Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1
Aug 16 13:20:51 host... (9 Replies)
Discussion started by: notreallyhere
9 Replies
8. UNIX for Advanced & Expert Users
Hi ,
Could someone let me know how to detect duplicate ip address after assigning ip address to ethernet interface using c program (3 Replies)
Discussion started by: Gopi Krishna P
3 Replies
9. IP Networking
four interfaces with ifconfig
all interfaces have the same mac. If is not set for unique.
but it still works.
what difference does it make to have all macs the same or different? (4 Replies)
Discussion started by: rrodgers
4 Replies
LEARN ABOUT ULTRIX
endhostent
gethostent(3n) gethostent(3n)
Name
gethostent, gethostbyaddr, gethostbyname, sethostent, endhostent - get hosts entry
Syntax
#include <netdb.h>
struct hostent *gethostent()
struct hostent *gethostbyname(name)
char *name;
struct hostent *gethostbyaddr(addr, len, type)
char *addr; int len, type;
void sethostent(stayopen)
int stayopen;
void endhostent()
Description
The and subroutines return a pointer to an object with the following structure containing the broken-out fields reflecting information
obtained from the database.
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
#define h_addr h_addr_list[0] /* address for backward compatibility */
};
The members of this structure are:
h_name Official name of the host.
h_aliases A zero terminated array of alternate names for the host.
h_addrtype The type of address being returned; currently always AF_INET.
h_length The length, in bytes, of the address.
h_addr A pointer to the network address for the host. Host addresses are returned in network byte order.
If the stayopen flag on a subroutine is NULL, the hosts database is opened. Otherwise the has the effect of rewinding the database. The
may be called to close the database when processing is complete.
The subroutine simply reads the next line while and search until a matching name, or addr, len, type is found (or until EOF is encoun-
tered). The subroutine keeps a pointer in the database, allowing successive calls to be used to search the entire file.
The and subroutines query the database.
A call to must be made before a loop using in order to perform initialization and an must be used after the loop. Both and make calls to
and
Restrictions
All information is contained in a static area so it must be copied if it is to be saved. Only the Internet address format is currently
understood.
If YP is running, does not return the entries in any particular order. See the Guide to the Yellow Pages Service for setup information.
The database may also be distributed via the BIND/Hesiod naming service. See the Guide to the BIND/Hesiod Service for more information.
Return Values
Null pointer(0) returned on EOF or error.
Files
See Also
hosts(5), svc.conf(5)
Guide to the BIND/Hesiod Service
Guide to the Yellow Pages Service
gethostent(3n)