www.pudn.com > mypro-telnet.rar > getIP.c, change:2010-07-15,size:7239b


#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <strings.h> 
#include <netinet/in.h> 
#include <arpa/inet.h> 
 
typedef struct DevParam	 
{     
     unsigned int version;			    //00-01 硬件版本号  
     //unsigned char  mac[2];          //02-03 空闲MAC地址 
     unsigned int   devID;             //04-07 设备id 
     unsigned char  localIP[4];        //08-0B IP地址 
     unsigned char  gateIP[4];         //0C-0F 网关 
     unsigned char  netMask[4];	       //10-13 子网掩码 
     unsigned short dnsPort;           //14-15 端口 
     unsigned char  centerIP[4];       //16-19 服务器IP 
     unsigned char  dnsIP[4];   	   //1A-1D DNS服务器IP 
     unsigned short registTime;        //1e-1F 注册服务器时间 
     unsigned char  domainName[32];    //20-3F 域名 
     unsigned char  hostName[32];      //40-5F 主机名 
     unsigned char  username[8];       //60-67 登陆用户名 
     unsigned char  password[8];	   //68-6F 登陆密码 
     unsigned short baudRate;		   //70-71 控制云台波特率 
     unsigned short alarmPtr[6];	   //72-7d 四个报警量和2个报警输出量的配置信息地址 
     unsigned short usbStorePtr;  	   //7e-7f  
      
     unsigned char  pppoe;             //80-80 
     unsigned char  staticIP;          //81-81 静态IP开关 
     unsigned char  pppUsername[30];   //82-9F pppoe的用户名 
     unsigned char  PPPPassword[30];   //A0-BD pppoe的密码 
     unsigned char  audioFormat;	   //BE-BE 音频格式 
     unsigned char  audioInterval;	   //BF-BF 音频打包间隔 
     unsigned char  comRxMode;		   //c0-C0 串口数据接收模式  0爱康威  1首信  
     unsigned char  pswNeed;           //c1-c1 是否需要操作密码 
     unsigned char  vgamode;		   //c2-c2 VGA显示模式设置 
     unsigned char  outmode;		   //c3-c3 VGA显示模式设置 
     unsigned short ddns;			   //c4-c5 
     unsigned char  wifi;              //c6-c6 
     unsigned char  wifimode;          //c7-c7 
     unsigned short wifiCodeaddr;      //c8-c9 
     unsigned char  wifiASC;           //ca-ca //十六进制(0)ASCII(1) 
     unsigned char  DD;                //cb-cb 
     char			NTPServerIP[4];    //cc-cf 
     short			infoaddr;          //d0-d1 
     short			TimeRegion;        //d2-d3 
     unsigned short ptrPlatForm;       //d4-d5 平台参数指针 
     unsigned short webServicePort;	   //d6-d7 web Service端口 
     unsigned char  NOUSED[4];         //d8-db 空 
     char           wifinum;           //dc-dc 
     unsigned char  DHCP;              //dd-dd dhcp开关 
	 unsigned char  wifiIP[4];         //de-e1 
     unsigned char  wifimask[4];       //e2-e5 
     unsigned char  wifigateway[4];	   //e6-e9  
     unsigned short	webTcpPort;		   //ea-eb web 媒体服务端口 
     unsigned short TimePlan;          //ec-ed 各种报警的时间策略指针 
     unsigned short connectPORT;       //ee-ef 端口 
     unsigned char  connectIP[4];      //f0-f3 接入服务器的ip(备用) 
     unsigned char  udata;             //f4-f4 串口参数 
     unsigned char  ustop;			   //f5-f5 停止位 
     unsigned char  ucheck;			   //f6-f6 校验位 
     unsigned char  workModule;        //f7-f7 工作模式0表示被动,1表示主动 
     int            MultiCastGIP;	   //f8-fb 多播组IP 
     unsigned short MultiCastGPort;    //fc-fd 多播组PORT		   
     unsigned int   softVersion; 		//fe-ff 
     unsigned int	EncoderVer;			//编码器版本 
     int 			MaxChannel;			//最大通道 
     unsigned char  devMac[6];			//MAC地址 
} __attribute__((packed))DevParam; 
 
typedef struct ZXDevParam		 
{ 
	char			ID_Dev[32];			//c0-df  视频服务器的设备ID 
	unsigned char	registPwd[32];		//注册密码16 
	unsigned char	fdnsIP[4];			 
	char			SipAliveIP[4]; 		//64-67  Sip心跳IP 
	unsigned short	SipAlivePort;		//68-69  Sip心跳端口 
	unsigned short	SipRegPort;			//6a-6b  Sip注册端口 
	char			SipRegIP[4]; 		//6c-6f  Sip注册IP 
	char			AliveIP[4];			//心跳主机 
	unsigned short	AlivePort;			//心跳主机端口 
	unsigned short	mediaPort;			//媒体端口号 
	unsigned short	mediaCtrPort;		//媒体控制端口号 
	char			AlarmServerIp[4];	//管理服务器IP 
	unsigned short	AlarmServerPort;	//管理服务器PORT 
	unsigned short	wifiPoint;			//wifi参数指针				//delete 
	unsigned char	MaxConnect;			//每个通道的最大连接数 
	unsigned int	RegisterValidTime; 	//100-103		注册有效时长(单位s),超过有效时长后视频服务器重新发送注册消息,以小时为单位。 
	char			FtpServer[4];       //10c-10f   	ftp远程存储服务器IP 
	unsigned short	FtpPort;     	   	//110-111   	ftp远程存储服务器PORT 
	unsigned char	SpaceAlarm;			//112-112       硬盘满报警阀值(0-100) 
	char  			FtpUsername[32];   	//114-133  	ftp远程存储服务器用户名 
	char  			FtpPassword[32];   	//134-153 	ftp远程存储服务器密码 
	unsigned char	AliveEnable;        //154-154	是否使能心跳 
	unsigned short	PuSipPort;			//158-159	前端SIP端口 
	unsigned char	enableSipRegister;	//15a-15a	是否使能SIP注册 
	unsigned char	enableSipHeartbeat;	//15b-15b	是否使能SIP心跳 
	unsigned short	sipHeartbeatPeriod;	//15c-15d	SIP心跳周期,以秒为单位 
	char			alarmURL[32];      	//15e-17d	接收告警信号的URL 
	unsigned char	ComFlowBit;        	//181-181 	溢出位  
	unsigned char 	diskFullAlarmEnabled;	//182-182	硬盘满报警使能 
	unsigned char 	diskErrorAlarmEnabled;	//183-183	硬盘错误报警使能 
	unsigned short	videoMonitorEn;     //184-185 
	unsigned short	MonitorInterval;    //186-187 
	unsigned short	SerialTimeOut;		//188-189	串口接收超时时间	  
 
	char            remoteControlID[128]; 
}__attribute__((packed))ZXDevParam; 
 
DevParam  devParam; 
ZXDevParam  ZXdevParam; 
 
int readDevParm() 
{ 
	FILE *fpDev = NULL; 
	 
	if ((fpDev=fopen("/dvs/Dev.bin","r")) == NULL) 
	{	 
		printf("Error:Can't open the file Dev.bin!\n"); 
		return -1; 
	} 
	else 
	{ 
		if (fread(&devParam,1,sizeof(DevParam),fpDev) != sizeof(DevParam)) 
		{ 
			printf("Error:Reading from Dev.bin failed!\n"); 
			return -1; 
		} 
		if (fread(&ZXdevParam,1,sizeof(ZXDevParam),fpDev)!=sizeof(ZXDevParam)) 
		{ 
			printf("Error:Reading from Dev.bin failed!\n");	 
			return -1; 
		} 
		fclose(fpDev); 
	}	 
	return 0; 
} 
 
void getMac(void) 
{ 
	FILE *pFd=NULL; 
	unsigned int datalen; 
	char buf[100]; 
	 
    pFd = fopen("/dvs/macaddr.bin", "r"); 
    if (pFd != NULL) 
	{	 
		datalen = fread(buf,1,50,pFd); 
		if (datalen >= 6) 
		{ 
			devParam.devMac[0] = buf[0]; 
	        devParam.devMac[1] = buf[1]; 
	        devParam.devMac[2] = buf[2]; 
	        devParam.devMac[3] = buf[3]; 
	        devParam.devMac[4] = buf[4]; 
	        devParam.devMac[5] = buf[5];  
	    }	 
		fclose(pFd); 
	} 
	else 
	{ 
		devParam.devMac[0] = 0x00; 
		devParam.devMac[1] = 0x90; 
		devParam.devMac[2] = 0xb0; 
		devParam.devMac[3] = 0x12; 
		devParam.devMac[4] = 0x34; 
		devParam.devMac[5] = 0x56; 
	} 
}  
 
int main(int argc, char* argv[]) 
{ 
	if (readDevParm() < 0) 
		return -1; 
	 
	getMac(); 
	printf("ethaddr: %02X:%02X:%02X:%02X:%02X:%02X\n",devParam.devMac[0],devParam.devMac[1],devParam.devMac[2],devParam.devMac[3],devParam.devMac[4],devParam.devMac[5]); 
	printf("ipaddr: %d.%d.%d.%d\n",devParam.localIP[0],devParam.localIP[1],devParam.localIP[2],devParam.localIP[3]); 
	printf("netmask: %d.%d.%d.%d\n",devParam.netMask[0],devParam.netMask[1],devParam.netMask[2],devParam.netMask[3]); 
	printf("gatewayip: %d.%d.%d.%d\n",devParam.gateIP[0],devParam.gateIP[1],devParam.gateIP[2],devParam.gateIP[3]); 
 
	return 0; 
}