-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.h
49 lines (44 loc) · 1.43 KB
/
socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef SOCKETC_H
#define SOCKETC_H
void IP_d(unsigned char *,char *,char);
int socketData(int ds,genif * s_arp)
{
int index, it;
struct ifreq interfaz;
printf("\nInserte nombre de la interfaz:\n");arrow();
scanf("%s",interfaz.ifr_name);
getchar();
if(ioctl(ds,SIOCGIFINDEX,&interfaz)==-1)
perror("\n[Error al obtener índice]\n");
else
{
index = interfaz.ifr_ifindex;
if(ioctl(ds,SIOCGIFHWADDR,&interfaz)==-1){perror("\n[Error al obtener MAC]\n"); return 0;}
else memcpy(s_arp->mac,interfaz.ifr_hwaddr.sa_data,6);
if(ioctl(ds,SIOCGIFNETMASK,&interfaz)==-1)
{perror("\n[Error al obtener Máscara de subred]\n");return 0;}
else memcpy(s_arp->subn,interfaz.ifr_netmask.sa_data+2,4);
if(ioctl(ds,SIOCGIFADDR,&interfaz)==-1){perror("\n[Error al obtener IP]\n");return 0;}
else memcpy(s_arp->ip,interfaz.ifr_addr.sa_data+2,4);
}
IP_d(s_arp->gateway_ip,NULL,'g');
return index;
}
void print32bit(unsigned char * ADDR)
{
printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",ADDR[0],ADDR[1],ADDR[2],ADDR[3],ADDR[4],ADDR[5]);
}
void print16bit(unsigned char * ADDR)
{
printf("%d.%d.%d.%d",ADDR[0],ADDR[1],ADDR[2],ADDR[3]);
}
void fmtpSocketInfo(genif s_arp)
{
printf("\n");
printf("[ MAC ] ~ "); print32bit(s_arp.mac);
printf("\n[Subred] ~ "); print16bit(s_arp.subn);
printf("\n[ IP ] ~ "); print16bit(s_arp.ip);
printf("\n[ GW ] ~ "); print16bit(s_arp.gateway_ip);
puts("");
}
#endif