자기 ip 주소 얻어오는 방법은?

tipirzch의 이미지

안녕하세요..

유동 ip 사용할때 자신의 ip를 얻어오는 프로그램을 짜고 있는데요..

여기 게시판에서 찾은 프로그램(밑에 있는)을 돌리면

계속 127.0.0.1만 나오네요..

gethostbyname함수는 /etc/host 파일을 참고해서 주소정보를

받아온다는데 그 파일을 찾아가면 127.0.0.1 밖에 없더군요...

실제 할당받은 ip주소를 얻을수 있는 방법은 없나요?

#include <netinet/in.h>
#include <sys/utsname.h>
#include <netdb.h>

/*
* Description : Current localhost IP
* Argument : addrtype - type of address (INET4 or INET6)
* Return : the hostent structure or a NULL pointer
*/
char **my_addrs(int *addrtype)
{
struct hostent *hptr;
struct utsname myname;

if (uname(&myname) < 0)
return NULL;

if ((hptr = gethostbyname(myname.nodename)) == NULL)
return NULL;

*addrtype = hptr->h_addrtype;

return (hptr->h_addr_list);
}

pynoos의 이미지