memcpy(Ret_IP , &tSpoofing_IP ,sizeof(int));
// resolution MAC to ethernet format
if(MAC_FormatCheck(MAC_s)==0)
goto ResError ;
for(int i=0 ; i<6 ;i++)
{
Ret_MAC[i] = MAC_SubFormatTransform(&MAC_s[i*3]) ;
}
return 1;
ResError :
memset(Ret_IP ,0 ,sizeof(char)*15);
memset(Ret_MAC ,0 ,sizeof(char)*17);
return 0 ;
}
//--------------------------------------------------------------------------
// **********************************
// Get Localhost Interface information
// **********************************
//
// get localhost MAC and IP via iface
int getInterfaceInfo(unsigned char * iface ,unsigned char *local_IP ,unsigned char *local_MAC )
{
// Get MAC address
char tMAC[18]="";
char ifPath[256]="/sys/class/net/";
strcat(ifPath ,(char*)iface);
strcat(ifPath ,"/address");
FILE *if_f =fopen(ifPath , "r");
if(if_f == NULL)
return 0 ;
else
{
fread(tMAC ,1 ,17 ,if_f); //read MAC from /sys/class/net/iface/address
fclose(if_f) ;
for(int i=0 ; i<6 ;i++) // confirm data to local_MAC
{
*(local_MAC+i) = MAC_SubFormatTransform(&tMAC[i*3]) ;
}
}
// Get IP address
// using ioctrl to get local IP ,
// it may not bt an best way to achive that , i still search another way
int fd;
struct ifreq ifr;
in_addr tIP ;
fd = socket(AF_INET, SOCK_DGRAM, 0); //using ioctl get IP address
ifr.ifr_addr.sa_family = AF_INET;
strcpy(ifr.ifr_name , (char*)iface);
ioctl(fd, SIOCGIFADDR, &ifr);
close(fd);
tIP =((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;
memcpy((char*)local_IP , &tIP ,sizeof(in_addr));
return 1;
}
//--------------------------------------------------------------------------
// ************************************
// Fetch Localhosdt ARP table
// ************************************
// find IP or MAC from localhost arp table ,
#define FETCH_ARP_TABLE_ERROR 0x0000 // could not access localhost ARP table
#define FETCH_ARP_TABLE_SUCCESS 0x0001 // find ARP entry
#define FETCH_ARP_TABLE_UNKNOW 0x0002 // ARP entry unknow or empty
int FetchARPTable(char * TargetIP , char * TargetMAC)
{
// ARP table at /proc/net/arp
int ret =FETCH_ARP_TABLE_UNKNOW;
FILE *ARP_f =fopen("/proc/net/arp" , "r");
if(ARP_f == NULL)
{
ret =FETCH_ARP_TABLE_ERROR;
}
else
{
// pass title
char Title[100] ; //file title , pass that
fgets(Title ,100 ,ARP_f);
char t_IP[15] ;
char t_HW_type[8] ;
char t_Flags[8] ;
char t_MAC[17] ;
char t_Mask[5] ;
char t_Device[16] ;
while(!feof(ARP_f)) //search arp table
{
fscanf(ARP_f ,"%s %s %s %s %s %s",t_IP,t_HW_type,t_Flags,t_MAC,t_Mask,t_Device);
1127

被折叠的 条评论
为什么被折叠?



