Return NULL on failure.
*/
struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) {
- struct addrinfo *ai, hint = {};
+ struct addrinfo *ai;
int err;
- hint.ai_family = addressfamily;
- hint.ai_socktype = socktype;
+ struct addrinfo hint = {
+ .ai_family = addressfamily,
+ .ai_socktype = socktype,
+ };
err = getaddrinfo(address, service, &hint, &ai);
}
sockaddr_t str2sockaddr(const char *address, const char *port) {
- struct addrinfo *ai, hint = {};
- sockaddr_t result = {};
+ struct addrinfo *ai;
+ sockaddr_t result = {0};
int err;
- hint.ai_family = AF_UNSPEC;
- hint.ai_flags = AI_NUMERICHOST;
- hint.ai_socktype = SOCK_STREAM;
+ struct addrinfo hint = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_NUMERICHOST,
+ .ai_socktype = SOCK_STREAM,
+ };
err = getaddrinfo(address, port, &hint, &ai);