728x90
반응형
inet_addr, inet_ntoa #define _WINSOCK_DEPRECATED_NO_WARNINGS 사용하지 않고 함수로 해결하기
클라이언트 inet_addr = inet_pton = inet_pton //문자열을 long type으로 바꾸어 줌
서버 inet_ntoa =inet_ntop =inet_ntop //long type을 문자열로 바꾸어 줌
pton : PC -> 네트워크
ntop : 네트워크 -> PC로
에러코드 해결
C4996
'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
Use inet_ntop() or InetNtop()
C4996
'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
Use inet_pton() or InetPton()
inet_ntoa -> inet_ntop() 사용
inet_ntoa 사용 문장
printf("[client IP:%s,PORT:%d] accepted\n", inet_ntoa(clientAddress.sin_addr), ntohs(clientAddress.sin_port));
#include <ws2tcpip.h> <=헤더파일 추가
char clientIP[20] = { 0 }; //dst : 결과 저장하는 곳
if (inet_ntop(AF_INET, &clientAddress.sin_addr, clientIP, sizeof(clientIP)) == NULL)
ErrorMsg("inet_ntop");
else OKMsg("inet_ntop");
printf("[client IP:%s,PORT:%d] accepted\n", clientIP, ntohs(clientAddress.sin_port));
//const char* inet_ntop(int af, const void* src, char* dst, size_t size); <= 형식
inet_addr -> inet_pton() 사용
inet_addr 사용 문장
Address.sin_addr.s_addr = inet_addr(SERVER_IP); //inet_ntoa
#include <ws2tcpip.h> <=헤더파일 추가
result = inet_pton(AF_INET, SERVER_IP, &(serverAddress.sin_addr));
if (result == -1) ErrorMsg("inet_pton");
else OKMsg("inet_pton");
//inet_pton(int af, const char *src, void *dst); <= 형식
728x90
반응형