Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
5c9eb217
Kaydet (Commit)
5c9eb217
authored
Agu 20, 1999
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch by Ben Gertzfield to add inet_aton() and inet_ntoa() calls.
üst
abf8a1da
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
socketmodule.c
Modules/socketmodule.c
+72
-0
No files found.
Modules/socketmodule.c
Dosyayı görüntüle @
5c9eb217
...
...
@@ -54,6 +54,8 @@ Module interface:
- socket.htons(16 bit value) --> new int object
- socket.htonl(32 bit value) --> new int object
- socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h>
- socket.inet_aton(IP address) -> 32-bit packed IP representation
- socket.inet_ntoa(packed IP) -> IP address string
- an Internet socket address is a pair (hostname, port)
where hostname can be anything recognized by gethostbyname()
(including the dd.dd.dd.dd notation) and port is in host byte order
...
...
@@ -151,6 +153,10 @@ int shutdown( int, int );
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
/* added 20 Aug 1999 to remove warnings from inet_ntoa call <che@debian.org> */
#include <arpa/inet.h>
#include <fcntl.h>
#else
#include <winsock.h>
...
...
@@ -1785,6 +1791,68 @@ static char htonl_doc[] =
\n
\
Convert a 32-bit integer from host to network byte order."
;
/*
* socket.inet_aton() and socket.inet_ntoa() functions
*
* written 20 Aug 1999 by Ben Gertzfield <che@debian.org> <- blame him!
*
*/
static
char
inet_aton_doc
[]
=
"inet_aton(string) -> packed 32-bit IP representation
\n
\
\n
\
Convert an IP address in string format (123.45.67.89) to the 32-bit packed
binary format used in low-level network functions."
;
static
PyObject
*
BUILD_FUNC_DEF_2
(
PySocket_inet_aton
,
PyObject
*
,
self
,
PyObject
*
,
args
)
{
char
*
ip_addr
;
struct
in_addr
packed_addr
;
int
err
;
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
ip_addr
))
{
return
NULL
;
}
err
=
inet_aton
(
ip_addr
,
&
packed_addr
);
if
(
err
==
0
)
{
/* invalid address */
PyErr_SetString
(
PySocket_Error
,
"illegal IP address string passed to inet_aton"
);
return
NULL
;
}
return
PyString_FromStringAndSize
((
char
*
)
&
packed_addr
,
sizeof
(
packed_addr
));
}
static
char
inet_ntoa_doc
[]
=
"inet_aton(packed_ip) -> ip_address_string
\n
\
\n
\
Convert an IP address from 32-bit packed binary format to string format"
;
static
PyObject
*
BUILD_FUNC_DEF_2
(
PySocket_inet_ntoa
,
PyObject
*
,
self
,
PyObject
*
,
args
)
{
char
*
packed_str
;
int
err
,
addr_len
;
struct
in_addr
packed_addr
;
if
(
!
PyArg_Parse
(
args
,
"s#"
,
&
packed_str
,
&
addr_len
))
{
return
NULL
;
}
if
(
addr_len
!=
sizeof
(
packed_addr
))
{
PyErr_SetString
(
PySocket_Error
,
"packed IP wrong length for inet_ntoa"
);
return
NULL
;
}
memcpy
(
&
packed_addr
,
packed_str
,
addr_len
);
return
PyString_FromString
(
inet_ntoa
(
packed_addr
));
}
/* List of functions exported by this module. */
...
...
@@ -1803,6 +1871,8 @@ static PyMethodDef PySocket_methods[] = {
{
"ntohl"
,
PySocket_ntohl
,
0
,
ntohl_doc
},
{
"htons"
,
PySocket_htons
,
0
,
htons_doc
},
{
"htonl"
,
PySocket_htonl
,
0
,
htonl_doc
},
{
"inet_aton"
,
PySocket_inet_aton
,
0
,
inet_aton_doc
},
{
"inet_ntoa"
,
PySocket_inet_ntoa
,
0
,
inet_ntoa_doc
},
{
NULL
,
NULL
}
/* Sentinel */
};
...
...
@@ -1927,6 +1997,8 @@ getservbyname() -- map a service name and a protocol name to a port number\n\
getprotobyname() -- mape a protocol name (e.g. 'tcp') to a number
\n
\
ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order
\n
\
htons(), htonl() -- convert 16, 32 bit int from host to network byte order
\n
\
inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format
\n
\
inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
\n
\
\n
\
(*) not available on all platforms!)
\n
\
\n
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment