Function to fill in address structure given an address and port
| 63 | |
| 64 | // Function to fill in address structure given an address and port |
| 65 | static void fillAddr(const string &address, unsigned short port, |
| 66 | sockaddr_in &addr) { |
| 67 | memset(&addr, 0, sizeof(addr)); // Zero out address structure |
| 68 | addr.sin_family = AF_INET; // Internet address |
| 69 | |
| 70 | hostent *host; // Resolve name |
| 71 | if ((host = gethostbyname(address.c_str())) == NULL) { |
| 72 | // strerror() will not work for gethostbyname() and hstrerror() |
| 73 | // is supposedly obsolete |
| 74 | throw SocketException("Failed to resolve name (gethostbyname())"); |
| 75 | } |
| 76 | addr.sin_addr.s_addr = *((unsigned long *) host->h_addr_list[0]); |
| 77 | |
| 78 | addr.sin_port = htons(port); // Assign port in network byte order |
| 79 | } |
| 80 | |
| 81 | // Socket Code |
| 82 |
no test coverage detected