<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
嵌入式 hi3518平台以太网网络模块设计包括重连机制和网线检测机制
最新推荐文章于 2024-08-12 22:25:09 发布