#include<stdio.h>
#include<stdlib.h>
#include<arpa/inet.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<string.h>
int main(int argc, char** argv)
{
// char *serv_port = "8080";
char *str;
struct sockaddr_in addr_ip_address;
socket(PF_INET,SOCK_STREAM,0);
memset(&addr_ip_address, 0, sizeof(addr_ip_address));
addr_ip_address.sin_family = AF_INET;
addr_ip_address.sin_addr.s_addr = htonl(INADDR_ANY);
printf("INADDR_ANY : %s\n",INADDR_ANY);
str = inet_ntoa(addr_ip_address.sin_addr);
printf("%s\n", str);
return 0;
}
========================================================================================[judgementday@localhost network_programming]$ ./ip_address
INADDR_ANY : (null)
0.0.0.0
========================================================================================
INADDR_ANY 은 localhost인데 자신의 IP가 아닌 ox0000~으로 되어있다. INADDR_ANY로 주소를 잡아주면 커널(OS)이 그 주소를 잡아주는게 아니라 0.0.0.0으로 대기중에 있다가 connect(클라이언트)에서 특정 서버로 접속하면 소켓이 바인드 된다.
한동안 손 놓고 있다가 다시 볼려니 뭔지 잘 모르겠다.
이런, 바보!! ㅠ
[출처 : http://blog.naver.com/kernoarsid02]