⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_ioctl_siocgif.c

📁 T-kernel Tcp/ip Protocol Stack Sample
💻 C
字号:
/* *  Copyright (C) 1999-2003 MITSUBISHI ELECTRIC CORPORATION and *  RENESAS SOLUTIONS CORPORATION and *  RENESAS TECHNOLOGY CORPORATION *  All rights reserved. * *  TCP/IP Test Application program [API]. */#include <tk/tkernel.h>#include <renesas_tcpip.h>#include <renesas_tcpip_common.h>#include "config.h"voidtest_task(int stacd, void *exinf){	int	i, s, ret;	int num;	struct ifreq ifr;	short flags;	int metric;	struct sockaddr_in addr;	int testno, testno2, result[6];	num = 1;	testno = 0;	memset((char *)result, 0, sizeof(result));	/* for setup: get normal socket */	errno = 0;	if ((s = unix_socket(AF_INET, SOCK_DGRAM, 0)) < 0) {		printf("socket(AF_INET,SOCK_DGRAM,0) fail\n");		goto testend;	}	/* set my interface name */	memset((char *)&ifr, 0, sizeof(struct ifreq));	strcpy(ifr.ifr_name, IF_NAME);	/* Test 1 */        printf("ioctl(SIOCGIFFLAGS) Test %d: \n",num++);	errno = 0;testno = 1;	ret = unix_ioctl(s, SIOCGIFFLAGS, (VP)&ifr);	if (ret < 0) {		result[testno] = 1;	}	else {		flags = ifr.ifr_ifru.ifru_flags;		printf("flags = 0x%08x\n", flags);		/*		 * IFF_UP         : 0x1       : interface is up		 * IFF_BROADCAST  : 0x2       : broadcast address valid		 * IFF_DEBUG      : 0x4       : turn on debugging		 * IFF_LOOPBACK   : 0x8       : is a loopback net		 * IFF_POINTOPOINT: 0x10      : interface is point-to-point link		 * IFF_NOTRAILERS : 0x20      : obsolete: avoid use of trailers		 * IFF_RUNNING    : 0x40      : resources allocated		 * IFF_NOARP      : 0x80      : no address resolution protocol		 * IFF_PROMISC    : 0x100     : receive all packets		 * IFF_ALLMULTI   : 0x200     : receive all multicast packets		 * IFF_OACTIVE    : 0x400     : transmission in progress		 * IFF_SIMPLEX    : 0x800     : can't hear own transmissions		 * IFF_LINK0      : 0x1000    : per link layer defined bit		 * IFF_LINK1      : 0x2000    : per link layer defined bit		 * IFF_LINK2      : 0x4000    : per link layer defined bit		 * IFF_ALTPHYS    : IFF_LINK2 : use alternate physical connection		 * IFF_MULTICAST  : 0x8000    : supports multicast		 */		result[testno] = 0;	}	/* Test 2 */        printf("ioctl(SIOCGIFMETRIC) Test %d: \n",num++);	errno = 0;testno = 2;	ret = unix_ioctl(s, SIOCGIFMETRIC, (VP)&ifr);	if (ret < 0) {		result[testno] = 1;	}	else {		metric = ifr.ifr_ifru.ifru_metric;		printf("metric = 0x%08x\n", metric);		result[testno] = 0;	}	/* Test 3 */        printf("ioctl(SIOCGIFADDR) Test %d: \n",num++);	errno = 0;testno = 3;	ret = unix_ioctl(s, SIOCGIFADDR, (VP)&ifr);	if (ret < 0) {		result[testno] = 1;	}	else {#if 1		memcpy(&addr, &ifr.ifr_ifru.ifru_addr,sizeof(addr));#else		bcopy(&ifr.ifr_ifru.ifru_addr, &addr, sizeof(addr));#endif		if (addr.sin_addr.s_addr == inet_addr(TGT_ADDR))			result[testno] = 0;		else			result[testno] = 1;	}	/* Test 4 */        printf("ioctl(SIOCGIFNETMASK) Test %d: \n",num++);	errno = 0;testno = 4;	ret = unix_ioctl(s, SIOCGIFNETMASK, (VP)&ifr);	if (ret < 0) {		result[testno] = 1;	}	else {#if 1		memcpy(&addr, &ifr.ifr_ifru.ifru_addr,sizeof(addr));#else		bcopy(&ifr.ifr_ifru.ifru_addr, &addr, sizeof(addr));#endif		if (addr.sin_addr.s_addr == inet_addr(MSK_ADDR))			result[testno] = 0;		else			result[testno] = 1;	}	/* Test 5 */        printf("ioctl(SIOCGIFBRDADDR) Test %d: \n",num++);	errno = 0;testno = 5;	ret = unix_ioctl(s, SIOCGIFBRDADDR, (VP)&ifr);	if (ret < 0) {		result[testno] = 1;	}	else {#if 1		memcpy(&addr,&ifr.ifr_ifru.ifru_broadaddr,sizeof(addr));#else		bcopy(&ifr.ifr_ifru.ifru_broadaddr, &addr, sizeof(addr));#endif		if (addr.sin_addr.s_addr == inet_addr(BRD_ADDR))			result[testno] = 0;		else			result[testno] = 1;	}	unix_shutdown(s, SHUT_RDWR);	unix_close(s);#if defined(T_KERNEL)	tk_slp_tsk(2000);#endiftestend:	/* check the results */	testno2 = 5;	for (i=1; i <= testno; i++) {		if (result[i] == 1)			break;	}	if (i > testno2)		printf("Pass.\n");	else		printf("Error.\n");#if defined(T_KERNEL)	tk_slp_tsk(TMO_FEVR);#endif}/* EOF */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -