IP변환방법
글쓴이: ergo50 / 작성시간: 수, 2004/04/28 - 11:44오전
안녕하세요...
3551521903 와같은 십진수로 표기된 IP를 파일에서 읽어서
xxx.xxx.xxx.xxx 와같은 표기로 전환하려고 하는데요,
어떤함수가 있을까요?
unsigned long int aa = 3551521903;
in.s_addr = aa;
printf("%s\n\n", inet_ntoa(in));
했더니 이상한값이 튀어나오네요 --
조언좀 부탁드리겠습니다.
수고하세요
Forums:


음냐..이건
ip주소 (binary) dotted decimal
---> inet_pton()
<-- inet_ntop()
galadriel in the tower of elves
잘 나오는데요..??뭐가 안 된다는건지..[code:1]&
잘 나오는데요..??
뭐가 안 된다는건지..
[12:12:33 pxdev:temp] o( ")o $ cat b.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main(int argc, char **argv) { unsigned char tmp[5]; struct in_addr in; unsigned long int ip = 3551521903; in.s_addr = ip; printf("%s\n\n", inet_ntoa(in)); /* 이렇게 해도 된답니다. ^^ */ memset(tmp, 0x00, sizeof(tmp)); memcpy(tmp, &ip, 4); printf("%u.%u.%u.%u\n", tmp[0], tmp[1], tmp[2], tmp[3]); exit(EXIT_SUCCESS); } [12:12:36 pxdev:temp] (o^^o) $ b 211.175.236.111 211.175.236.111 [12:12:39 pxdev:temp] o( ")o $>/dev/null 2>&1
감사합니다!!그런데 결과가 반대로 출력되는건 무슨조화에요?Re
감사합니다!!
그런데 결과가 반대로 출력되는건 무슨조화에요?
RedHat 3.0AS 입니다
[root@damanegi kamu00]# ./a.out
111.236.175.211
111.236.175.211
[root@damanegi kamu00]#
[quote="ergo50"]감사합니다!!그런데 결과가 반대로 출력되
unsigned long int ip = htonl(3551521903);이렇게 해보세요.
빠른답변 감사합니다.많은 도움이 되었습니다.수고하세요
빠른답변 감사합니다.
많은 도움이 되었습니다.
수고하세요