Using sockets in C, is it safe to do this in a function?
int ConnectTo(char *ip, int port){
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
inet_pton(AF_INET, ip, &addr.sin_addr.s_addr);
addr.sin_port = htons(port);
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(connect(sock, (struct sockaddr *) &addr, sizeof(addr))
return sock;
else
return -1;
}
More specifically, the prototype given in 'man connect' is
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
Will I be punished somewhere down the line if the sockaddr structure is trashed later?