|
Home > Archive > Unix Programming > April 2006 > Error in program reading mac address
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Error in program reading mac address
|
|
| jeniffer 2006-04-27, 7:56 am |
| I am trying to run the following program taken from richard stevens
book and I get the following errors.I am not able to get the function
my_addrs functionality correctly implemented.Please help me.
$ gcc -c prmac.c
prmac.c: In function `main':
prmac.c:16: warning: assignment makes pointer from integer without a
cast
$ gcc -o prmac prmac.c
prmac.c: In function `main':
prmac.c:16: warning: assignment makes pointer from integer without a
cast
/tmp/ccSE4HT4.o(.text+0x1b): In function `main':
: undefined reference to `my_addrs'
collect2: ld returned 1 exit status
primac.c =>
#include<sys/ioctl.h>
#include<net/if_arp.h>
#include<netinet/in.h>
int main(int argc, char **argv)
{
int family, sockfd;
char str[INET6_ADDRSTRLEN];
char **pptr;
unsigned char *ptr;
struct arpreq arpreq;
struct sockaddr_in *sin;
pptr = my_addrs(&family);
for ( ; *pptr != NULL; pptr++) {
printf("%s: ", inet_ntop(family, *pptr, str,
sizeof(str)));
switch (family) {
case AF_INET:
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
sin = (struct sockaddr_in *) &arpreq.arp_pa;
bzero(sin, sizeof(struct sockaddr_in));
sin->sin_family = AF_INET;
memcpy(&sin->sin_addr, *pptr, sizeof(struct
in_addr));
ioctl(sockfd, SIOCGARP, &arpreq);
ptr = &arpreq.arp_ha.sa_data[0];
printf("%x:%x:%x:%x:%x:%x\n", *ptr, *(ptr+1),
*(ptr+2), *(ptr+3), *(ptr+4),
*(ptr+5));
break;
default:
printf("unsupported address family: %d",
family);
}
}
exit(0);
}
| |
| Gordon Burditt 2006-04-27, 7:56 am |
| >I am trying to run the following program taken from richard stevens
>book and I get the following errors.I am not able to get the function
>my_addrs functionality correctly implemented.Please help me.
So where is the code for my_addrs()? Did you forget to copy that
part out of the book?
Gordon L. Burditt
| |
| jeniffer 2006-04-27, 7:56 am |
|
Gordon Burditt wrote:
>
> So where is the code for my_addrs()? Did you forget to copy that
> part out of the book?
>
> Gordon L. Burditt
I looked but I cannot find the definition of my_addrs() function in the
header files.
my_addrd() is the author's own wrapper function
This file I saw from the net has the declaration of the function but no
definition
http://www.cs.odu.edu/~cs779/stevens2nd/libgai/unp.h
If anyone can find out the basic function that can be used instead of
my_addrs() it wud be very helpful.
| |
| Barry Margolin 2006-04-27, 7:56 am |
| In article <1145851105.505428.236280@e56g2000cwe.googlegroups.com>,
"jeniffer" <zenith.of.perfection@gmail.com> wrote:
> Gordon Burditt wrote:
>
> I looked but I cannot find the definition of my_addrs() function in the
> header files.
Function definitions are in .c files, not .h. Header files just contain
declarations.
I found this function in:
http://www.cs.odu.edu/~cs779/stevens2nd/lib/my_addrs.c
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Gordon Burditt 2006-04-27, 7:56 am |
| >> >I am trying to run the following program taken from richard stevens
>
>I looked but I cannot find the definition of my_addrs() function in the
>header files.
You don't normally find definitions of functions in header files.
Declarations, yes, definitions, no. You find them in *.c files.
>my_addrd() is the author's own wrapper function
Is this supposed to be the same function as above, or a different one?
If it's the author's function, read his book. You might find the
code in there.
>This file I saw from the net has the declaration of the function but no
>definition
>http://www.cs.odu.edu/~cs779/stevens2nd/libgai/unp.h
>If anyone can find out the basic function that can be used instead of
>my_addrs() it wud be very helpful.
Read the book. If necessary, buy a copy first.
Gordon L. Burditt
|
|
|
|
|