Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F13142023
sockets.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
sockets.c
View Options
/*
* Copyright (C) 1996 Darkbot Project.
* This program is free software, you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2. This
* program is distributed in the hope that it will be useful, but without
* any warranty, without even the implied warranty of merchantability or
* fitness for a particular purpose. See the COPYING file for details.
*/
#include
"defines.h"
#include
"vars.h"
#include
"prototypes.h"
/**
* Write a character array to a socket connection.
* 6/22/00 Dan
* Method argument now pointer to const data.
*/
int
writeln
(
const
char
*
b
)
{
return
(
write
(
socketfd
,
b
,
strlen
(
b
))
<
0
)
?
0
:
1
;
}
int
readln
(
void
)
{
char
ch
=
0
;
int
i
=
0
;
do
{
if
(
read
(
socketfd
,
&
ch
,
1
)
<
1
)
return
0
;
if
(
ch
>=
32
||
ch
<=
126
)
if
(
i
<
524
-
1
)
L
[
i
++
]
=
ch
;
}
while
(
ch
!=
'\n'
);
L
[
i
]
=
'\0'
;
return
1
;
}
/**
* 6/23/00 Dan
* - Changed method argument to be pointer to const data
* - Initialized variables when declared
* - Changed b to a power of 2
*/
void
S
(
const
char
*
format
,
...)
{
va_list
arglist
;
char
b
[
STRING_LONG
]
=
{
0
};
struct
sendq
*
n
=
0
;
va_start
(
arglist
,
format
);
vsprintf
(
b
,
format
,
arglist
);
va_end
(
arglist
);
if
(
send_tog
==
0
)
{
send_tog
=
1
;
if
(
DebuG
==
1
)
{
printf
(
"OUT: %s"
,
b
);
}
writeln
(
b
);
return
;
}
n
=
malloc
(
sizeof
(
struct
sendq
));
if
(
n
==
NULL
)
{
db_log
(
"error.log"
,
"AHH! no ram left! in S!
\n
"
);
return
;
}
memset
(
n
,
0
,
sizeof
(
struct
sendq
));
strncpy
(
n
->
data
,
b
,
sizeof
(
n
->
data
));
if
(
sendqhead
==
NULL
)
{
sendqhead
=
sendqtail
=
n
;
}
else
{
sendqtail
->
next
=
n
;
sendqtail
=
sendqtail
->
next
;
}
}
/**
* 6/23/00 Dan
* - Changed method argument to be pointer to const data
* - Initialized b
*/
int
Snow
(
const
char
*
format
,
...)
{
va_list
arglist
;
char
b
[
STRING_LONG
]
=
{
0
};
va_start
(
arglist
,
format
);
vsprintf
(
b
,
format
,
arglist
);
va_end
(
arglist
);
if
(
DebuG
==
1
)
printf
(
"OUT: %s"
,
b
);
return
(
writeln
(
b
));
}
int
Send
()
{
struct
sendq
*
c
;
char
output
[
STRING_LONG
];
c
=
sendqhead
;
get_sendq_count
(
0
);
if
(
c
==
NULL
)
{
send_tog
=
0
;
return
-1
;
}
if
(
DebuG
==
1
)
printf
(
"OUT: %s"
,
c
->
data
);
#ifdef DEBUG2
db_log
(
"darkbot_debug.log"
,
"OUT: %s"
,
c
->
data
);
#endif
strncpy
(
output
,
c
->
data
,
sizeof
(
output
));
del_sendq
(
0
);
return
(
writeln
(
output
));
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Fri, Nov 21, 16:08 (5 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3188539
Default Alt Text
sockets.c (2 KB)
Attached To
Mode
rDARKBOT Darkbot
Attached
Detach File
Event Timeline
Log In to Comment