Created
June 4, 2018 00:41
-
-
Save holmeshe/c5a19a16f2accd0a4548c15eda3c13ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…include | |
int main(int argc, char *argv[]) { | |
int sfd, portno, n; | |
struct sockaddr_in srvaddr; | |
struct hostent *host; | |
if (argc < 3) { fprintf(stderr,"usage: %s ip port\n", argv[0]); exit(0); } | |
portno = atoi(argv[2]); | |
sfd = socket(AF_INET, SOCK_STREAM, 0); | |
if (sfd < 0) { perror("ERROR: socket()"); exit(0); } | |
host = gethostbyname(argv[1]); | |
if (host == NULL) { fprintf(stderr,"ERROR: host does not exist"); exit(0); } | |
bzero((char *) &srvaddr, sizeof(srvaddr)); | |
srvaddr.sin_family = AF_INET; | |
srvaddr.sin_port = htons(portno); | |
bcopy((char *)host->h_addr, (char *)&srvaddr.sin_addr.s_addr, host->h_length); | |
if (connect(sfd, (struct sockaddr *)&srvaddr, sizeof(srvaddr)) < 0) { perror("ERROR: connect()"); exit(0); } | |
sleep(100000); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment