Login
Log in using an SSO provider:
Fedora Account System
Red Hat Associate
Red Hat Customer
Login using a Red Hat Bugzilla account
Forgot Password
Create an Account
Red Hat Bugzilla – Attachment 748281 Details for
Bug 880698
glibc: getaddrinfo() doesn't order results correctly when node is NULL
Home
New
Search
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh90 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
[?]
This site requires JavaScript to be enabled to function correctly, please enable it.
Uli Drepper's server example code, hacked up slightly by me
drepper-srv.c (text/x-csrc), 2.39 KB, created by
Markus Armbruster
on 2013-05-15 13:08:24 UTC
(
hide
)
Description:
Uli Drepper's server example code, hacked up slightly by me
Filename:
MIME Type:
Creator:
Markus Armbruster
Created:
2013-05-15 13:08:24 UTC
Size:
2.39 KB
patch
obsolete
>#include <error.h> >#include <errno.h> >#include <netdb.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> >#include <netinet/in.h> >#include <sys/poll.h> >#include <arpa/inet.h> > >int >main (int argc, char *argv[]) >{ > struct addrinfo *ai; > struct addrinfo hints; > memset (&hints, '\0', sizeof (hints)); > hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; > hints.ai_socktype = SOCK_STREAM; > int e = getaddrinfo (NULL, "4567", &hints, &ai); > if (e != 0) > error (EXIT_FAILURE, 0, "getaddrinfo: %s", gai_strerror (e)); > int nfds = 0; > struct addrinfo *runp = ai; > while (runp != NULL) > { > ++nfds; > runp = runp->ai_next; > } > struct pollfd fds[nfds]; > for (nfds = 0, runp = ai; runp != NULL; runp = runp->ai_next) > { > char addrbuf[46]; > printf("Trying %s\n", > inet_ntop(runp->ai_family, > runp->ai_family == AF_INET > ? (void *)&((struct sockaddr_in *)runp->ai_addr)->sin_addr > : (void *)&((struct sockaddr_in6 *)runp->ai_addr)->sin6_addr, > addrbuf, sizeof(addrbuf))); > fds[nfds].fd = socket (runp->ai_family, runp->ai_socktype, runp->ai_protocol); > if (fds[nfds].fd == -1) > error (EXIT_FAILURE, errno, "socket"); > fds[nfds].events = POLLIN; > int opt = 1; > setsockopt (fds[nfds].fd, SOL_SOCKET, SO_REUSEADDR, > &opt, sizeof (opt)); > > if (bind (fds[nfds].fd, > runp->ai_addr, runp->ai_addrlen) != 0) > { > if (errno != EADDRINUSE) > error (EXIT_FAILURE, errno, "bind"); > else > error (0, errno, "bind"); > close (fds[nfds].fd); > } > else > { > if (listen (fds[nfds].fd, SOMAXCONN) != 0) > error (EXIT_FAILURE, errno, "listen"); > ++nfds; > } > } > freeaddrinfo (ai); > while (1) > { > int n = poll (fds, nfds, -1); > if (n > 0) > for (int i = 0; i < nfds; ++i) > if (fds[i].revents & POLLIN) > { > struct sockaddr_storage rem; > socklen_t remlen = sizeof (rem); > int fd = accept (fds[i].fd, (struct sockaddr *) &rem, &remlen); > if (fd != -1) > { > char buf1[200]; > if (getnameinfo ((struct sockaddr *) &rem, remlen, > buf1, sizeof (buf1), NULL, 0, 0) != 0) > strcpy (buf1, "???"); > char buf2[100]; > (void) getnameinfo ((struct sockaddr *) &rem, remlen, > buf2, sizeof (buf2), NULL, 0, > NI_NUMERICHOST); > printf ("connection from %s (%s)\n", buf1, buf2); > char buf[1000]; > ssize_t l = read (fd, buf, sizeof (buf)); > write (fd, buf, l); > close (fd); > } > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 880698
:
652835
| 748281