N
Nadina
Hello,
I have 3 questions, more or less related. Thank you in advance for your
answers!
Nadina
1) I am trying to find out if netdb.h exists on my current system.
Is "find / -name netdb.h" a solution?
2) Also how can I eliminate the "Permission denied" lines that this
command prints out?
3) I am not sure if I am compiling properly the following code:
//adv_sock_test.cpp
#include <sys/select.h>
#include <iostream>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <strings.h>
using namespace std;
int main()
{
struct addrinfo hints, *res;
bzero(&hints, sizeof(hints));
hints.ai_flags = AI_CANNONNAME; //return the canonical name of the
host
hints.ai_family = AF_INET;
getaddrinfo("pdc-lab", "domain", &hints, &res);
cout << "host: " << res->aci_cannonname << endl;
}
**************************************************
To compile I use
g++ -Wall -lsocket -lnsl -lc adv_sock_test.cpp -o adv_sock_test
but I get couple of errors:
adv_sock_test.cpp: In function `int main()':
adv_sock_test.cpp:12: aggregate `addrinfo hints' has incomplete type
and
cannot be defined
adv_sock_test.cpp:14: `AI_CANNONNAME' undeclared (first use this
function)
adv_sock_test.cpp:14: (Each undeclared identifier is reported only once
for
each function it appears in.)
adv_sock_test.cpp:17: `getaddrinfo' undeclared (first use this
function)
adv_sock_test.cpp:18: invalid use of undefined type `struct addrinfo'
adv_sock_test.cpp:12: forward declaration of `struct addrinfo'
make: *** [adv_sock_test.cpp] Error 1
I have 3 questions, more or less related. Thank you in advance for your
answers!
Nadina
1) I am trying to find out if netdb.h exists on my current system.
Is "find / -name netdb.h" a solution?
2) Also how can I eliminate the "Permission denied" lines that this
command prints out?
3) I am not sure if I am compiling properly the following code:
//adv_sock_test.cpp
#include <sys/select.h>
#include <iostream>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <strings.h>
using namespace std;
int main()
{
struct addrinfo hints, *res;
bzero(&hints, sizeof(hints));
hints.ai_flags = AI_CANNONNAME; //return the canonical name of the
host
hints.ai_family = AF_INET;
getaddrinfo("pdc-lab", "domain", &hints, &res);
cout << "host: " << res->aci_cannonname << endl;
}
**************************************************
To compile I use
g++ -Wall -lsocket -lnsl -lc adv_sock_test.cpp -o adv_sock_test
but I get couple of errors:
adv_sock_test.cpp: In function `int main()':
adv_sock_test.cpp:12: aggregate `addrinfo hints' has incomplete type
and
cannot be defined
adv_sock_test.cpp:14: `AI_CANNONNAME' undeclared (first use this
function)
adv_sock_test.cpp:14: (Each undeclared identifier is reported only once
for
each function it appears in.)
adv_sock_test.cpp:17: `getaddrinfo' undeclared (first use this
function)
adv_sock_test.cpp:18: invalid use of undefined type `struct addrinfo'
adv_sock_test.cpp:12: forward declaration of `struct addrinfo'
make: *** [adv_sock_test.cpp] Error 1