network interface의 link 상태를 점검하고 싶습니다.
글쓴이: isinji / 작성시간: 수, 2003/08/13 - 3:46오후
OS : Tru64 UNIX V5.1
안녕하세요. 처음으로 kldp에 질문을 올려보네요.
먼저 원하는 것은 ioctl()등을 통해 Network Interface의 Link 상태(up/down)를 가져오려고 합니다.
net/if.h 헤더파일을 조사해 보니 Interface의 Link 상태를 저장하는 부분이 없는 것 같더군요.
리눅스의 네트웍 인터페이스에 관련된 구조체나 Tru64 Unix나 별반 차이가 없을 것 같아 여기에 질문을 올려봅니다.
Forums:


Re: network interface의 link 상태를 점검하고 싶습니다.
http://www.tazenda.demon.co.uk/phil/net-tools/
여기 가셔서 net-tools소스 받으시고 풀어보시면 ifconfig의 소스가 있습니다.
이 내용을 조금 들여다 보시면 얻으려 하시는것은 물론이고, 보다 많은 정보도
얻으실것으로 생각됩니다.
------------------ P.S. --------------
지식은 오픈해서 검증받아야 산지식이된다고 동네 아저씨가 그러더라.
몰라도..
#include <stdio.h> #include <sys/ioctl.h> #include <net/if.h> #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> #include <stdio.h> #include <unistd.h> #include "wdscd.h" int devcheck(char *dev) { int fd; int strl; struct sockaddr *sa; struct sockaddr_in *sin; struct ifreq ifr; fd = socket(PF_INET,SOCK_STREAM,0); if (fd == -1) { pdebug("socket() failed"); return -1; } /* Copy the interface name into the buffer */ strncpy(ifr.ifr_name,dev,IFNAMSIZ); if (ioctl(fd,SIOCGIFADDR,&ifr)) { pdebug("device is not up/online"); oldaddr = 0; // Kludges r' us? return -1; } /* Now the buffer will contain the information we requested */ sa = (struct sockaddr *)&(ifr.ifr_addr); if (sa->sa_family == AF_INET) { sin = (struct sockaddr_in*) sa; if (inet_addr(inet_ntoa(sin->sin_addr)) != oldaddr) { oldaddr = inet_addr(inet_ntoa(sin->sin_addr)); strl = strlen(inet_ntoa(sin->sin_addr)); strncpy(coldaddr,inet_ntoa(sin->sin_addr),strl); close(fd); return 1; } else { close(fd); return 0; } } else { pdebug("Unknown Address Family"); } close(fd); return -1; }네트웍 플밍을 해본적이 워낙 오래되어서.. 이게 맞는지 모르겠네요..
근데.. 왜 내 답변을 해주는 사람이 없는지...
input > eth0
output> 3Com Ethernet (etherenet model name)
howto ?
이상은 Valkyrie
http://aladdin.co.kr/shop/wproduct.aspx?ISBN=8995710160&kw=00001A
mms://211.106.66.141/live4/kbs/psong182_m.asf
HAPPy !!
댓글 달기