-
I think timestamp is the time the user logs on.
in the server code, here's how timestamp() is defined. its actually a structure.
Code:
char * timestamp()
{
char *ctime();
static char buf[32];
time_t t, time();
t= time( (time_t *)(0));
strcpy(buf,ctime(&t));
buf[24]= '\0'; /* get rid of newline */
return(buf);
}
whoami is is basically the address coming in. we initialize it by doing this:
Code:
/* Process one connection */
len = sizeof(cliaddr);
if( (connfd = accept(listenfd, (SA *) &cliaddr, &len)) < 0)
{
if(errno == EINTR) continue;
exit(-1);
}
// WHOAMI INITIALIZED BELOW
strcpy(whoami, inet_ntop(AF_INET,&cliaddr.sin_addr,buff,sizeof(buff)));
and line is what is equal to the stuff coming in, like the interface, password, version, etc.
so it writes all of that to stplog.
the thing is, the server is being run on UNIX, so i dont know howd id do that, unless Id have to go back and make a copy of the server.c program, convert that to make it run on windows and then see what happens. I dont know how else i could get access to stplog.
-
It looks like fgets doesn't work in this situation. I'm looking at it.
-
I just noticed that on the putline function, it gets written, but when it does fflush, its returning -1.
here's the function:
Code:
void ws_putline(char *str)
{
fwrite(str,1,strlen(str),ws_fdw); // writes 23 characters
fflush(ws_fdw); // returns -1
}
-
Yes, I've replicated your error. I don't think writing through the stream functions is going to work. I think you'll have to get rid of of the _open_osfhandle() and fdopen() calls and use the raw socket functions. I'm sorry for wasting your time.
Here is the new version of ws_putline():
Code:
void ws_putline(char *str)
{
if (send(ws_sockfd, str, strlen(str), 0) == SOCKET_ERROR)
{
printf("send() failed with error %d\n", WSAGetLastError());
}
}
-
Similarly ws_putdata() becomes:
Code:
int ws_putdata(int *buf, int ndata)
{
int n = send(ws_sockfd, buf, ndata, 0);
if (n == SOCKET_ERROR)
{
printf("send() failed with error %d\n", WSAGetLastError());
}
return(n);
}
-
You didnt waste my time, dont worry about it. How do I used raw socket functions. I put in the new putline, it still didnt work, ill use the debugger to check out whats going wrong. I just dont know what raw sockets functions are.
-
ws_getdata() becomes:
Code:
ws_getdata(int *buf, int ndata)
{
int n = recv(ws_sockfd, buf, ndata, 0);
if (n == SOCKET_ERROR)
{
printf("recv() failed with error %d\n", WSAGetLastError());
}
return(n);
}
-
for getline here's what i wrote, but i still got the same thing.
Code:
int ws_getline(char *str, int maxlen)
{
char *p;
// p= fgets(str,maxlen,ws_fdr);
// if(p == NULL) return(EOF);
// return(strlen(p));
int ret;
ret = recv(ws_sockfd,p,maxlen,0);
str=p;
return ret;
}
return is still -1.
for ws_putline(), i did pretty much what you said, I changed it a little.
Code:
void ws_putline(char *str)
{
//fwrite(str,1,strlen(str),ws_fdw); // writes 23 characters
//fflush(ws_fdw);// returns EOF error. returns -1 value
int n=0;
if (send(ws_sockfd, str, strlen(str), 0) == SOCKET_ERROR)
{
printf("send() failed with error %d\n", WSAGetLastError());
}
else
{
n= send(ws_sockfd, str, strlen(str), 0);
n;
str;
}
}
n is equal to 23 when this is said and done with
-
Here is an implementation of ws_getline():
Code:
int ws_getline(char *str, int maxlen)
{
int total = 0;
while (total < maxlen - 1)
{
/* Get a character */
int ret = recv(ws_sockfd, str, 1, 0);
if (ret == SOCKET_ERROR)
{
printf("recv() failed with error %d\n", WSAGetLastError());
break;
}
else if (ret > 0)
{
/* Increment received character count */
total++;
/* Check if we are finished this line */
if (*str == '\n') break;
/* Move to next character in buffer */
str++;
}
}
*str = '\0';
return total;
}
-
No, your ws_putline is calling send() twice. If you need the return value from send() use:
Code:
void ws_putline(char *str)
{
int n = send(ws_sockfd, str, strlen(str), 0);
if (n == SOCKET_ERROR)
{
printf("send() failed with error %d\n", WSAGetLastError());
}
}
-
Once you have replaced the functions it should work. You can delete these lines entirely:
Code:
fd_rd = _open_osfhandle(ws_sockfd, _O_RDWR);
if (fd_rd == -1) exit(-1);
ws_fdr= fdopen(fd_rd,"r");
ws_fdw= fdopen(fd_rd,"w");
00640:
if( ws_fdr == NULL || ws_fdw == NULL)
err(FATAL,"STP: cannot open ws_fdw/ws_fdr\n");
-
I tried that, it made my program freeze at the line
int ret = recv(ws_sockfd, str, 1, 0);
-
That means it is waiting to receive something. Could you post the new code?
-
I will, but should it take this long to receive, i mean its been sitting here for a while
-
I was also thinking, you know how I do have the ws_fdr and ws_fdw in the server, but i wont be using it in this, is that going to affect how this thing logs on or gets the password, version, interface, etc.?