f.ben.isaac@gmail.com
October 15th, 2008, 08:00 AM
Just answer one, you do not have to answer them all.....Plz do a favor:
I can not learn anything new until i fully understand whats going on
what i'm doing now.
**************************************...
FIRST:
I have struct addrinfo *res;
cout<<res;
cout<<&res;
these two above produces two different addresses, why?
**************************************...
SECOND:
Based on the first question.
doing this:
cout<<*res;
Compiler throws an error! why this wouldn't work? *res! does not have an address? It does not exist?!
**************************************...
THIRD:
struct addrinfo hints;
struct addrinfo *res;
struct addrinfo *p;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
//when status is success, a linked list of addrinfo structures is //returned in "res" parameter.
status = getaddrinfo(argv[1], NULL, &hints, &res);
So what i understand is:
res will be pointing to hints, because hints got all data, but res
have nothing. So upon success, res will be pointing to hints. In
other words, res will have an address of hints. But when i output addresses for a check, res address does not appear to be changed:
//after statues returns 0
cout<<&hints<<endl; //holds same address it had
cout<<&res<<endl; //holds same address it had
of course both have different addresses.
My question is: whats the point of returning linked list of
"res" when it actually does not have anything!
Remember: we only filled "hints", res is not filled with anything,
so "res" remained the same it has its same old address, and
its empty as we did not fill anything to it. Where is the effect
of the return then?!!
**************************************...
Please help, i teach myself, so i got no tutor.
Here is the complete code which you may find it useful to give the proper advice:
http://beej.us/guide/bgnet/examples/showip.c
I hope to get some response :(
I can not learn anything new until i fully understand whats going on
what i'm doing now.
**************************************...
FIRST:
I have struct addrinfo *res;
cout<<res;
cout<<&res;
these two above produces two different addresses, why?
**************************************...
SECOND:
Based on the first question.
doing this:
cout<<*res;
Compiler throws an error! why this wouldn't work? *res! does not have an address? It does not exist?!
**************************************...
THIRD:
struct addrinfo hints;
struct addrinfo *res;
struct addrinfo *p;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
//when status is success, a linked list of addrinfo structures is //returned in "res" parameter.
status = getaddrinfo(argv[1], NULL, &hints, &res);
So what i understand is:
res will be pointing to hints, because hints got all data, but res
have nothing. So upon success, res will be pointing to hints. In
other words, res will have an address of hints. But when i output addresses for a check, res address does not appear to be changed:
//after statues returns 0
cout<<&hints<<endl; //holds same address it had
cout<<&res<<endl; //holds same address it had
of course both have different addresses.
My question is: whats the point of returning linked list of
"res" when it actually does not have anything!
Remember: we only filled "hints", res is not filled with anything,
so "res" remained the same it has its same old address, and
its empty as we did not fill anything to it. Where is the effect
of the return then?!!
**************************************...
Please help, i teach myself, so i got no tutor.
Here is the complete code which you may find it useful to give the proper advice:
http://beej.us/guide/bgnet/examples/showip.c
I hope to get some response :(