f.ben.isaac@gmail.com
October 16th, 2008, 10:32 PM
struct addrinfo hints, *res;
int sockfd;
// first, load up address structs with getaddrinfo():
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo("www.example.com", "3490", &hints, &res);
// make a socket:
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
// connect!
connect(sockfd, res->ai_addr, res->ai_addrlen);
This is an example where we make a socket connection to “www.example.com”, port 3490....
we didn't call bind(). Basically, we don't care about our local port number; we only care where we're going (the remote port). The kernel will choose a local port for us, and the site we connect to will automatically get this information from us.
Isn't port 3490 getaddrinfo("www.example.com", "3490", &hints, &res);
refers to the local port? - The underlined part confuses me, because we already specified the local port which is 3490....
I'm confused
int sockfd;
// first, load up address structs with getaddrinfo():
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo("www.example.com", "3490", &hints, &res);
// make a socket:
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
// connect!
connect(sockfd, res->ai_addr, res->ai_addrlen);
This is an example where we make a socket connection to “www.example.com”, port 3490....
we didn't call bind(). Basically, we don't care about our local port number; we only care where we're going (the remote port). The kernel will choose a local port for us, and the site we connect to will automatically get this information from us.
Isn't port 3490 getaddrinfo("www.example.com", "3490", &hints, &res);
refers to the local port? - The underlined part confuses me, because we already specified the local port which is 3490....
I'm confused