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
e0c69013
Kaydet (Commit)
e0c69013
authored
Tem 19, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added leading comment and security check.
üst
42ded89c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
5 deletions
+28
-5
pysvr.c
Demo/pysvr/pysvr.c
+28
-5
No files found.
Demo/pysvr/pysvr.c
Dosyayı görüntüle @
e0c69013
/* A multi-threaded telnet-like server that gives a Python prompt.
Usage: pysvr [port]
For security reasons, it only accepts requests from the current host.
This can still be insecure, but restricts violations from people who
can log in on your machine. Use with caution!
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -88,8 +98,8 @@ usage()
static
void
main_thread
(
int
port
)
{
int
sock
;
struct
sockaddr_in
addr
;
int
sock
,
conn
,
size
;
struct
sockaddr_in
addr
,
clientaddr
;
sock
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
);
if
(
sock
<
0
)
{
...
...
@@ -117,9 +127,7 @@ main_thread(int port)
fprintf
(
stderr
,
"Listening on port %d...
\n
"
,
port
);
for
(;;)
{
struct
sockaddr_in
clientaddr
;
int
conn
,
size
;
size
=
sizeof
clientaddr
;
conn
=
accept
(
sock
,
(
struct
sockaddr
*
)
&
clientaddr
,
&
size
);
if
(
conn
<
0
)
{
oprogname
();
...
...
@@ -127,6 +135,21 @@ main_thread(int port)
exit
(
1
);
}
size
=
sizeof
addr
;
if
(
getsockname
(
conn
,
(
struct
sockaddr
*
)
&
addr
,
&
size
)
<
0
)
{
oprogname
();
perror
(
"can't get socket name of connection"
);
exit
(
1
);
}
if
(
clientaddr
.
sin_addr
.
s_addr
!=
addr
.
sin_addr
.
s_addr
)
{
oprogname
();
perror
(
"connection from non-local host refused"
);
fprintf
(
stderr
,
"(addr=%lx, clientaddr=%lx)
\n
"
,
ntohl
(
addr
.
sin_addr
.
s_addr
),
ntohl
(
clientaddr
.
sin_addr
.
s_addr
));
close
(
conn
);
continue
;
}
create_thread
(
conn
,
&
clientaddr
);
}
}
...
...
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