]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <sys/socket.h> | |
4 | #include <netinet/in.h> | |
5 | #include <netdb.h> | |
6 | ||
7 | void | |
8 | init_sockaddr (struct sockaddr_in *name, | |
9 | const char *hostname, | |
10 | unsigned short int port) | |
11 | { | |
12 | struct hostent *hostinfo; | |
13 | ||
14 | name->sin_family = AF_INET; | |
15 | name->sin_port = htons (port); | |
16 | hostinfo = gethostbyname (hostname); | |
17 | if (hostinfo == NULL) | |
18 | { | |
19 | fprintf (stderr, "Unknown host %s.\n", hostname); | |
20 | exit (EXIT_FAILURE); | |
21 | } | |
22 | name->sin_addr = *(struct in_addr *) hostinfo->h_addr; | |
23 | } |