diff -r a13310c045b0 Modules/socketmodule.c --- a/Modules/socketmodule.c Mon May 02 13:36:18 2011 +0200 +++ b/Modules/socketmodule.c Tue May 03 11:07:15 2011 +0300 @@ -2821,18 +2821,23 @@ sock_sendto(PySocketSockObject *s, PyObject *args) { Py_buffer pbuf; - PyObject *addro; + PyObject *addro, *tmp = Py_None; char *buf; Py_ssize_t len; sock_addr_t addrbuf; int addrlen, n = -1, flags, timeout; flags = 0; - if (!PyArg_ParseTuple(args, "s*O:sendto", &pbuf, &addro)) { - PyErr_Clear(); - if (!PyArg_ParseTuple(args, "s*iO:sendto", - &pbuf, &flags, &addro)) + /* sendto accepts an optional second arg 'flags' */ + if (!PyArg_ParseTuple(args, "s*O|O:sendto", &pbuf, &addro, &tmp)) + return NULL; + /* if tmp is set, 3 arguments have been passed, so convert the second + (flags) to int, and copy the third one to addro */ + if (tmp != Py_None) { + flags = PyInt_AsLong(addro); + if (PyErr_Occurred()) return NULL; + addro = tmp; } buf = pbuf.buf; len = pbuf.len;