读书人

solaris上检测网口函数

发布时间: 2013-01-08 14:02:14 作者: rapoo

solaris下检测网口函数
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <sys/sockio.h>
#include <sys/sockET.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <net/if.h>
#include <unistd.h>
//#include <stropt.h>

int main()
{
int socket_fd = 0;
struct ifreq ifr;
int ret = 0;

/* Setup our control structures. */
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, "bge0");

/* Open control socket. */
socket_fd = socket(PF_UNIX, SOCK_DGRAM, 0);
if (socket_fd < 0)
{
printf("Error: Cannot get control socket\n");
return -1;
}

ret = ioctl(socket_fd, SIOCGIFFLAGS, &ifr);
if ( ret < 0 )
{
printf("Error: ioctrl socket[%d] get control socket\n", socket_fd);
return -1;
}

/* 最低位表示网口的开和关,1表示开,0表示关 */
printf("ifr.ifr_flags is %d\n", ifr.ifr_flags);
if ( ifr.ifr_flags & 0x1 )
{
printf("Info: bge0 is up\n");
}
else
{
printf("Info: bge0 is down\n");
}

return 0;
}

这段代码是用来测试网卡状态的.原来在linux系统上可以用.现在我做点修改,移植到了solaris上编译时出现了如下错误:
root@dns # gcc -o test ethupdown.c
Undefined first referenced
symbol in file
socket /var/tmp/cc6JrQ5L.o
ld: fatal :Symbol referencing errors.No output written to a
collect2:ld returned 1 exit status

不知道是不是头文件包错了还是什么的.. 小弟solaris不熟啊,求高人帮忙~









[解决办法]
链接动态库
gcc -l socket -o test ethupdown.c

读书人网 >其他服务器

热点推荐