On Mon, 2002-06-17 at 15:10, Halil Demirezen wrote: > 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)); In any case, you're leaking a hostent structure here. > > 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; > > } Cheers, Christian. -- ________________________________________________________________________ http://www.whoop.org -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/