Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 900:58a7438c2e7e legacy-trunk
Some UNIX types want the exact size of the address structure
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 12 Jun 1992 10:39:36 +0000 |
| parents | 6459e2f21bf6 |
| children | a4793ae26682 |
line wrap: on
line diff
--- a/Modules/socketmodule.c Fri Jun 12 10:39:22 1992 +0000 +++ b/Modules/socketmodule.c Fri Jun 12 10:39:36 1992 +0000 @@ -317,6 +317,39 @@ } +/* Get the address length according to the socket object's address family. + Return 1 if the family is known, 0 otherwise. The length is returned + through len_ret. */ + +static int +getsockaddrlen(s, len_ret) + sockobject *s; + int *len_ret; +{ + switch (s->sock_family) { + + case AF_UNIX: + { + *len_ret = sizeof (struct sockaddr_un); + return 1; + } + + case AF_INET: + { + *len_ret = sizeof (struct sockaddr_in); + return 1; + } + + /* More cases here... */ + + default: + err_setstr(SocketError, "getsockaddrarg: bad family"); + return 0; + + } +} + + /* s.accept() method */ static object * @@ -329,7 +362,8 @@ object *res; if (!getnoarg(args)) return NULL; - addrlen = sizeof addrbuf; + if (!getsockaddrlen(s, &addrlen)) + return NULL; newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); if (newfd < 0) return socket_error();
