Using getbyhostname()

Posted on 2005-02-24
Medium Priority
Last Modified: 2012-06-22
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];
Question by:mtcmedia
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 30

Expert Comment

ID: 13397742
Hi mtcmedia,

What type is data?
What type is saddr?
What type is h_addr?
LVL 30

Expert Comment

ID: 13397764
>>Data is defined as: char *data[20];

How are you allocating space for the variable, and how are you populating it?
LVL 30

Accepted Solution

Axter earned 1000 total points
ID: 13397814
>>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.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question