Hello to everyone!!
I am trying to print the MAC address by using ether_ntoa. When i try to do
printf("MAC (src): %s\n",ether_ntoa((struct ether_addr *)&eheader->ether_shost));
I get a segmentation fault, so I have come up with two different approaches:
This is the snippet code nº1:
struct ether_header *eheader;
char *p;
...
p = ether_ntoa(struct ether_addr *) &eheader->ether_shost);
printf("-MAC (src): %s\n",p);
and the warning I obtain is:
assignment makes pointer from integer without a cast
so I do the cast and ...
This is the snippet code nº2:
struct ether_header *eheader;
char *p;
...
p = (char *) ether_ntoa((struct ether_addr *) &eheader->ether_shost);
printf("-MAC (src): %s\n",p);
and the warning I obtain is:
cast to pointer from integer of different size
If you take a look at the man page, ether_ntoa is defined this way, returning a char *:
extern char *ether_ntoa (__const struct ether_addr *__addr) __THROW;
so I don't know what I am doing wrong. The problem is "not" the warning, is the segmentation fault it comes after, when I try to print it.
I am getting this error under openSUSE (in ubuntu I don't need to do this *p trick) so if there is an openSUSE expert here I will appreciate her help.
Thank you very much!