Unix advanced sockets etc.

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
 
A

Andre Kostur

Hello,

I have 3 questions, more or less related. Thank you in advance for your
answers!

The real question is are they related to C++?
1) I am trying to find out if netdb.h exists on my current system.
Is "find / -name netdb.h" a solution?

Nope.. not a C++ question.
2) Also how can I eliminate the "Permission denied" lines that this
command prints out?

Neither is this.
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

You're missing an #include for something. You'll have to check the
documentation that's available for your compiler and/or platform.
Nothing here is specifically C++ related.
 
N

Nadina

No they are not related to C++ but I am inclined to believe that one
programms C++ in a certain environment and I am really looking forward
any relevant answer from a UNIX user. Thank you.

Also I don't think I am missing any header because I have man-ed all of
the functions I am using. Thank you for suggestion,
 
L

Larry I Smith

Nadina said:
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

For starters:

change "AI_CANNONNAME" to "AI_CANONNAME"
change "aci_cannonname" to "ai_canonname"

With g++ v3.3.4 on linux (SuSE v9.2) compile with:

g++ -o adv_sock_test adv_sock_test.cpp

There may be more, but I'm late for an appointment...

Regards,
Larry
 
N

Nadina

Correct, I misspeled those. Thnx but that's not what is fundamentally
wrong with my code.

I think the libraries may not be up to date on the machine. I run my
code under SUN OS, with g++ v3.2

Is there any way that I could know exactly what the available std libs
contain?
 
R

Rolf Magnus

Nadina said:
No they are not related to C++

And that's the point. This newsgroup is about the C++ language and nothing
else. This is just how Usenet works, and most Usenet users are quite picky
about that.
but I am inclined to believe that one programms C++ in a certain
environment

For most environments, there are specific newsgroups.
and I am really looking forward any relevant answer from a
UNIX user. Thank you.

Why not ask in comp.unix.programmer then?
Also I don't think I am missing any header because I have man-ed all of
the functions I am using. Thank you for suggestion,

It compiles here (Linux) without errors.
 
N

Nadina

great! thnx a lot, the problem then is with my libraries!
i'll try to respect the rules of the forum :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top