R
Roman Mashak
Hello, All!
Short piece of code:
....
struct in_addr {
unsigned long int s_addr;
};
struct iphdr {
unsigned char ihl:4, version:4;
unsigned char tos;
short unsigned int tot_len;
short unsigned int id;
short unsigned int frag_off;
unsigned char ttl;
unsigned char protocol;
short unsigned int check;
unsigned int saddr;
unsigned int daddr;
};
extern char *inet_ntoa(struct in_addr);
struct iphdr *ip;
....
/* somewhere here 'ip' is filled in with values */
....
printf("%-15s ", inet_ntoa(ip->saddr));
Compiling with "gcc -Wall -g -ansi -pedantic" result with a warning: "
incompatible type for argument 1 of `inet_ntoa' ". I came to know the
solution is to change the call into:
printf("%-15s ", inet_ntoa(*(struct in_addr *)&ip->saddr));
But I can't entirely understand this construction - the conglomeration of
pointers and '&' operators, could you please explain it to me.
PS. It's not homework.
With best regards, Roman Mashak. E-mail: (e-mail address removed)
Short piece of code:
....
struct in_addr {
unsigned long int s_addr;
};
struct iphdr {
unsigned char ihl:4, version:4;
unsigned char tos;
short unsigned int tot_len;
short unsigned int id;
short unsigned int frag_off;
unsigned char ttl;
unsigned char protocol;
short unsigned int check;
unsigned int saddr;
unsigned int daddr;
};
extern char *inet_ntoa(struct in_addr);
struct iphdr *ip;
....
/* somewhere here 'ip' is filled in with values */
....
printf("%-15s ", inet_ntoa(ip->saddr));
Compiling with "gcc -Wall -g -ansi -pedantic" result with a warning: "
incompatible type for argument 1 of `inet_ntoa' ". I came to know the
solution is to change the call into:
printf("%-15s ", inet_ntoa(*(struct in_addr *)&ip->saddr));
But I can't entirely understand this construction - the conglomeration of
pointers and '&' operators, could you please explain it to me.
PS. It's not homework.
With best regards, Roman Mashak. E-mail: (e-mail address removed)