evutil.c


Log

Author Commit Date CI Message
Nick Mathewson e49e2891 2012-02-10T17:29:53 Update copyright notices to 2012
Nick Mathewson 3c824bd3 2011-10-24T13:18:09 Update copyright dates to 2011.
Harlan Stenn 7c11e51e 2011-08-27T05:48:11 Clean up some problems identified by Coverity.
Nicholas Marriott 8ee9f9c1 2011-07-02T21:49:07 Fix a few warnings on OpenBSD - redeclaration of dst_size - arpa/inet.h requires netinet/in.h first - don't use a local with the same name as a global - it isn't needed so remove it
Nick Mathewson 1a21d7b8 2011-04-05T17:21:12 Fix the check for multicast or broadcast addresses in evutil_check_interfaces First of all, it is totally okay to have an address end with .255, depending on what your netmask is, so we shouldn't reject a local address if it ends with .255. Second, our check for ending with .255 was broken. So was our check for class-d addresses. Found by Dave Hart.
Nick Mathewson 637d17a1 2011-04-05T16:32:39 Check for allocation failures in apply_socktype_protocol_hack
Nick Mathewson 3c8f4e75 2011-01-31T16:44:06 Add compile-time check for AF_UNSPEC==PF_UNSPEC
Nick Mathewson cb921139 2011-01-31T16:32:05 Build on systems without AI_PASSIVE
Nick Mathewson 453317b2 2011-01-24T18:22:32 Fall back to sscanf if we have no other way to implement strtoll
Jardel Weyrich 666b0966 2010-12-18T01:07:27 Detect and handle more allocation failures.
Nick Mathewson 22f4af65 2010-12-09T11:43:12 Remove end-of-line whitespace
Kevin Bowling 32390732 2010-11-23T19:40:23 Fix snprintf related failures on IRIX.
Nick Mathewson 49418612 2010-11-16T12:55:10 Use the US-English "canceled", not the UK "cancelled".
Nick Mathewson a3245afe 2010-11-01T14:23:33 Fix win32 build in response to fixes from win64 build.
Nick Mathewson f8095d64 2010-11-01T14:15:34 Fix a typo in 7484df61c981fc33db2~
Nick Mathewson 7484df61 2010-11-01T13:43:43 Fix even more win64 warnings
Nick Mathewson 19c71e74 2010-10-27T10:36:08 Fix som event_warns that should have been event_warnx
Trond Norbye f5ad31c1 2010-10-27T12:47:07 Check return value for ioctlsocket on win32
Nick Mathewson a8b7674c 2010-09-28T01:09:17 Merge remote branch 'github/signed_compare'
Nick Mathewson d49b5e33 2010-09-27T15:12:55 Do not search outside of the system directory for windows DLLs Hardens against some attacks.
Nick Mathewson 9c8db0f8 2010-09-23T22:45:55 Fix all warnings in the main codebase flagged by -Wsigned-compare Remember, the code int is_less_than(int a, unsigned b) { return a < b; } is buggy, since the C integer promotion rules basically turn it into int is_less_than(int a, unsigned b) { return ((unsigned)a) < b; } and we really want something closer to int is_less_than(int a, unsigned b) { return a < 0 || ((unsigned)a) < b; } . Suggested by an example from Ralph Castain
Nick Mathewson 57d3413c 2010-09-08T11:39:24 Merge remote branch 'github/globals'
Nick Mathewson e50c0fcc 2010-09-02T11:10:50 Use the _func() replacements for open, fstat, etc in evutil.c on win32 Remember that in a fit of ANSI C compliance, Microsoft decided to screw portability by renaming basically all the functions in unistd.h to get prefixed with an understore. For some reason, mingw didn't seem to mind, but at least some people's compilers did: see bug 3044490.
Nick Mathewson 1fdec20f 2010-09-01T15:01:39 Stop using global arrays to implement the EVUTIL_ctype functions These apparently made libtool sad on win32, and the function call overhead here should be negligable anyway.
Nick Mathewson ec347b92 2010-07-07T16:45:03 Move event-config.h to include/event2 This change means that all required include files are in event2, and all files not in event2/* are optional.
Nick Mathewson 57b30cd7 2010-08-06T13:01:32 Turn our socketpair() replacement into its own function This patch splits the formerly windows-only case of evutil_socketpair() into an (internal-use-only) function named evutil_ersatz_socketpair(), and makes it build and work right on non-Windows hosts. We need this for convenience to test sendfile on solaris, where socketpair can't give you an AF_INET pair, and sendfile() won't work on AF_UNIX.
Nick Mathewson 7c2dea16 2010-07-13T11:06:08 Pass flags to fcntl(F_SETFL) and fcntl(F_SETFD) as int, not long Everybody but Linux documents this as taking an int, and Linux is very tolerant of getting an int instead. If it weren't, everybody doing fcntl(fd,F_SETFL,O_NONBLOCK) would break, since the glibc headers define O_NONBLOCK as an int literal.
Pierre Phaneuf 0798dd12 2010-05-27T22:37:09 Close the file in evutil_read_file whether there's an error or not. evutil_read_file would close the file if there was an error, but not if things went normally.
Nick Mathewson 47c5dfbe 2010-05-18T17:28:51 Remove some dead assignments
Nick Mathewson 8c3452bc 2010-05-18T13:55:32 Correctly recognize .255 addresses as link-local when looking for interfaces
Nick Mathewson c1cd32a1 2010-05-08T22:21:52 Define _REENTRANT as needed on Solaris, elsewhere It turns out that _REENTRANT isn't only needed to make certain functions visible; we also need it to make pthreads work properly some places (like Solaris, where forgetting _REENTRANT basically means that all threads are sharing the same errno). Fortunately, our ACX_PTHREAD() configure macro already gives us a PTHREAD_CFLAG variable, so all we have to do is use it.
Nick Mathewson 935e1504 2010-05-08T19:36:05 Fix whitespace in evutil.c
Nick Mathewson 35570716 2010-05-08T19:16:47 Fix another nasty solaris getaddrinfo() behavior Everybody else thinks that when you getaddrinfo() on an ip address and don't specify the protocol and the socktype, it should give you multiple answers , one for each protocol/socktype implementation. OpenSolaris takes a funny view of RFC3493, and leaves the results set to 0. This patch post-processes the getaddrinfo() results for consistency.
Nick Mathewson 2cf2a286 2010-04-21T11:57:55 Fix getaddrinfo with protocol unset on Solaris 9. Found by Dagobert Michelsen Apparently when you call Solaris 9's getaddrinfo(), it likes to leave ai_protocol unset in the result. This is no way to behave, if I'm reading RFC3493 right. This patch makes us check for a getaddrinfo() that's broken in this way, and work around it by trying to infer socktype and protocol from one another. Partial bugfix for 2987542
Nick Mathewson 20fda296 2010-05-03T13:00:00 Try /proc on Linux as entropy fallback; use sysctl as last resort It turns out that the happy fun Linux kernel is deprecating sysctl, and using sysctl to fetch entropy will spew messages in the kernel logs. Let's not do that. Instead, let's call sysctl for our entropy only when all other means fail. Additionally, let's add another means, and try /proc/sys/kernel/random/uuid if /dev/urandom fails.
Nick Mathewson b1c79500 2010-04-23T14:42:25 Make evdns logging threadsafe The old logging code was littered with places where we stored messages in static char[] fields. This is fine in a single-threaded program, but if you ever tried to log evdns messages from two threads at once, you'd hit a race. This patch also refactors evdns's debug_ntop function into a more useful evutil_sockaddr_port_format() function, with unit tests.
Sebastian Sjöberg 899c1dcc 2010-04-14T15:42:57 Replace EVUTIL_CLOSESOCKET macro with a function The EVUTIL_CLOSESOCKET() macro required you to include unistd.h in your source for POSIX. We might as well turn it into a function: an extra function call is going to be cheap in comparison with the system call. We retain the EVUTIL_CLOSESOCKET() macro as an alias for the new evutil_closesocket() function. (commit message from email by Nick and Sebastian)
Christopher Davis 8f9e60c8 2010-04-09T19:16:09 Always round up when there's a fractional number of msecs.
Christopher Davis 850c3ff2 2010-03-31T20:30:55 Add evutil_tv_to_msec for safe conversion of timevals to milliseconds. This is useful for backends that require their timeout values be in milliseconds.
Nick Mathewson cdd4c490 2010-03-11T00:38:46 Try to comment some of the event code more
Brodie Thiesfield b677032b 2010-03-08T13:46:04 Avoid errors in evutil.c when building with _UNICODE defined
Nick Mathewson 17efc1cd 2010-03-04T01:25:51 Update all our copyright notices to say "2010"
Nick Mathewson 57b72488 2010-02-27T22:27:13 Small cleanups on freebsd-connect-refused patch. There should be no need to call be_socket_enable: that does an event_add(). What we really want to do is event_active(), to make sure that the writecb is executed. Also, there was one "} if () {" that was missing an else. I've noted that the return value for evutil_socket_connect() is getting screwy, but since that isn't an exported function, we can fix it whenever.
Niels Provos 7bc48bfd 2010-02-27T18:59:06 deal with connect() failing immediately
Nick Mathewson 4faeaea9 2010-02-19T03:39:50 Clean up formatting: function/keyword spacing consistency. - Keywords always have a space before a paren. Functions never do. - No more than 3 blank lines in a row.
Nick Mathewson e5bbd40a 2010-02-18T17:41:15 Clean up formatting: use tabs, not 8-spaces, to indent.
Nick Mathewson d4de062e 2010-02-10T17:19:18 Add an arc4random implementation for use by evdns Previously, evdns was at the mercy of the user for providing a good entropy source; without one, it would be vulnerable to various active attacks. This patch adds a port of OpenBSD's arc4random() calls to Libevent [port by Chris Davis], and wraps it up a little bit so we can use it more safely.
Nick Mathewson 6810bdb1 2010-02-05T13:50:51 Always use our own gai_strerror() replacement. This is necessary if we have any errors that the platform gai_strerror() doesn't know how to handle.
Nick Mathewson c18490e6 2010-02-05T01:09:01 Add a check to make soure our EVUTIL_AI flags do not conflict with the native ones
Nick Mathewson 5c7a7bca 2010-01-23T20:07:05 Fix windows and msvc build
Nick Mathewson 918e9c5e 2010-01-23T16:38:36 Fix a number of warnings from gcc -pedantic
Nick Mathewson 26e1b6f2 2010-01-21T01:51:40 Remove some commented-out code in evutil
Nick Mathewson 8d4aaf90 2010-01-20T12:56:54 Don't use a bind address for nameservers on loopback If the user sets a bind address to use for nameservers, and a nameserver happens to be on 127.0.0.1, the nameserver will generally fail. This patch alters this behavior so that the bind address is only applied when the nameserver is on a non-loopback address.
Nick Mathewson 0f7144fd 2009-12-07T17:21:13 Refactor code from evdns into a new internal "read a file" function.
Nick Mathewson ba2945f9 2010-01-06T17:59:44 Merge branch 'ratelimit' Conflicts: bufferevent_async.c
Nick Mathewson 165d30e3 2009-12-30T14:29:56 Fix compilation of rate-limiting code on win32.
Jardel Weyrich d0939d2b 2009-12-29T16:21:26 Introduced evutil_make_socket_closeonexec() to preserve fd flags for F_SETFD. Use this to eliminate the various macros that called F_SETFD throughout the code.
Jardel Weyrich 4df7dbcb 2009-12-29T16:19:24 Adjusted fcntl() retval comparison on evutil_make_socket_nonblocking(). Apparently, a successful return value on F_SETFL is "anything but -1".
Jardel Weyrich 5a43df82 2009-12-28T16:03:47 Improve readability of evutil_unparse_protoname()
Jardel Weyrich 0d64051f 2009-12-28T16:01:59 Fix a bogus free in evutil_new_addrinfo()
Jardel Weyrich 4c8b7cdc 2009-12-28T16:00:05 Make evutil_make_socket_nonblocking() leave any other flags alone. Fixes bug 2922121
Nick Mathewson f070a4ae 2009-11-18T23:18:55 Do the proper hack for the (Open)BSD getaddrinfo quirk. From evutil.c: Some older BSDs (like OpenBSD up to 4.6) used to believe that giving a numeric port without giving an ai_socktype was verboten. We test for this so we can apply an appropriate workaround. If it turns out that the bug is present, then: - If nodename==NULL and servname is numeric, we build an answer ourselves using evutil_getaddrinfo_common(). - If nodename!=NULL and servname is numeric, then we set servname=NULL when calling getaddrinfo, and post-process the result to set the ports on it. We test for this bug at runtime, since otherwise we can't have the same binary run on multiple BSD versions. svn:r1550
Nick Mathewson 201d8d0b 2009-11-17T18:29:44 Clarify even more about various system-specific problems with getaddrinfo svn:r1542
Nick Mathewson 9151d000 2009-11-17T03:36:43 Use the common-case code from getaddrinfo_common *always*; OS differences are just too huge. svn:r1541
Nick Mathewson 3451c870 2009-11-17T02:57:32 Never pass our weird flags to the system getaddrinfo. Make sure there is no overlap between flag values. svn:r1540
Nick Mathewson 888007f9 2009-11-17T02:38:19 Windows *does* have getservbyname, no matter what autoconf says. TODO: figure out why autoconf is confused about this. svn:r1538
Nick Mathewson 86f57420 2009-11-16T22:25:46 Add two implementations of getaddrinfo: one blocking and one nonblocking. The entry points are evutil_getaddrinfo and evdns_getaddrinfo respectively. There are fairly extensive unit tests. I believe this code conforms to RFC3493 pretty closely, but there are probably more issues. It should get tested on more platforms. This code means we can dump the well-intentioned but weirdly-implemented bufferevent_evdns and evutil_resolve code. svn:r1537
Nick Mathewson 629a6133 2009-11-15T18:59:59 When running set[ug]id, don't check the environment. Idea from OpenBSD, but made a bit more generic to handle uncivilized lands that do not define issetugid. svn:r1530
Nick Mathewson 784b8773 2009-11-06T21:46:57 We do not work any more without an event-config.h; stop pretending that it is meaningful to check for HAVE_CONFIG_H svn:r1516
Nick Mathewson 0b9eb1bf 2009-11-03T20:40:48 Add a bufferevent function to resolve a name then connect to it. This function, bufferevent_socket_connect_hostname() can either use evdns to do the resolve, or use a new function (evutil_resolve) that uses getaddrinfo or gethostbyname, like http.c does now. This function is meant to eventually replace the hostname resolution mess in http.c. svn:r1496
Nick Mathewson 25af6954 2009-10-14T00:46:47 When a bufferevent_connect() call fails, give the client an error callback. Patch from Christopher Davis. svn:r1444
Nick Mathewson 621aafd2 2009-07-30T22:11:23 Export sockaddr comparison functionality. svn:r1400
Nick Mathewson 7c20a6ae 2009-07-30T17:01:21 Export an ev_socklen_t. svn:r1391
Nick Mathewson 72ea534f 2009-07-28T19:41:57 Export evutil_str[n]casecmp as evutil_ascii_str[n]casecmp. svn:r1387
Nick Mathewson 709c21c4 2009-07-28T04:03:57 Bufferevent support for openssl. This code adds a new Bufferevent type that is only compiled when the openssl library is present. It supports using an SSL object and an event alert mechanism, which can either be an fd or an underlying bufferevent. There is still more work to do: the unit tests are incomplete, and we need to support flush and shutdown much better. Sometimes events are generated needlessly: this will hose performance. There's a new encrypting proxy in sample/le-proxy.c. This code has only been tested on OSX, and nowhere else. svn:r1382
Nick Mathewson 043515bc 2009-07-14T18:50:06 Stop using C++ style comments. svn:r1343
Nick Mathewson 01be8708 2009-06-11T19:09:08 Fix compile on cygwin. This isnt the solution I would like: I would prefer to get pton and ntop to work even when AF_INET6 is not defined. svn:r1326
Nick Mathewson f11dff2c 2009-05-07T03:45:51 Add and use locale-independent strcasecmp functions. svn:r1280
Nick Mathewson ebf29455 2009-04-30T23:49:15 Compilation fixes for vc++ 2008 express. Not the end of them. svn:r1260
Nick Mathewson 50e20fe0 2009-04-29T20:48:35 fix a typo in a comment svn:r1251
Nick Mathewson a835c7cf 2009-04-18T18:27:56 fix a misindent svn:r1200
Nick Mathewson acaf65c3 2009-02-11T17:23:32 Make evutil_parse_sockaddr_port give a useful socket-length output. svn:r1118
Nick Mathewson cd731b77 2009-02-10T21:40:12 Do not use ctypes functions in cases when we need the "net" locale. This patch adds a new set of EVUTIL_IS* functions to replace use of the ctypes is* functions in all cases where we care about characters' interpretations in net ascii rather than in the locale. For example, when we're working with DNS hostnames, we don't want to do the 0x20 hack on non-ascii characters, even if the host thinks they should be isalpha. svn:r1114
Nick Mathewson da49d6a3 2009-02-10T19:43:11 Stop using platform inet_aton/inet_addr; they can behave strangely on certain misformed addresses. svn:r1111
Nick Mathewson c7b2f8fd 2009-02-10T19:38:05 New function to abstract SO_REUSEADDR. svn:r1102
Nick Mathewson 722885fb 2009-02-02T21:59:53 Some mingws have AF_UNIX, which may have prevented our socketpair from working at all on them. Fix that. svn:r1098
Nick Mathewson f13bede7 2009-01-28T20:31:19 Fix an unlikely degenerate case of evutil_vsnprintf svn:r1067
Nick Mathewson b85b710c 2009-01-27T22:34:36 Update copyright statements to reflect the facts that: a) this is 2009 b) niels and nick have been comaintainers for a while c) saying "all rights reserved" when you then go on to explicitly disclaim some rights is sheer cargo-cultism. svn:r1065
Nick Mathewson 8889a770 2009-01-27T22:30:46 Replace all use of config.h with event-config.h. svn:r1064
Nick Mathewson 9993137c 2009-01-27T21:10:31 Remove all trailing whitespace in all the source files. svn:r1063
Niels Provos 70405e3c 2009-01-21T07:18:31 fix freebsd compile; from Alexander Drozdov svn:r1030
Nick Mathewson 9935d5b0 2009-01-13T21:39:32 Fix win32 compilation. Surprisingly, unit tests pass too. svn:r1002
Nick Mathewson 169321c9 2009-01-13T20:26:37 Rename four internal headers to follow the -internal.h convention. svn:r1000
Nick Mathewson 980bcd68 2009-01-02T21:21:58 Work better with platforms that do not have ipv6 structures, or that do not have sin_len fields, etc. svn:r986
Nick Mathewson cfbd1680 2009-01-02T20:46:26 Add another function to parse the common address:port combination formats into a sockaddr. svn:r984
Nick Mathewson 0d9d5cfe 2009-01-02T20:46:12 New functions in evutil to clone inet_pton and inet_ntop, with tests. Adapted from Tor code. svn:r983
Nick Mathewson fded0a87 2008-09-05T16:47:04 Fix compilation of recent error code with win32. svn:r937
Nick Mathewson de069b99 2008-09-05T16:29:56 On win32, errno is not the last socket error. Worse, WSAGetLastError() is not the last socket error sometimes (i.e., EWOULDBLOCK). Also, strerror() does not handle winsock errors. Therefore, event_err() and event_warn() are completely wrong for windows socket errors. Fix that. svn:r936
Niels Provos 55f91494 2008-06-24T16:29:02 fix evutil_snprintf on windows svn:r860
Nick Mathewson 0cafdeb6 2008-05-12T17:16:47 Tweaks to make unit tests fail less badly on mingw on trunk. svn:r814