summaryrefslogtreecommitdiff
path: root/other/telnetfp-0.1.2/base_net.cpp
diff options
context:
space:
mode:
authorSkyperTHC2026-03-03 06:28:55 +0000
committerSkyperTHC2026-03-03 06:28:55 +0000
commit5d3573ef7a109ee70416fe94db098fe6a769a798 (patch)
treedc2d5b294c9db8ab2db7433511f94e1c4bb8b698 /other/telnetfp-0.1.2/base_net.cpp
parentc6c59dc73cc4586357f93ab38ecf459e98675cc5 (diff)
packetstorm sync
Diffstat (limited to 'other/telnetfp-0.1.2/base_net.cpp')
-rw-r--r--other/telnetfp-0.1.2/base_net.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/other/telnetfp-0.1.2/base_net.cpp b/other/telnetfp-0.1.2/base_net.cpp
new file mode 100644
index 0000000..0635985
--- /dev/null
+++ b/other/telnetfp-0.1.2/base_net.cpp
@@ -0,0 +1,65 @@
1class tcp_socket
2{
3 private:
4 int sock;
5
6 public:
7
8 int sopen (char *host, int port)
9 {
10 int x = -1;
11 struct hostent *foo = NULL;
12 struct sockaddr_in addr;
13
14 memset ((struct sockaddr_in *) &addr, 0, sizeof (struct sockaddr_in));
15
16 if ((addr.sin_addr.s_addr = inet_addr (host)) == -1)
17 {
18 if ((foo = gethostbyname (host)) == NULL)
19 return -2;
20 addr.sin_addr.s_addr = *(unsigned long *) (foo->h_addr_list[0]);
21 }
22 addr.sin_family = PF_INET;
23 addr.sin_port = htons (port);
24 sock = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
25
26 x = connect (sock, (struct sockaddr *) &addr, sizeof (struct sockaddr_in));
27 if (x != 0 || sock < 0)
28 return -1;
29
30 return 0;
31 }
32
33
34 char *sread (int x)
35 {
36 char *y = NULL;
37 y = (char *) malloc (x + 1);
38 memset (y, 0x00, x + 1);
39 if (read (sock, y, x) < 1)
40 {
41 free (y);
42 return NULL;
43 }
44 return y;
45 }
46
47
48 int swrite (char *x)
49 {
50 return write (sock, x, strlen (x));
51 }
52
53
54 void sclose ()
55 {
56 close (sock);
57 }
58
59
60 void
61 init ()
62 {
63 sock = 0;
64 }
65};