T
Thomas
Hi there,
I write a network prog (it's in c++ but I use the socket api). Here is my func/method:
struct addrinfo* Net::Init(const char *serv) const {
struct addrinfo hints;
bzero(&hints, sizeof(struct addrinfo) );
hints.ai_flags = AI_PASSIVE; // for passive open
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo *res;
int r = 0;
r = getaddrinfo(NULL, serv, &hints, &res);
if (r != 0) {
cout << "Line: " << __LINE__ << endl;
cout << '\n' << gai_strerror(r) << endl;
}
return res;
}
It works but not correct. Here is the call in main:
struct addrinfo *res = cli.Init("http");
listenfd = cli.Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
The problem is: when I pass "http" in cli.Init("http") and call it I get every time another port/service when I view socklist (lists all listening sockets on my ubuntu linux).
Whats wrong here?
Greetings Thomas
I write a network prog (it's in c++ but I use the socket api). Here is my func/method:
struct addrinfo* Net::Init(const char *serv) const {
struct addrinfo hints;
bzero(&hints, sizeof(struct addrinfo) );
hints.ai_flags = AI_PASSIVE; // for passive open
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo *res;
int r = 0;
r = getaddrinfo(NULL, serv, &hints, &res);
if (r != 0) {
cout << "Line: " << __LINE__ << endl;
cout << '\n' << gai_strerror(r) << endl;
}
return res;
}
It works but not correct. Here is the call in main:
struct addrinfo *res = cli.Init("http");
listenfd = cli.Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
The problem is: when I pass "http" in cli.Init("http") and call it I get every time another port/service when I view socklist (lists all listening sockets on my ubuntu linux).
Whats wrong here?
Greetings Thomas