ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
gethostbyname() returns a structure and member of this structure is of type char **h_addr_list.So basicly h_add_list should point to an array of pointers to char.
Instead it points to an aray of pointers to struct in_addr.
How can this even work and why didn't the designers made h_addr_list of type struct in_addr **h_addr_list?
I think struct in_addr is used to hold the IP address.
U pass ip address as a string . Is it right?
If its correct , They used char ** to support for maintanance (or portability) of previous code, because this IP address size (IPv6 new address) will change as the network grows. So they might have used it instead of that struct. When we use char **. we can get the full address regardless of its size(taking \0 as the last character).
I know very little. it may be correct or wrong. Dont scold me if its wrong.
bye,
Eshwar
if you look at the definition of struct in_addr (from netinet/in.h) you will see that the struct only has 1 member which is a 32bit unsigned integer which could be treated as 4 bytes or chars. so thats why it works, as for why they did it - i dont know as my network programming knowledge is quite limited.
I understand,but still h_addr_list points to an array of pointers to structures and when I tried to apply similar syntax in my code(char pointer pointing to a structure of some sort) I got an error.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.