That restriction comes
way after the actual socket connection part. Logging into the website is something you're responsible for, after you have the TCP part set up.
I'll show you some of my old code that does relatively the same as what you're looking for:
This will actually connect to the website, once you give it an IP (e.g., "60.60.60.60") and a port (use 80 for TCP).
Code:
int init_tcp_conn(char *ip, char *port) {
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct sockaddr_in use;
memset(&use,0x00,sizeof(struct sockaddr_in));
use.sin_family = AF_INET;
use.sin_port = htons(atoi(port));
inet_pton(AF_INET, ip, &use.sin_addr);
if (connect(fd, (struct sockaddr *)&use, sizeof(struct sockaddr)) < 0)
perror("connect");
return fd;
}
The other function will actually retrieve the dots-and-numbers IP from a website URL (e.g., "www.google.com"). From there, you can pass it to the above function ^
Code:
char *get_peer_ip(char *hostname, char *port) {
char *tmp = malloc(20);
struct hostent *he;
struct in_addr **addr_list;
if (he = gethostbyname(hostname) < 0) {
perror("gethost");
}
addr_list = (struct in_addr **)he->h_addr_list;
inet_ntop(AF_INET, (void *)addr_list[0], tmp, INET_ADDRSTRLEN);
return tmp;
}
A quick example on how to implement this?
Code:
char *host = "www.google.com";
char *port = "80";
char *dst = get_peer_ip(host,port);
printf("Got peer IP %s\n", dst);
int fd = init_tcp_conn(dst, port);
printf("Connected.\n");
From here, you can use the send() and recv() calls to make the needed requests to log into the website.