嵌入式 hi3518平台以太网网络模块设计包括重连机制和网线检测机制

本文档介绍了一个基于hi3518平台的以太网网络模块设计,包括网络接口定义、重连机制和网线状态检测。通过使用`ioctl`和`socket`系统调用,实现了对网络接口状态的检查,如`eth0`的链接状态和IP地址获取。此外,还提供了网络连接状态的检查函数`Joseph_Get_Netlink_Status`,用于监测网络连接是否正常,并结合`Joseph_Ping`实现网络可用性验证。
摘要由CSDN通过智能技术生成
<span style="font-family:Courier New;">
#include <sys/types.h>  
#include <string.h>  
#include <stdlib.h>  
#include <sys/ioctl.h>  
#include <sys/stat.h>  
#include <stdio.h>  
#include <string.h>  
#include <errno.h>  
#include <net/if.h>  
#include <sys/utsname.h>  
#include <limits.h>  
#include <ctype.h>     
#include <sys/socket.h>  
#include <arpa/inet.h>     
#include <linux/sockios.h>  
#include <sys/socket.h>   
#include <netinet/ip.h>   
#include <netinet/ip_icmp.h>   
#include <netdb.h>  
#include <netinet/in.h>

#define JOSEPH_LOOP_INTERFACE 			"lo"
#define JOSEPH_ETH_INTERFACE 			"eth0"
#define JOSEPH_WIRLESS_INTERFACE 		"wlan0"

#define ETHTOOL_GLINK   				0x0000000a   /* Get link status (ethtool_value) */  
#define JSOEPH_NET_CHECK_PACKET_SIZE    4096   
#define JOSEPH_NET_CHECK_TIME			3000

typedef struct Joseph_Net_Interface_Info
{
	int net_device_type;// 0 ~ eth0 ; 1 ~ wlan ;3 ~ ppp0
	int net_device_priority;// 0 ~ eth0 ; 1 ~ wlan ;3 ~ ppp0
	int	net_device_status;//0 ~ down; 1 ~ up
	int net_device_link_status;//0 ~ no ;1 ~ yes
	char net_device_name[8];
	char net_device_ip[16];
	char net_device_mac_info[32];
	char net_device_gw_info[16];
	char net_device_mask_info[16];
	char net_device_broadcast_info[16];
		
}JOSEPH_NET_INTERFACE_INFO;

typedef struct Joseph_Ethtool_Value {  
	unsigned int   cmd;  
	unsigned int   data;   
}JOSEPH_ETHTOOL_VALUE;

enum Joseph_Net_Device_Type
{
	JOSEPH_ETH = 0,
	JOSEPH_WIFI = 1,
	JOSEPH_3G = 2,
}JOSEPH_NET_DEVICE_TYPE;

unsigned short Joseph_Cal_Chksum(unsigned short *addr, int len)	
{  
	int nleft=len;  
	int sum=0;  
	unsigned short *w=addr;  
	unsigned short answer=0;	

	while(nleft > 1)	
	{  
	  sum += *w++;	
	  nleft -= 2;  
	}  

	if( nleft == 1)  
	{ 		
	  *(unsigned char *)(&answer) = *(unsigned char *)w;  
	  sum += answer;  
	}  

	sum = (sum >> 16) + (sum & 0xffff);  
	sum += (sum >> 16);  
	answer = ~sum;  

	return answer;  
}  

int Joseph_Ping( char *ips,char *srcip , int timeout)
{ 	   

	int n;
	pid_t pid;	
	int maxfds = 0;	 
	fd_set readfds;	 

	struct ip *iph;	 
	struct icmp *icmp;	
	struct timeval *tval; 		 
	struct sockaddr_in addr;	  
	struct sockaddr_in from;
	struct ifreq ifr;
	
	bzero(&addr,sizeof(addr));
	addr.s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值