xtreme client v.543
Nikos Mavroyanopoulos
nmav at hellug.gr
Mon Jan 17 02:48:51 EET 2000
/* x-treme client for Linux
* Ενα quick hack του παλιού xtreme client, για να δουλευει με τα
* sources που μου έστειλε ο m0bius (mobius at groovy.gr)
* Την string() την έφτιαξε ο phoenix (phoenix at iname.com)
*
* Φαινεται πως προχωρήσαν πιο γρήγορα απο εμένα...
* δεν είναι και ο καλύτερος C κώδικας, αλλά who really cares:)
*/
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#define LISTENQ 1024
#define SA struct sockaddr
#define SERV_PORT 6699
/* #define NO_STDOUT */
/* #define NO_STDERR */
int string(char *username, char* tr);
int main(int koko, char** kaka)
{
char c;
int listenfd, connfd, clifd, i, strln;
socklen_t len;
unsigned char buff;
struct sockaddr_in cliaddr, servaddr, xtreme_addr;
char topbuff[512];
char *xstr;
char *USERNAME;
if (koko!=2) {
fprintf(stderr, "Usage: ./a.out username\n");
exit(1);
}
USERNAME=kaka[1];
xstr=malloc(strlen(USERNAME)*2+54);
if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket");
return -1;
}
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT);
if (bind(listenfd, (SA *) & servaddr, sizeof(servaddr)) < 0) {
fprintf(stderr,
"Probably a TIME_WAIT state. Retry later.\n");
perror("bind");
return -1;
}
if (listen(listenfd, LISTENQ) < 0) {
perror("listen");
return -1;
}
len = sizeof(cliaddr);
for (;;) {
if ((connfd = accept(listenfd, (SA *) & cliaddr, &len)) <
0) {
perror("accept");
return -1;
}
#ifndef NO_STDERR
fprintf(stderr, "connection from %s, port %d\n",
inet_ntop(AF_INET, &cliaddr.sin_addr, topbuff,
sizeof(topbuff)),
ntohs(cliaddr.sin_port));
#endif
strln = string(USERNAME, xstr);
#ifndef NO_STDERR
fprintf(stderr, "String(%d) was sent.\n", strln);
#endif
write(connfd, xstr, strln);
close(connfd);
#ifndef NO_STDERR
fprintf(stderr, "connection terminated\n");
fflush(stderr);
#endif
}
free(xstr);
}
int string(char *name, char* tr)
{
char replies[3][54] = {
"\x00\x00\x00\x00\x00\x71\x00\x38\x00\x3f\x00\x3a\x00\x33"
"\x00\x3d\x00\x48\x00\x23\x00\x4e\x00\x4a\x00\x48\x00\x3b"
"\x00\x43\x00\x3b\x00\x23\x62\x26\x00\x26\x00\x26\x00\x2b"
"\x00\x23\x00\x47\x00\x31\x00\x4b\x00\x44\x00\x33", //AUTH
"\x41\x43\x4b", // ACK
"\x41\x43\x4b"
}; // ACK
int repliesn[3] = { 54, 3, 3 };
int moufa;
int usrlen;
if (strlen(name) > 666) {
exit(-1);
}
usrlen = strlen(name);
srand((unsigned int) time(NULL));
for (moufa = 0; moufa < (repliesn[0]); moufa++) {
if ((tr[moufa] = replies[0][moufa]) == 0x00) {
tr[moufa] =
(char) (1 +
(254.0 * rand() / (RAND_MAX + 1.0)));
}
}
for (;moufa < repliesn[0]+(usrlen*2);moufa++) {
tr[moufa] = (char) (1 +
(254.0 * rand() / (RAND_MAX + 1.0)));
}
for (moufa=1; moufa < (usrlen * 2) ; moufa += 2) {
tr[moufa+ repliesn[0]] = name[moufa / 2] - 10;
}
if (usrlen > 4) {
tr[3] = 0x33;
tr[4] = 0x2a + usrlen;
} else {
tr[3] = 0x32;
tr[4] = 0x34 + usrlen;
}
return (repliesn[0]+(usrlen*2));
}
--
Nikos Mavroyanopoulos
mailto:nmav at hellug.gr
Always remember you're unique - just like everyone else.
--
====================================================================
Gia boithia (h na diagrafhte) e-mail sto majordomo at hellug.gr
Ta archives tis listas einai sto http://lists.hellug.gr/lgu.html
prin steilete kapoia erothsh psakte mipos exei hdh apanththei.
Gia opoiodipote problima stilte e-mail ston owner-linux-greek-users at hellug.gr
====================================================================
More information about the Linux-greek-users
mailing list