Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:12.2:PowerPC
multitail
multitail-getaddrinfo.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File multitail-getaddrinfo.patch of Package multitail
--- cmdline.c.orig 2012-01-01 12:48:44.644473139 +0100 +++ cmdline.c 2012-01-01 13:17:50.776411019 +0100 @@ -182,11 +182,16 @@ void add_redir_to_socket(char filtered, char *prio, char *fac, char *address, redirect_t **predir, int *n_redirect) { - struct hostent *hp; char *local_address = mystrdup(address, __FILE__, __PRETTY_FUNCTION__, __LINE__); char *colon = strchr(local_address, ':'); int prio_nr = -1, fac_nr = -1; int loop; + char* node; + char* service; + struct addrinfo hints; + struct addrinfo* result; + struct addrinfo* rp; + int s, sfd; *predir = (redirect_t *)myrealloc(*predir, (*n_redirect) * sizeof(redirect_t), __FILE__, __PRETTY_FUNCTION__, __LINE__); @@ -199,21 +204,44 @@ (*predir)[*n_redirect].redirect = mystrdup(address, __FILE__, __PRETTY_FUNCTION__, __LINE__); - (*predir)[*n_redirect].fd = socket(AF_INET, SOCK_DGRAM, 0); - if ((*predir)[*n_redirect].fd == -1) - error_exit(__FILE__, __PRETTY_FUNCTION__, __LINE__, "Cannot create socket for redirecting via syslog protocol.\n"); - - memset(&(*predir)[*n_redirect].sai, 0x00, sizeof((*predir)[*n_redirect].sai)); - (*predir)[*n_redirect].sai.sin_family = AF_INET; if (colon) { *colon = 0x00; - (*predir)[*n_redirect].sai.sin_port = atoi(colon + 1); + node = local_address; + service = colon + 1; } else - (*predir)[*n_redirect].sai.sin_port = 514; - hp = gethostbyname(local_address); - memcpy(&(*predir)[*n_redirect].sai.sin_addr.s_addr, hp -> h_addr, hp -> h_length); + { + node = local_address; + service = "syslog"; + } + + memset(&hints, 0x00, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = 0; + hints.ai_protocol = 0; + + s = getaddrinfo(node, service, &hints, &result); + if (s != 0) + error_exit(__FILE__, __PRETTY_FUNCTION__, __LINE__, "Cannot create socket for redirecting via syslog protocol: %s.\n", gai_strerror(s)); + + for (rp = result; rp != NULL; rp = rp -> ai_next) + { + sfd = socket(rp -> ai_family, rp -> ai_socktype, rp -> ai_protocol); + if (sfd == -1) + continue; + if (connect(sfd, rp -> ai_addr, rp -> ai_addrlen) != -1) + break; + close(sfd); + } + + freeaddrinfo(result); + + if (rp == NULL) + error_exit(__FILE__, __PRETTY_FUNCTION__, __LINE__, "Cannot create socket for redirecting via syslog protocol.\n"); + + (*predir)[*n_redirect].fd = sfd; for(loop=0; loop<8; loop++) { --- mt.c.orig 2012-01-01 13:07:22.315433377 +0100 +++ mt.c 2012-01-01 13:17:29.752411767 +0100 @@ -2295,31 +2295,54 @@ { char *dummy = mystrdup(cur -> filename, __FILE__, __PRETTY_FUNCTION__, __LINE__); char *colon = strchr(dummy, ':'); - struct sockaddr_in sa; - socklen_t ssai_len = sizeof(sa); - char *host = "0.0.0.0"; - int port = 514; + struct addrinfo hints; + struct addrinfo* result; + struct addrinfo* rp; + int sfd, s; - cur -> wfd = cur -> fd = socket(AF_INET, SOCK_DGRAM, 0); - if (cur -> fd == -1) - error_exit(__FILE__, __PRETTY_FUNCTION__, __LINE__, "Failed to create socket for receiving syslog data.\n"); + char *host = NULL; + char *service = "syslog"; if (colon) { - port = atoi(colon + 1); - if (port <= 0) - error_exit(__FILE__, __PRETTY_FUNCTION__, __LINE__, "--[Ll]isten requires a >= 0 portnumber.\n"); + service = colon + 1; *colon = 0x00; if (colon > dummy) host = dummy; } - memset(&sa, 0x00, ssai_len); - sa.sin_family = AF_INET; - sa.sin_port = htons(port); - sa.sin_addr.s_addr = inet_addr(host); - if (bind(cur -> fd, (struct sockaddr *)&sa, ssai_len) == -1) - error_exit(__FILE__, __PRETTY_FUNCTION__, __LINE__, "Failed to bind socket to %s.\n", cur -> filename); + memset(&hints, 0x00, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = AI_PASSIVE; + hints.ai_protocol = 0; + hints.ai_canonname = NULL; + hints.ai_addr = NULL; + hints.ai_next = NULL; + + s = getaddrinfo(host, service, &hints, &result); + if (s != 0) + error_exit(__FILE__, __PRETTY_FUNCTION__, __LINE__, "Failed to create socket for receiving syslog data on %s: %s.\n", cur -> filename, gai_strerror(s)); + + for (rp = result; rp != NULL; rp = rp -> ai_next) + { + sfd = socket(rp -> ai_family, rp -> ai_socktype, rp -> ai_protocol); + if (sfd == -1) + continue; + if (bind(sfd, rp -> ai_addr, rp -> ai_addrlen) == 0) + break; + close(sfd); + } + + freeaddrinfo(result); + + if (rp == NULL) + error_exit(__FILE__, __PRETTY_FUNCTION__, __LINE__, "Failed to create socket for receiving syslog data on %s.\n", cur -> filename); + + cur -> wfd = cur -> fd = sfd; + + cur -> wfd = cur -> fd = socket(AF_INET, SOCK_DGRAM, 0); + if (cur -> fd == -1) myfree(dummy);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor