Using getbyhostname()

Hello Experts,

My errors are:

194: warning: assignment makes pointer from integer without a cast
198: error: dereferencing pointer to incomplete type

On lines:

194: if((serverhost = gethostbyname(data[1])) < 0) {    
198: memcpy(&ip->saddr,serverhost->h_addr,serverhost->h_length);

Data is defined as: char *data[20];
LVL 2
mtcmediaAsked:
Who is Participating?
 
AxterConnect With a Mentor Commented:
>>char *data[20];

With this type, data is an array of pointers, which means you must have it point to valid allocated space before using it.
Since you're indexing position 1 in this array of pointers, you need to specificaly validate that position one is getting assigned valid data.

If saddr is a pointer, then you don't need the & sign in front of it.
memcpy(ip->saddr,serverhost->h_addr,serverhost->h_length);
0
 
AxterCommented:
Hi mtcmedia,

What type is data?
What type is saddr?
What type is h_addr?
0
 
AxterCommented:
>>Data is defined as: char *data[20];

How are you allocating space for the variable, and how are you populating it?
0
All Courses

From novice to tech pro — start learning today.