Exemplo n.º 1
0
static int set_flag(int skfd,char *ifname, short flag)
{
    struct ifreq ifr;

//    strcpy(ifr.ifr_name, ifname);
    snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),ifname);

#ifndef WLAN
    if (netioctl(skfd, SIOCGIFFLAGS, &ifr,sizeof(ifr), g_StreamServer_Buf, System_BUFFER_LEN) < 0) 
#else
	if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) 
#endif
    {
		fprintf(stderr, "%s: unknown interface: %s\n",
			ifname,	strerror(errno));
		return (-1);
    }
    //strcpy(ifr.ifr_name, ifname);
    snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),ifname);
    ifr.ifr_flags |= flag;
#ifndef WLAN    
    if (netioctl(skfd, SIOCSIFFLAGS, &ifr,sizeof(ifr), g_StreamServer_Buf, System_BUFFER_LEN) < 0) 
#else
    if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) 
#endif
    {
		perror("SIOCSIFFLAGS");
		return -1;
    }
    return (0);
}
Exemplo n.º 2
0
static prism_cnfDesireSSID_t *ReadWlanESSIDList(const char *pcInterface, int fd, int *piLength)
{
   	prism_cnfDesireSSID_t *pApList = NULL;
   	int i, j;
   	struct iwreq wrq;

	if (pcInterface == NULL || fd < 0 || piLength == NULL)
		return NULL;

	memset(&wrq, 0, sizeof(wrq));
	strcpy(wrq.ifr_name, pcInterface);

   	wrq.u.data.length = 0;//get twice.
 #ifndef WLAN
	if(netioctl(fd, SIOCGIWAPLIST, &wrq,sizeof(wrq), g_StreamServer_Buf, System_BUFFER_LEN) < 0)
#else
	if(ioctl(fd, SIOCGIWAPLIST, &wrq) < 0)
#endif
	{
		diag_printf("ioctl SIOCGIWAPLIST < 0\n");
		return NULL;
	}

	if (wrq.u.data.length <= 0)
	{
		diag_printf("wrq.u.data.length = %d\n", wrq.u.data.length);
		return NULL;
	}

	pApList = (prism_cnfDesireSSID_t *)malloc(wrq.u.data.length * sizeof(prism_cnfDesireSSID_t));
	if(pApList == NULL)
	{
		PRINT_MEM_OUT;
		return NULL;
	}

	wrq.u.data.pointer = (caddr_t)pApList;
#ifndef WLAN
	if(netioctl(fd, SIOCGIWAPLIST, &wrq, sizeof(wrq),g_StreamServer_Buf, System_BUFFER_LEN) < 0)
#else
	if(ioctl(fd, SIOCGIWAPLIST, &wrq) < 0)
#endif
	{
		diag_printf("ioctl SIOCGIWAPLIST < 0\n");
		free(pApList);
		return NULL;
	}

	for(i = 0; i < wrq.u.data.length; i++)
	{
		diag_printf("Access point: %d	", i);
		for(j = 0; j < (pApList + i)->ssidLen; j++)
			diag_printf("%c", *((pApList + i)->ssidName + j));
		diag_printf("\n");
	}

	*piLength = wrq.u.data.length;
	return pApList;
}
Exemplo n.º 3
0
void test_netioctl_entry(char *pBuf, int iBufLen)
{
	int fd;
	struct ifreq ifbuf;
	
	fd = socket(AF_INET, SOCK_STREAM, 0, pBuf, iBufLen);
	if(fd < 0)
	{
		test_printf_error("test_netioctl_entry");
		return;
	}
		
	if(netioctl(-1, SIOCSIFADDR, &ifbuf, sizeof(ifbuf), pBuf, iBufLen) >= 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	
	if(netioctl(fd, SIOCSIFADDR, NULL, sizeof(ifbuf), pBuf, iBufLen) >= 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	
	if(netioctl(fd, SIOCSIFADDR, &ifbuf, 0, pBuf, iBufLen) >= 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	
	if(netioctl(fd, SIOCSIFADDR, &ifbuf, sizeof(ifbuf), NULL, iBufLen) >= 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	
	if(netioctl(fd, SIOCSIFADDR, &ifbuf, sizeof(ifbuf), pBuf, 0) >= 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	
	test_printf_success("test_netioctl_entry");
	netclose(fd, pBuf, iBufLen);
}
Exemplo n.º 4
0
static BOOL ScanWlanAp(const char *pcInterface, int fd)
{
	struct iwreq wrq;

	if (pcInterface == NULL || fd < 0) return FALSE;

	memset(&wrq, 0, sizeof(wrq));
	strcpy(wrq.ifr_name, pcInterface);
diag_printf("interface: %s\n", pcInterface);
	/* Get number of ap */
#ifndef WLAN
	if(netioctl(fd, 0x8B18, &wrq,sizeof(wrq), g_StreamServer_Buf, System_BUFFER_LEN) < 0)
#else
	if(ioctl(fd, 0x8B18, &wrq) < 0)
#endif
	{
		fprintf(stderr, "SIOCSIWSCAN: %s\n", strerror(errno));
		return FALSE;
	}
	return TRUE;

/*
   	if (wrq.u.data.length > 0) return wrq.u.data.length;
   	else
   	{
PTE;
   		return 0;
   	}
*/
}
Exemplo n.º 5
0
/*
 * Name: GetWlanOperationMode
 * Description: Get wireless operation mode.
 *
 * Parameter:
 *  pcInterface[in]: Net interface for wireless lan.
 *  piMode[out]: Operation mode.
 * Return value:
 *  TRUE: Success.
 *  FALSE: Failed.
 */
BOOL GetWlanOperationMode(const char *pcInterface, int *piMode)
{
	int fd;
	int rt;
	struct iwreq wrq;
	

	if (pcInterface == NULL) return FALSE;

	//if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) return FALSE;
#ifndef WLAN	
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return FALSE;
#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return FALSE;

#endif
	memset(&wrq, 0, sizeof(wrq));

	strcpy(wrq.ifr_name, pcInterface);
#ifndef WLAN
	rt = netioctl(fd, SIOCGIWMODE, &wrq,sizeof(wrq), g_StreamServer_Buf, System_BUFFER_LEN);
    netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	rt = ioctl(fd, SIOCGIWMODE, &wrq);
    close(fd);
#endif
    if (rt < 0
    	|| !(wrq.u.mode >= 0 && wrq.u.mode < sizeof(g_apcWlanOperationMode) / sizeof(const char *)))
    	return FALSE;

	if (piMode != NULL) *piMode = wrq.u.mode;
	return TRUE;
}
Exemplo n.º 6
0
BOOL GetWlanChannel(const char *pcInterface, int *piChannel)
{
	int rt;
	int fd;
	struct iwreq wrq;

	if (pcInterface == NULL || piChannel == NULL)
	{
		fprintf(stderr, "illegal call function GetWlanChannel!\n");
		return FALSE;
	}
#ifndef WLAN 
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return FALSE;
#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0)
		return FALSE;
#endif
	memset(&wrq, 0, sizeof(wrq));
	strcpy(wrq.ifr_name, pcInterface);
#ifndef WLAN 
	rt = netioctl(fd, SIOCGIWFREQ, &wrq,sizeof(wrq), g_StreamServer_Buf, System_BUFFER_LEN);
	netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	rt = ioctl(fd, SIOCGIWFREQ, &wrq);
	close(fd);
#endif	

	if (rt >= 0)
	{
		*piChannel = wrq.u.freq.m;
		return TRUE;
	}
	else return FALSE;
}
Exemplo n.º 7
0
/*
 * Name: GetWlanWepKey
 * Description: Get wireless WEP key settings.
 *
 * Parameter:
 *  pcInterface[in]: Net interface for wireless lan.
 *  pAscKey[out]: Buffer length of which >= 14.
 *  piAscKeyLen[out]: The Length of valid buffer pointed by "pAscKey".
 *                    -1 if WEP key is disabled.
 *  piKeyIndex[out]: Index of WEP keys.
 * Return value:
 *  TRUE: Success.
 *  FALSE: Failed.
 */
BOOL GetWlanWepKey(const char *pcInterface,
					void *pAscKey,
					int *piAscKeyLen,
					int *piKeyIndex)
{
	int fd;
	int rt;
	unsigned char pucKey[IW_ENCODING_TOKEN_MAX];
	struct iwreq wrq;

	if (pcInterface == NULL) return FALSE;
#ifndef WLAN
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return FALSE;
#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return FALSE;
#endif
	memset(&wrq, 0, sizeof(wrq));

	strcpy(wrq.ifr_name, pcInterface);
	wrq.u.data.pointer = (caddr_t)pucKey;
	wrq.u.data.length = 0;
	wrq.u.data.flags = 0;
#ifndef WLAN
	rt = netioctl(fd, SIOCGIWENCODE, &wrq, sizeof(wrq),g_StreamServer_Buf, System_BUFFER_LEN);
    netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	rt = ioctl(fd, SIOCGIWENCODE, &wrq);
    close(fd);
#endif
    if (rt >= 0)
    {
    	if (wrq.u.data.flags & IW_ENCODE_DISABLED)
    	{
    		if (piAscKeyLen != NULL) *piAscKeyLen = -1;
    	}
    	else
    	{
    		if (piAscKeyLen != NULL)
    		{
				/* iKeyIndex in ioctl from 1 to 4, while SetWlanWepKey use 0 to 3 */
    			*piAscKeyLen = wrq.u.data.length - 1;
    		}
    		if (pAscKey != NULL)
    			memcpy(pAscKey, pucKey, wrq.u.data.length);
    		if (piKeyIndex != NULL)
    			*piKeyIndex = wrq.u.encoding.flags & 0x000000FF;
    	}
    }

	return (rt >= 0 ? TRUE : FALSE);
}
Exemplo n.º 8
0
BOOL SetWlanESSID(const char *pcInterface, const char *pcWlanID)
{
	int rt;
	int fd;
	struct iwreq wrq;
	char ac[64];

	if (pcInterface == NULL)
	{
		fprintf(stderr, "illegal call function SetWlanESSID!\n");
		return FALSE;
	}

#ifndef WLAN
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return FALSE;
#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return FALSE;
#endif	
	memset(&wrq, 0, sizeof(wrq));
	strcpy(wrq.ifr_name, pcInterface);

	if (pcWlanID == NULL)
	{//essid: any
		ac[0] = '\0';
		wrq.u.essid.flags = 0;
	}
	else
	{
		httpMyStrncpy(ac, pcWlanID, sizeof(ac));
		wrq.u.essid.flags = 1;
	}

	wrq.u.essid.pointer = (caddr_t)ac;
	wrq.u.essid.length = strlen(ac) + 1;
	
#ifndef WLAN
	rt = netioctl(fd, SIOCSIWESSID, &wrq, sizeof(wrq),g_StreamServer_Buf, System_BUFFER_LEN);

	netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	if((rt = ioctl(fd, SIOCSIWESSID, &wrq)) < 0)
		diag_printf("scan ESSID %s failed\n",pcWlanID);	
	else
		diag_printf("set ssid finished\n");
	
	close(fd);
#endif	
	return (rt >= 0 ? TRUE : FALSE);
}
Exemplo n.º 9
0
char *GetWlanESSID(const char *pcInterface, char *pcWlanID, int iWlanIDMaxLen)
{
	int fd;
	struct iwreq wrq;
	char ac[64];

	if (pcInterface == NULL || pcWlanID == NULL || iWlanIDMaxLen < 0)
	{
		fprintf(stderr, "illegal call function GetWlanESSID!\n");
		return NULL;
	}
#ifndef WLAN
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return NULL;
#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return NULL;
#endif
	/* Get network ID */
	memset(&wrq, 0, sizeof(wrq));
	strcpy(wrq.ifr_name, pcInterface);
	wrq.u.essid.pointer = (caddr_t)ac;
	wrq.u.essid.length = 0;
	wrq.u.essid.flags = 0;
#ifndef WLAN  
	if(netioctl(fd, SIOCGIWESSID, &wrq, sizeof(wrq),g_StreamServer_Buf, System_BUFFER_LEN) >= 0)
#else
	if(ioctl(fd, SIOCGIWESSID, &wrq) >= 0)
#endif
	{
		if (wrq.u.essid.flags == 0) pcWlanID[0] = '\0';
		else
		{
			if (wrq.u.essid.length < sizeof(ac))
				ac[wrq.u.essid.length] = '\0';
			else ac[sizeof(ac) - 1] = '\0';
			httpMyStrncpy(pcWlanID, ac, iWlanIDMaxLen);
		}
	}
	else pcWlanID[0] = '\0';
#ifndef WLAN 
	netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	close(fd);
#endif
	return pcWlanID;
}
Exemplo n.º 10
0
/*
 * Name: SetWlanOperationMode
 * Description: Set wireless operation mode.
 *
 * Parameter:
 *  pcInterface[in]: Net interface for wireless lan.
 *  iMode[in]: Operation mode.
 * Return value:
 *  TRUE: Success.
 *  FALSE: Failed.
 */
BOOL SetWlanOperationMode(const char *pcInterface, int iMode)
{
	int fd;
	int rt;
	struct iwreq wrq;
	//int buffer_size = 1024;
	//char buffer_size[1024];

	if (pcInterface == NULL) return FALSE;
	if (!(iMode >= 0
		&& iMode < sizeof(g_apcWlanOperationMode) / sizeof(const char *)))
		return FALSE;

	if (iMode != 1 && iMode != 2)
	{
		fprintf(stderr, "Only Ad-Hoc and Managed modes supported.\n");
		return FALSE;
	}

	//if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) return FALSE;
#ifndef WLAN
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return FALSE;
#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return FALSE;
#endif
	memset(&wrq, 0, sizeof(wrq));

	strcpy(wrq.ifr_name, pcInterface);
	wrq.u.mode = iMode;
diag_printf("mode %d\n", iMode);
#ifndef WLAN
	rt = netioctl(fd, SIOCSIWMODE, &wrq,sizeof(wrq), g_StreamServer_Buf, System_BUFFER_LEN);
    netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	rt = ioctl(fd, SIOCSIWMODE, &wrq);
    close(fd);
#endif
	return (rt >= 0 ? TRUE : FALSE);
}
Exemplo n.º 11
0
BOOL GetWlanLinkState(const char *pcInterface, int *piState)
{
	int fd;
	int rt;
	int iState;
	struct iwreq wrq;

	if (pcInterface == NULL || piState == NULL) return FALSE;
#ifndef WLAN
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return FALSE;

#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return FALSE;

#endif
	memset(&wrq, 0, sizeof(wrq));

	strcpy(wrq.ifr_name, pcInterface);
	wrq.u.data.pointer = (caddr_t)&iState;
   	wrq.u.data.length = sizeof(int);
#ifndef WLAN
   	rt = netioctl(fd, SIOCIWFIRSTPRIV + 0x9, &wrq,sizeof(wrq), g_StreamServer_Buf, System_BUFFER_LEN);
   	netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
   	rt = ioctl(fd, SIOCIWFIRSTPRIV + 0x9, &wrq);
   	close(fd);
#endif


	if (rt >= 0)
	{
		*piState = iState;
		return TRUE;
	}
	else return FALSE;
}
Exemplo n.º 12
0
unsigned long GetGeneralIP(const char *pcInterface, int iRequest)
{
	struct ifreq ifr;
	int fd;
	unsigned long ulRt;

	if (pcInterface == NULL)
	{
		fprintf(stderr, "illegal call function GetGeneralIP!\n");
		return 0L;
	}
#ifndef WLAN
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return 0L;
#else	
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return 0L;
#endif
	//strcpy(ifr.ifr_name, pcInterface);
	snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),pcInterface);

#ifndef WLAN
	if (netioctl(fd, iRequest, &ifr,sizeof(ifr), g_StreamServer_Buf, System_BUFFER_LEN) < 0)
#else
	if (ioctl(fd, iRequest, &ifr) < 0)
#endif
		ulRt = 0;
	else
		ulRt = (*(struct sockaddr_in *)&(ifr.ifr_addr)).sin_addr.s_addr;
#ifndef WLAN		
	netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	close(fd);
#endif
	return ulRt;
}
Exemplo n.º 13
0
int GetDevInterface(void)
{
	int dev_num = 0;
	struct ifreq ifbuf[MAXINTERFACES/2]={0};
	struct ifconf ifc;
	int i,fd, ifnum=0;
	int iInterface;
	unsigned long ulGateway;


	dev_num = 1;

	memset(&ipmc, 0, sizeof(ipmc));
	memset(&ifc, 0, sizeof(ifc));

	fd = socket(AF_INET, SOCK_DGRAM, 0, g_RemoteNet_Buf, RNT_BUFFER_LEN);
	if (fd < 0) 
    {
		perror("socket");
		return fd;
    }

    ifc.ifc_len = sizeof(ifbuf);
    ifc.ifc_buf = (caddr_t)ifbuf;
    if(netioctl_withbuf(fd, SIOCGIFCONF, &ifc,sizeof(ifc), g_RemoteNet_Buf, RNT_BUFFER_LEN) < 0)
    {
        netclose(fd, g_RemoteNet_Buf, RNT_BUFFER_LEN);
        return -1;
    }
    ifnum = ifc.ifc_len/sizeof(struct ifreq);
    for(i=0;i<ifnum;i++)
         diag_printf("interface name are %s\n",ifbuf[i].ifr_name);

   //strcpy(ifbuf[0].ifr_name,"eth1");

    while(ifnum-- > 0)
    {
        if( strlen(ifbuf[ifnum].ifr_name) > 4 ||ifbuf[ifnum].ifr_name == NULL||
           strcmp(ifbuf[ifnum].ifr_name,"lo")==0||
            netioctl(fd, SIOCGIFFLAGS, &ifbuf[ifnum],sizeof(ifbuf[ifnum]), g_RemoteNet_Buf, RNT_BUFFER_LEN) < 0 ||
            !(ifbuf[ifnum].ifr_flags & IFF_UP) ||
            netioctl(fd, SIOCGIFADDR, &ifbuf[ifnum],sizeof(ifbuf[ifnum]), g_RemoteNet_Buf, RNT_BUFFER_LEN) < 0)
            continue;              

		diag_printf("if name ===%s\n",ifbuf[ifnum].ifr_name);
		
		/*Get the MAC Address*/
        if (netioctl(fd, SIOCGIFHWADDR, &ifbuf[ifnum],sizeof(ifbuf[ifnum]), g_RemoteNet_Buf, RNT_BUFFER_LEN) >= 0)
       		diag_printf("MAC Address====%d\n",ifbuf[ifnum].ifr_hwaddr.sa_data);
       	else
       		diag_printf("get mac addr error\n");
       	
		/*Get the Netmask*/
        if (netioctl(fd, SIOCGIFNETMASK, &ifbuf[ifnum],sizeof(ifbuf[ifnum]), g_RemoteNet_Buf, RNT_BUFFER_LEN) >= 0)
       		diag_printf("Netmask====%s\n",inet_ntoa( (((struct sockaddr_in *)&ifbuf[ifnum].ifr_netmask)->sin_addr), g_RemoteNet_Buf, RNT_BUFFER_LEN));    
       	else
       		diag_printf("get netmask error\n");

        /*Get the IP Address*/    
        if (netioctl(fd, SIOCGIFADDR, &ifbuf[dev_num], sizeof(ifbuf[dev_num]), g_RemoteNet_Buf, RNT_BUFFER_LEN) >= 0)
	        diag_printf("ipaddr Address====%s\n",inet_ntoa((((struct sockaddr_in *)&ifbuf[ifnum].ifr_addr)->sin_addr), g_RemoteNet_Buf, RNT_BUFFER_LEN));
	    else
	    	diag_printf("get if addr error\n");
	    
        /*Get the Gateway*/
		ulGateway = wb740getgateway(ifbuf[ifnum].ifr_name, g_RemoteNet_Buf, RNT_BUFFER_LEN);
		diag_printf("Gateway====%s\n",inet_ntoa(*(struct in_addr*)&ulGateway, g_RemoteNet_Buf, RNT_BUFFER_LEN));
        dev_num++;
    }

    netclose(fd, g_RemoteNet_Buf, RNT_BUFFER_LEN);
    return dev_num;
}
Exemplo n.º 14
0
void GetPubIPInfo(unsigned long *pulPublicIpAddress,
							unsigned long *pulPublicSubnetMask,
							unsigned long *pulDefaultGateway,
							unsigned long *pulDNSServer)
{
	BOOL bEnable[2];
	int fd;
	struct ifreq ifr;
	bEnable[0] = g_ConfigParam.abAsNetEnable[0];
	bEnable[1] = g_ConfigParam.abAsNetEnable[1];
	
	
#ifndef WLAN
	if (!bEnable[0] && !bEnable[1]) bEnable[0] = TRUE;
   	fd = socket(AF_INET, SOCK_DGRAM, 0, g_Mctest_Buf, MCTEST_BUFFER_LEN);
	strcpy(ifr.ifr_name, g_apcNetworkInterface[0]);
#else
	if (!bEnable[0] && !bEnable[1]) bEnable[1] = TRUE;
    fd = socket(AF_INET, SOCK_DGRAM, 0);
	strcpy(ifr.ifr_name, g_apcNetworkInterface[1]);
#endif
    if (fd < 0) 
    {
        perror("socket");
        return;
    }

  	/*Get the IP Address*/ 
	if(pulPublicIpAddress != NULL)
	{        
#ifndef WLAN  	   
        if (netioctl(fd, SIOCGIFADDR, &ifr, sizeof(ifr),g_Mctest_Buf, MCTEST_BUFFER_LEN) >= 0)
#else
        if (ioctl(fd, SIOCGIFADDR, &ifr) >= 0)
#endif         
            *pulPublicIpAddress = (unsigned int)(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
         else
         	*pulPublicIpAddress = 0;
#ifndef WLAN  	   
        diag_printf("ipaddr Address====%s\n",inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr, g_Mctest_Buf, MCTEST_BUFFER_LEN));  
#else
        diag_printf("ipaddr Address====%s\n",inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));  
#endif 
	}   
	     
	/*Get the Netmask*/
	if(pulPublicSubnetMask != NULL)
	{         	
#ifndef WLAN  	   
        if (netioctl(fd, SIOCGIFNETMASK, &ifr,sizeof(ifr), g_Mctest_Buf, MCTEST_BUFFER_LEN) >= 0)
#else
        if (ioctl(fd, SIOCGIFNETMASK, &ifr) == 0)
#endif         
            *pulPublicSubnetMask = (unsigned int)(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
        else
            *pulPublicSubnetMask = 0;
#ifndef WLAN  	   
        diag_printf("Netmask====%s\n",inet_ntoa(((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr, g_Mctest_Buf, MCTEST_BUFFER_LEN));    
#else
        diag_printf("Netmask====%s\n",inet_ntoa(((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr));    
#endif   
	}
	
     /*Get the Gateway*/
	if(pulDefaultGateway != NULL)
	{
#ifndef WLAN         
        {
        	unsigned long Gateway;
        	char tmpgw[16];
        	char *c,*p;
        	int i = 0;
        	Gateway = wb740getgateway((char*)(ifr.ifr_name),g_Mctest_Buf, MCTEST_BUFFER_LEN);
        	diag_printf("Gateway====%s\n",inet_ntoa(*(struct in_addr*)&Gateway, g_Mctest_Buf, MCTEST_BUFFER_LEN));
        	if(Gateway != 0L)
        	{
        		strcpy(tmpgw,inet_ntoa(*(struct in_addr*)&Gateway, g_Mctest_Buf, MCTEST_BUFFER_LEN));
        		p = tmpgw;
        		while(*p != '\0')
        		{
        			c = p;
        			while((*p != '.') && (*p != '\0'))
        				p++;
        			*p = '\0';
        			ipmc[dev_num].gwaddr[i] = (unsigned char)atoi(c);          			
        			if(i < 3)
        			{p++; i++;  }  		
        		}	
				
			} 
			else 
				memset(ipmc[dev_num].gwaddr,0 ,4);
			
		}
#else
		if (g_ConfigParam.aucIPAssignedWay[1] == IP_ASSIGNMENT_MANUALLY)
			*pulDefaultGateway = g_ConfigParam.ulAsGateway[1];
		else
		{
			struct in_addr gateway;
			unsigned int length = sizeof(gateway);
			get_bootp_option(&wlan0_bootp_data, TAG_GATEWAY, (void*)&gateway,&length);
			diag_printf("gateway: %x\n", gateway.s_addr);
			*pulDefaultGateway = gateway.s_addr;
		}
#endif
	}
#ifndef WLAN
    netclose(fd, g_Mctest_Buf, MCTEST_BUFFER_LEN);
#else
    close(fd);
#endif
	if(pulDNSServer != NULL)
	{
		if (g_ConfigParam.aucIPAssignedWay[1] == IP_ASSIGNMENT_MANUALLY)
		{
			*pulDNSServer = g_ConfigParam.aulAsDNS[0];
   			*(pulDNSServer+1) = g_ConfigParam.aulAsDNS[1];
   			*(pulDNSServer+2) = g_ConfigParam.aulAsDNS[2];
   		}
   		else
   		{
			struct in_addr gateway;
			unsigned int length = sizeof(gateway);
			get_bootp_option(&wlan0_bootp_data, TAG_GATEWAY, (void*)&gateway,&length);
			diag_printf("gateway as dns: %x\n", gateway.s_addr);
			
			*pulDefaultGateway = gateway.s_addr;
			*pulDNSServer = gateway.s_addr;
   			*(pulDNSServer+1) = 0;
   			*(pulDNSServer+2) = 0;
   		}
	}
	
	if (g_ConfigParam.aucIPAssignedWay[1] == IP_ASSIGNMENT_DHCP
		&& wlan0_dhcpstate != DHCPSTATE_BOOTP_FALLBACK
		&& wlan0_dhcpstate != DHCPSTATE_BOUND
		)
	{
		if (g_WebCamState.bDHCP_Finished)
		{
			unsigned int GetRandomIP(void);
			unsigned int ulIP = GetRandomIP();
			if (pulPublicIpAddress != NULL)
				*pulPublicIpAddress = ulIP;
			if (pulPublicSubnetMask != NULL)
				*pulPublicSubnetMask = 0x0000FFFF;
			if (pulDefaultGateway != NULL)
				*pulDefaultGateway = ulIP;
		}
		else
		{
			if (pulPublicIpAddress != NULL)
				*pulPublicIpAddress = 0;
			if (pulPublicSubnetMask != NULL)
				*pulPublicSubnetMask = 0xFFFFFFFF;
			if (pulDefaultGateway != NULL)
				*pulDefaultGateway = 0;
		}
		if (pulDNSServer != NULL)
		{
			*pulDNSServer = 0;
			*(pulDNSServer + 1) = 0;
			*(pulDNSServer + 2) = 0;
		}
	}
    return;

}
Exemplo n.º 15
0
BOOL SetGeneralIP(const char *pcInterface, unsigned long ulIP, unsigned long ulNetmask)
{
	struct ifreq ifr;
	int ret;
	int fd;
	struct sockaddr_in *pAddr;

	if (pcInterface == NULL)
	{
		fprintf(stderr, "illegal call function SetGeneralIP!\n");
		return FALSE;
	}
#ifndef WLAN
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0) 
		return FALSE;
#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return FALSE;
#endif
	memset((void*)&ifr, 0, sizeof(ifr));
	strcpy(ifr.ifr_name, pcInterface);
#ifdef WLAN

    if (ioctl(fd, SIOCGIFFLAGS, &ifr)) {
        diag_printf("SIOCSIFFLAGS error %x\n", errno);
        close(fd);
        return false;
    }
    ifr.ifr_flags &= ~IFF_UP;
    if (ioctl(fd, SIOCSIFFLAGS, &ifr)) {
        diag_printf("SIOCSIFFLAGS error %x\n", errno);
        close(fd);
        return false;
    }
    ret = ioctl(fd, SIOCGIFADDR, &ifr);
    if(ret < 0 && (errno != EADDRNOTAVAIL))
    {
        perror("SIOCIFADDR");
    }
    
    ret = ioctl(fd, SIOCDIFADDR, &ifr);
    if(ret < 0 && (errno != EADDRNOTAVAIL))
    {
        perror("SIOCIFADDR");
    }    
    
	ifr.ifr_flags = IFF_UP | IFF_BROADCAST | IFF_RUNNING;
    if (ioctl(fd, SIOCSIFFLAGS, &ifr)) 
    {
        diag_printf("SIOCSIFFLAGS error %x\n", errno);
		close(fd);
        return false;
    }
 #endif
	pAddr = (struct sockaddr_in *)&(ifr.ifr_addr);
	bzero(pAddr, sizeof(struct sockaddr_in));
	pAddr->sin_addr.s_addr = ulIP;
	pAddr->sin_family = AF_INET;
	pAddr->sin_len = sizeof(*pAddr);
#ifndef WLAN	
	if (netioctl(fd, SIOCSIFADDR, &ifr, sizeof(ifr),g_StreamServer_Buf, System_BUFFER_LEN) < 0)
#else
	if (ioctl(fd, SIOCSIFADDR, &ifr) < 0)
#endif
	{
		diag_printf("can not set ip errno = %x\n",errno);
#ifndef WLAN
		netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
		close(fd);
#endif
		return FALSE;
	}

	pAddr = (struct sockaddr_in *)&(ifr.ifr_addr);
	bzero(pAddr, sizeof(struct sockaddr_in));
	pAddr->sin_addr.s_addr = ulNetmask;
	pAddr->sin_family = AF_INET;
	pAddr->sin_len = sizeof(*pAddr);
#ifndef WLAN
	if (netioctl(fd, SIOCSIFNETMASK, &ifr,sizeof(ifr), g_StreamServer_Buf, System_BUFFER_LEN) < 0)
#else
	if (ioctl(fd, SIOCSIFNETMASK, &ifr) < 0)
#endif
	{
		diag_printf("Can not set netmask!\n");
#ifndef WLAN
		netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
		close(fd);
#endif
		return FALSE;
	}
#ifndef WLAN
	netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	close(fd);
#endif
	return TRUE;
}
Exemplo n.º 16
0
/*
 * Name: SetWlanWepKey
 * Description: Set wireless WEP key.
 *
 * Parameter:
 *  pcInterface[in]: Net interface for wireless lan.
 *  pAscKey[in]: Buffer length of which >= 14.
 *  iAscKeyLen[in]: The Length of valid buffer pointed by "pAscKey".
 *                  Set the value to -1 if WEP key wants to be
 *                  disabled.
 *  iKeyIndex[in]: Index of WEP keys.
 * No return value.
 */
BOOL SetWlanWepKey(const char *pcInterface,
					const void *pAscKey,
					int iAscKeyLen,
					int iKeyIndex,
					int WepAuthentication)
{
	int fd;
	int rt;
	unsigned char pucKey[IW_ENCODING_TOKEN_MAX];
	struct iwreq wrq;
	
	diag_printf("SetWlanWepKey=%s,%02x%02x%02x,%d,%d,%d\n", pcInterface,
		(int)((unsigned char *)pAscKey)[0],
		(int)((unsigned char *)pAscKey)[1],
		(int)((unsigned char *)pAscKey)[2],
		iAscKeyLen,
		iKeyIndex,
		WepAuthentication);
		
	
	if (pcInterface == NULL) return FALSE;
#ifndef WLAN
	if ((fd = socket(AF_INET,SOCK_DGRAM,0, g_StreamServer_Buf, System_BUFFER_LEN)) < 0)
		return FALSE;
#else
	if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) 
		return FALSE;	
#endif
	memset(&wrq, 0, sizeof(wrq));

	/* iKeyIndex in ioctl from 1 to 4, while SetWlanWepKey use 0 to 3 */
	iKeyIndex++;

	strcpy(wrq.ifr_name, pcInterface);
	if (iAscKeyLen >= 0)
	{//on
		wrq.u.data.length = iAscKeyLen;
		if(wrq.u.data.length > IW_ENCODING_TOKEN_MAX)
			wrq.u.data.length = IW_ENCODING_TOKEN_MAX;
		if (pAscKey != NULL)
		{
			memcpy(pucKey, pAscKey, wrq.u.data.length);
			wrq.u.data.pointer = (caddr_t)pucKey;
		}
		else wrq.u.data.pointer = NULL;

		if (iKeyIndex > 0 && iKeyIndex < IW_ENCODE_INDEX)
			wrq.u.encoding.flags |= iKeyIndex;

		wrq.u.data.flags |= WepAuthentication;
		//wrq.u.data.flags |= IW_ENCODE_OPEN;
	}
	else
	{//off
		wrq.u.data.length = 0;
		wrq.u.data.pointer = (caddr_t)pucKey;
		wrq.u.data.flags |= IW_ENCODE_DISABLED;
		wrq.u.data.flags |= IW_ENCODE_OPEN;
	}
#ifndef WLAN
	rt = netioctl(fd, SIOCSIWENCODE, &wrq, sizeof(wrq),g_StreamServer_Buf, System_BUFFER_LEN);
	netclose(fd, g_StreamServer_Buf, System_BUFFER_LEN);
#else
	rt = ioctl(fd, SIOCSIWENCODE, &wrq);
	close(fd);
#endif
	return (rt >= 0 ? TRUE : FALSE);
}
Exemplo n.º 17
0
void test_netioctl_entry(char *pBuf, int iBufLen)
{
	int fd;
	struct ifreq ifbuf;
	int newip, newnetmask;
	int ip, netmask;
	
	fd = socket(AF_INET, SOCK_STREAM, 0, pBuf, iBufLen);
	if(fd < 0)
	{
		test_printf_error("test_netioctl_entry");
		return;
	}
	
	if(inet_aton(TEST_NETIOCTL_IP_ADDR, (struct in_addr*)&newip, pBuf, iBufLen) < 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	if(inet_aton(TEST_NETIOCTL_IP_NETMASK, (struct in_addr*)&newnetmask, pBuf, iBufLen) < 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	
	memset(&ifbuf, 0, sizeof(ifbuf));
	strcpy(ifbuf.ifr_name, TEST_NETIOCTL_INTERFACE_NAME);
	((struct sockaddr_in*)&(ifbuf.ifr_addr))->sin_addr.s_addr = newip;
	((struct sockaddr_in*)&(ifbuf.ifr_addr))->sin_family = AF_INET;
	if(netioctl(fd, SIOCSIFADDR, &ifbuf, sizeof(ifbuf), pBuf, iBufLen) < 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	((struct sockaddr_in*)&(ifbuf.ifr_addr))->sin_addr.s_addr = newnetmask;
	if(netioctl(fd, SIOCSIFNETMASK, &ifbuf, sizeof(ifbuf), pBuf, iBufLen) < 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	
	strcpy(ifbuf.ifr_name, TEST_NETIOCTL_INTERFACE_NAME);
	if(netioctl(fd, SIOCGIFADDR, &ifbuf, sizeof(ifbuf), pBuf, iBufLen) < 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	ip = ((struct sockaddr_in*)&(ifbuf.ifr_addr))->sin_addr.s_addr;
	
	if(netioctl(fd, SIOCGIFNETMASK, &ifbuf, sizeof(ifbuf), pBuf, iBufLen) < 0)
	{
		test_printf_error("test_netioctl_entry");
		netclose(fd, pBuf, iBufLen);
		return;
	}
	netmask = ((struct sockaddr_in*)&(ifbuf.ifr_addr))->sin_addr.s_addr;
	
	if(ip != newip || netmask != newnetmask)
		test_printf_error("test_netioctl_entry");
	else
		test_printf_success("test_netioctl_entry");
	
}