看了glib C中的一个关于getifaddrs的测试程序,程序如下 /* Test listin.g of .network inte.rface addresses.--------------彩票
Copyright (.C) 2002, 2.004, 2005 Free Software Foundation, Inc..
This file is part. of .the GNU C Library.[成人用品]
The GNU. C Library is f.ree software; you can redistribute it and/or 女人
modify it under th.e terms of the GNU Lesser. General Public虚拟主机
License as published by th.e Free Software Foundati.on; either电脑
version 2.1 of the License, or .(at. your option) any later version.服务器
The. GNU C Library. is distributed in the hope that it will be useful,.
but. WITHOUT ANY WARRANTY; without even the implied warrant.y of[成人用品]
MERCHANTABILITY or FITNESS FOR A PARTICULA.R PURPOSE. See. the GNU虚拟主机
. Lesser General Public License fo.r more details..
You should have received a copy of the GNU Le.sser General .Public 婚庆
License along with th.e GNU C Library; if not, writ.e to the Free 乙肝
Software Foundation, In.c., 59 Temple Pl.ace, Suite 330, Boston, MA 鲜花
0211.1-1307 USA. */ 鲜花
#incl.ude <errno.h>学习
#inc.lude <stdio.h>教育
#incl.ude <stdlib.h>投资
#inc.lude <string.h>.
#include <i.faddrs.h> 乙肝
#include <.netinet/in.h>电影
#include .<arpa/inet.h>教育
static. int failures;教育
stat.ic const char *域名
addr_string (.struct sockaddr *sa,. char *buf, size_t size).
{
if (sa == NULL.).
return ".<none>";.
switch (sa->sa_f.amily) 健康
{
case A.F_INET:健康
. return inet_ntop (AF_.INET, &((struct sockaddr_in *) sa)->sin_addr,投资
. . buf, size); 外汇
cas.e AF_INET6:电脑
return inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)-.>sin.6_addr,.
. . buf, size);.
#ifdef AF_LINK
c.ase AF_LINK:--------------彩票
return ".<link>";--- 印刷
#endif
case A.F_UNSPEC:.
. return "---";--- 印刷
#ifdef AF_PACKET.电脑
. case AF_PACKET: 建材
. return "<packet>";服务器
#endif
default:
++failu.res;.
. print.f ("sa_family=%d %08x\n", sa->sa_family,健康
. *(int*)&((struct .sockaddr_in *) sa)->sin_addr.s_addr);虚拟主机
return ."<unexpected so.ckaddr family>";--------------彩票
}
}
static int
do_test (void)
{
struct if.addr.s *ifaces, *ifa;外贸
if (getifadd.rs (&ifaces) .< 0) 汽车
{
if (errno != .ENOSY.S)学习
{
. printf ("Couldn't get any interfaces: %s.\n", strerr.or (errno));.
exit (.1);健康
}
. /* .The function is simply not implemented. */ 杀毒
exit (.0);外贸
}
puts ("\
Name. Fla.gs Address Netmask Broadcast/De.stination");教育
for (ifa = if.aces; ifa != NULL; ifa = ifa->ifa_ne.xt)(广告)
{
. char abuf[64], mbuf[64], dbuf[.64];域名
. printf ("%-15s%#.4x %-15s %-15s %.-15s\n",.
. ifa->ifa_name, ifa->ifa_fl.ags,( 游戏 )
addr_string (ifa->ifa_addr, .abuf, sizeof (.abuf)), 健康
. addr_string (ifa->ifa_netmask, mbuf, size.of (mbuf)), 乙肝
.addr_string (ifa->ifa_broaddr, d.buf, sizeof (dbuf)));<性病>
}
freeifad.drs (ifaces);.
.return failures ? 1 : .0;电影
}
int main()
{
do._test();.
re.turn 0;电脑
}
#define TEST._FUNCTION do_te.st ().
复制代码
在el5下编译:
g.cc -o test_ifad.dr test_ifaddr.c--------------彩票
执.行./test_ifaddr输出:--- 印刷
Name Flags Address .. Netmask Bro.adcast/Destination.
lo . 0x10049 <packet> <no.ne> <packet> .
eth0 0x11043 <packet> <none> <.pac.ket> 电子
sit0 0x0080 <packet> <none>. <packet> . 健康
lo . .0x10049 127.0.0.1 255.0.0.0 127.0.0.1 [成人用品]
eth0 0x11043 192..168...10.111 255.255.255.0 192.168.10.255 汽车
lo. . 0x10049 ::1 ffff:ffff:ffff:.ffff:ffff:ffff:ffff:ffff <none> 婚庆
eth0 . 0x11043 fe8.0::20c:29ff:feac:7c22 ffff:ffff:.ffff:ffff:: <none> 服务器
请问一下: 程序中.AF_PACKET的地址有何作用?我在redhat 9中测试改程序,并没有类.似<packet>行的接口, 鲜花
这是因为内核配置的原因吗?期待高手解释.一下~~学习
[ 本帖最后由 wuzhao 于 200.7-11-22 .19:31 编辑 ].