입력 된 IP 주소가 유효하고 모두 0 (0.0.0.0 또는 00.00.0.0)이 아닌지 확인하기 위해 inet_pton을 사용하고 있습니다. 입력의 IP (SRC) 주소의 src 값이 00.00.00.00 인 경우 0을 소중히하는 0.0.0.0 inet_pton 세트 DST 인 경우inet_pton 모든 0 IP 주소
inet_pton(int af, const char *src, void *dst)
는 DST 값은 0 아니지만, 각각의 흔적에 대한 임의의 값을 가져옵니다. 왜 가치를 0.00.00.00 변환 inet_pton 0
#include <string.h>
#include <arpa/inet.h>
void main(int argc, char *argv[])
{
int s;
struct in_addr ipvalue;
printf("converting %s to network address \n", argv[1]);
s = inet_pton(AF_INET, argv[1], &ipvalue);
if(s < 0)
printf("inet_pton conversion error \n");
printf("converted value = %x \n", ipvalue.s_addr);
}
샘플
올바른 값 실행 :
./a.out 10.1.2.3
converting 10.1.2.3 to network address
converted value = 302010a
./a.out 0.0.0.0
converting 0.0.0.0 to network address
converted value = 0
잘못된 결과 :
을./a.out 00.00.00.0
converting 00.00.00.0 to network address
converted value = **a58396a0**
./a.out 00.0.0.0
converting 00.0.0.0 to network address
converted value = **919e2c30**