but you didn't refer to the int value inside the struct.
it's just a portion of something i would like to achieve.
here is another example.
file: tester.c
Code:
#include <stdio.h>
#include <string.h>
//#include "z.h"
#include "/usr/include/netinet/ip.h"
void func(struct ip *ip) {
printf("ip_ttl func: %d\n", (*(struct ip *)ip).ip_ttl);
}
int main() {
struct ip tmp;
memset(&tmp, 0, sizeof(struct ip));
tmp.ip_ttl = 0x4;
char buf[sizeof(struct ip)];
memset(buf, 0, sizeof(struct ip));
memcpy(buf, &tmp, sizeof(struct ip));
printf("ip_ttl main: %d\n", tmp.ip_ttl);
printf("ip_ttl main: %d\n", (*(struct ip *)buf).ip_ttl);
func((struct ip *)&tmp);
func((struct ip *)buf);
return 0;
}
and the output for it:
# ./tester
ip_ttl main: 4
ip_ttl main: 4
ip_ttl func: 4
ip_ttl func: 4
now modifying it to:
file: tester.c
Code:
#include <stdio.h>
#include <string.h>
#include "z.h"
/*#include "/usr/include/netinet/ip.h"
void func(struct ip *ip) {
printf("ip_ttl func: %d\n", (*(struct ip *)ip).ip_ttl);
}*/
int main() {
struct ip tmp;
memset(&tmp, 0, sizeof(struct ip));
tmp.ip_ttl = 0x4;
char buf[sizeof(struct ip)];
memset(buf, 0, sizeof(struct ip));
memcpy(buf, &tmp, sizeof(struct ip));
printf("ip_ttl main: %d\n", tmp.ip_ttl);
printf("ip_ttl main: %d\n", (*(struct ip *)buf).ip_ttl);
func((struct ip *)&tmp);
func((struct ip *)buf);
return 0;
}
file: z.h
Code:
#ifndef Z_H
#define Z_H
#include "/usr/include/netinet/ip.h"
void func(struct ip *ip);
#endif
file: z.c
Code:
#ifndef Z_C
#define Z_C
#include "z.h"
#include <stdio.h>
void func(struct ip *ip) {
printf("ip_ttl func: %d\n", (*(struct ip *)ip).ip_ttl);
}
#endif
the output now is the same as above.
but, when i try to do the same thing around other program of mine. it gives me the "dereferencing pointer to incomplete type".
SHOULD I PAST MY ORIGINAL CODE?
WILL SOMEONE BE ABLE TO HELP?