diff options
author | Guido van Rossum <guido@python.org> | 1992-11-26 08:54:07 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-11-26 08:54:07 (GMT) |
commit | c89705d6975ffb1e4a3764f4f36bab339f969e8f (patch) | |
tree | b4e565a58d410ad3a60ffbe11f94c2567b14365d /Modules/socketmodule.c | |
parent | df9320f8bcad10431fa103459fcebd4b5430599a (diff) | |
download | cpython-c89705d6975ffb1e4a3764f4f36bab339f969e8f.zip cpython-c89705d6975ffb1e4a3764f4f36bab339f969e8f.tar.gz cpython-c89705d6975ffb1e4a3764f4f36bab339f969e8f.tar.bz2 |
* config.c: Added audioop to lists.
* Makefile: change default source directory
* socketmodule.c: added getsockname and getpeername
* bltinmodule.c: corrected typo in type() error message
* Added new built-in functions str() and repr(): repr(x) == `x`;
str(x) == x if x is a string, otherwise str(x) == repr(x).
* Added joinfields to stropmodule.c (string.join calls joinfields now)
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r-- | Modules/socketmodule.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index b1ab96d..bb451eb 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -57,6 +57,8 @@ Socket methods: - s.getsockopt(level, optname) --> flag - s.bind(sockaddr) --> None - s.connect(sockaddr) --> None +- s.getsockname() --> sockaddr +- s.getpeername() --> sockaddr - s.listen(n) --> None - s.makefile(mode) --> file object - s.recv(nbytes) --> string @@ -564,6 +566,50 @@ sock_fileno(s, args) } +/* s.getsockname() method */ + +static object * +sock_getsockname(s, args) + sockobject *s; + object *args; +{ + char addrbuf[256]; + int addrlen, res; + if (!getnoarg(args)) + return NULL; + if (!getsockaddrlen(s, &addrlen)) + return NULL; + BGN_SAVE + res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); + END_SAVE + if (res < 0) + return socket_error(); + return makesockaddr((struct sockaddr *) addrbuf, addrlen); +} + + +/* s.getpeername() method */ + +static object * +sock_getpeername(s, args) + sockobject *s; + object *args; +{ + char addrbuf[256]; + int addrlen, res; + if (!getnoarg(args)) + return NULL; + if (!getsockaddrlen(s, &addrlen)) + return NULL; + BGN_SAVE + res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); + END_SAVE + if (res < 0) + return socket_error(); + return makesockaddr((struct sockaddr *) addrbuf, addrlen); +} + + /* s.listen(n) method */ static object * @@ -753,6 +799,8 @@ static struct methodlist sock_methods[] = { {"close", sock_close}, {"connect", sock_connect}, {"fileno", sock_fileno}, + {"getsockname", sock_getsockname}, + {"getpeername", sock_getpeername}, {"listen", sock_listen}, {"makefile", sock_makefile}, {"recv", sock_recv}, |