Re: incorrect hostaddress

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




what about changing the code adding the following in the resent lines


On 17 Jun 2002, Murgan   wrote:

> Please look at the snippet and tell why it is not giving the
> correct ip address in dotted decimal. my system is not multihomed
> as ifconfig gives only one inet address for the eth0( the only
> interface except lo).
>
> #include<stdio.h>
> #include<sys/utsname.h>
> #include<malloc.h>
> #include<netdb.h>
> #include<sys/socket.h>
>
> int main(){
        struct sockaddr_in sin;
>  	struct utsname *name;
>  	int i;
>  	struct hostent *hnt;
>  	name = (struct utsname *)malloc(sizeof(struct utsname));
>  	hnt = (struct hostent *)malloc(sizeof(struct hostent));
>  	i= uname(name);
>  	hnt = gethostbyname(name->nodename);
>  	if(i>=0){
                bcopy(hnt->h_addr, (char *)&sin.sin_addr, hnt->h_length);
       		printf("Network address:\t%s\n",inet_ntoa(sin.sin_addr.s_addr));
        }
>  	return;
> }
>
> The name->nodename gives the correct hostname.
> If it is wrong how do I get the correct ip address for my
> localhost.
> Pardon me if something like this has been asked but I am a newbie
> and I am stuck here.
> Thanking you
> Murgan
> _________________________________________________________
> Click below to visit monsterindia.com and there is always a
> better job for you at http://monsterindia.rediff.com/jobs
>
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
>

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux