On Tue, 30 Aug 2016 21:38:51 +0200, "R.Wieser" <add...@not.available>
wrote:
>For all people that tried to help me find a solution to that "server"
>variable problem, it turns out to be rather simple, and due to a mistake
>made by me.
>
Nothing new here.
>Yes!, I'm one of those people that does not run away when he has made one,
>and comes out openly for it. If you can't handle that, tough shit.
>
>
>But don't think you're without blame here !.
>
>
>From my initial message:
>
>> The only way I was able to do that was to refer to the first
>> (and in this case only) field in that structure:
>>
>> foobar( (unsigned char*) server->h_addr, ... )
>
>*Both* the "first" and "only" descriptions where wrong. Next to that
>"h_addr" isn't even a field in that hostent record, but in a ipv4/ipv6 table
>that the hostent record holds a pointer to, and *noone* here noticed any of
>those three mistakes. Doesn't anybody actually *read* a question before
>replying to it ? :-( :-)
>
>(I was actually thinking of another structure, just holding an ipv4 or ipv6
>address)
>
A fact that would have proved to be obvious had you posted a complete
and correct problem statement WITH the hostent struct:
typedef struct hostent {
char FAR *h_name;
char FAR FAR **h_aliases;
short h_addrtype;
short h_length;
char FAR FAR **h_addr_list;
} HOSTENT, *PHOSTENT, FAR *LPHOSTENT;
So the struct your server pointer was pointing to was the wrong struct
in the first place and given your insistence that your problem
statement was complete and correct this group should have recognized
your error?
The group is supposed to research the hostent struct outside of your
problem statement and determine your error based on incorrect and
incomplete information you provide?
And if they don't do this it's because /they/ didn't read but you
can't be bothered to read beginner tutorials about C++ while at the
same time you admit to being a novice in C++. Then you have the
arrogance to criticize the advice you received based on your own
mistaken belief in the correctness of your problem statement.
I remind you the group is about C++, not about socket programming and
you do the group a disservice if you demand they all be experts of the
structs within the Sockets stack. They were focused on the principles
of C++ and the nature of the semantics of your (incorrectly stated)
problem and your misconceptions about it.
NOTE
From Linux man 3 gethostbyname
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
}
#define h_addr h_addr_list[0] /* for backward compatibility */
From Microsoft's WinSock.h:
struct hostent {
char FAR * h_name; /* official name of host */
char FAR * FAR * h_aliases; /* alias list */
short h_addrtype; /* host address type */
short h_length; /* length of address */
char FAR * FAR * h_addr_list; /* list of addresses */
#define h_addr h_addr_list[0] /* address, for backward
compat */
};
If you had included either of these definitions, as requested, it
would have been obvious to all and to you long ago.
>
>In the end it turned out that "foobar( (unsigned int*) server , ...)" (which
>I had tried long before posting my problem here) actually did give me the
>address of the hostent structure, but as "server->h_addr" and the above
>where not looking at the same spot (remember, I thought that h_addr was the
>first-and-only field in the record) I assumed I was looking at the pointer
>variables data (the addres to the structure) itself (where "server->h_addr"
>showed me, by accident, the expected IPv4 address)
>
*********************************************************************
Note this:
>I do not know anymore who all suggested using just "server", you guys where
>right all along.
Everything in this admission is perfect - then comes the ego:
>Heck, even *I* was right, long before you guys :-)
>
*********************************************************************
Since you were right long before everyone else, the entire thread need
never have been started except you posted the question and then
rejected every bit of advice you received and insisted "it doesn't
work" throughout.
>For all who suggested "*server" or "server->". Sorry, no go.
>
>
>My apologies for not having played a subdued novice all along, but heck, do
>you guys fail at reading and trying to figure out what could have gone wrong
>...
No, the group didn't fail at reading. What they were reading was the
petulant and arrogant rants of someone who thinks he knows more than
the people from whom he is seeking help even while he admits to being
a complete novice on the topic. Pure arrogance.
>
>And no, that does not take anything away from the mistakes I made myself.
>The initial wrong assumption, and having waited so long before
>double-checking if that "h_addr" field was where I thought it would be.
>
>Regards,
>Rudy Wieser
>
>
>-- Origional message:
>R.Wieser <add...@not.available> schreef in berichtnieuws
>57c4895a$0$871$e4fe...@news.xs4all.nl...
>> Hello all,
>>
>> Fair warning: I'm a novice in regard to using C++ (GCC) *and* using linux
>> (lubuntu to be exact). If this is not the newsgroup to be asking
>questions
>> like the below than please advice which newsgroup(s) to use instead.
>>
>> - - - - - -
>> First problem, C++ related:
>>
>> I need to transfer the address of a structure to a function, and have only
>> be able to find a hackish solution for it. The problem is that the
>variable
>> I've got is actually a pointer, and I have no idea how to dereference it.
>>
>> The variable declaration and initialisation in case:
>>
>> struct hostent *server;
>> server = gethostbyname(argv[1]);
>>
>> Now I want to transfer the address stored in the "server" variable to a
>> function. The only way I was able to do that was to refer to the first
>(and
>> in this case only) field in that structure:
>>
>> foobar( (unsigned char*) server->h_addr, ... )
>>
>> I read somewhere that I could use (*server) , but trying it ( (unsigned
>> char*) (*server) ) gave a compile-time error.
>>
>> In short: How do I dereference that "server" variable so the function
>> receives a pointer to the structure ?
>>
>> - - - - - -
>> Second problem, Linux related:
>>
>> As someone wo has spend quite some time on Windows I'm rather accustomed
>> being able to pick a DLL and look inside it to see which functions it
>> exposes that I can use (yeah, I still have to generate a library from it
>and
>> find the function declarations, but thats not the point).
>>
>> I have no idea how to do the same under Linux (and/or how to convert the
>> found functions (system calls ?) to something I can use in C++ ).
>>
>> To be honest, I have no idea if the above is even feasible for C++ (GCC)
>> under linux.
>>
>> I did find an example using "nm", but that only showed the contents of the
>> .o (library) file, and only if the info was not stripped.
>>
>> I also tried that on the full /usr directory, but could not even find
>> "fprint" (found buf_fprint" and "str_fprint" though).
>>
>>
>> And now I'm on a roll asking questions, one thing I did not expect was to
>> find multiple (sometimes over 10) same-named header files , most often of
>> different sizes. Whats the idea behind that, and how should I know which
>> one of those to include ?
>>
>> Regards,
>> Rudy Wieser
>>
>>
>>
>