X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fsocket-util.c;h=e0f34e71409dec627e16f9938b5512f20534e662;hb=4f1046117c54e60b8ef6b7b21c23d3a4bf2e61fb;hp=f74e43b47cb8ce8449d6090fca5dd21e87e366ab;hpb=6e170b4c7802f4f388ec63d4c1146de830d98669;p=openvswitch diff --git a/lib/socket-util.c b/lib/socket-util.c index f74e43b4..e0f34e71 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010 Nicira Networks. + * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -114,13 +114,27 @@ int lookup_ip(const char *host_name, struct in_addr *addr) { if (!inet_aton(host_name, addr)) { - struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); VLOG_ERR_RL(&rl, "\"%s\" is not a valid IP address", host_name); return ENOENT; } return 0; } +/* Translates 'host_name', which must be a string representation of an IPv6 + * address, into a numeric IPv6 address in '*addr'. Returns 0 if successful, + * otherwise a positive errno value. */ +int +lookup_ipv6(const char *host_name, struct in6_addr *addr) +{ + if (inet_pton(AF_INET6, host_name, addr) != 1) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); + VLOG_ERR_RL(&rl, "\"%s\" is not a valid IPv6 address", host_name); + return ENOENT; + } + return 0; +} + /* Returns the error condition associated with socket 'fd' and resets the * socket's error status. */ int @@ -129,7 +143,7 @@ get_socket_error(int fd) int error; socklen_t len = sizeof(error); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { - struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10); + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10); error = errno; VLOG_ERR_RL(&rl, "getsockopt(SO_ERROR): %s", strerror(error)); } @@ -219,8 +233,7 @@ static void make_sockaddr_un__(const char *name, struct sockaddr_un *un, socklen_t *un_len) { un->sun_family = AF_UNIX; - strncpy(un->sun_path, name, sizeof un->sun_path); - un->sun_path[sizeof un->sun_path - 1] = '\0'; + ovs_strzcpy(un->sun_path, name, sizeof un->sun_path); *un_len = (offsetof(struct sockaddr_un, sun_path) + strlen (un->sun_path) + 1); } @@ -256,6 +269,8 @@ make_sockaddr_un(const char *name, struct sockaddr_un *un, socklen_t *un_len, dirfd = open(dir, O_DIRECTORY | O_RDONLY); if (dirfd < 0) { + free(base); + free(dir); return errno; }