![]() |
| | #1 |
| Registered User Join Date: May 2004
Posts: 215
| Connecting to Server Code: Code:
// server.c in UNIX
/* The client makes a simple identification */
if(fgets(line,MAXLINE,fdr) == NULL) goto finish;
/*if(sscanf(line,"%s %s %s",who,passwd,version) != 3) goto finish;*/
strcpy(interface, "stpc");
if(sscanf(line, "%s %s %s %s",who,passwd,version,interface) < 3) goto finish;
// this printf ensures that line has an interface
// for the logs
sprintf(line, "%s %s %s %s\n",who,passwd,version,interface);
if(strcmp(passwd,PASSWD) != 0) goto finish;
fprintf(stplog," %s %s %s",timestamp(),whoami,line);
fflush(stplog);
/* Let the client know we are connected */
fprintf(fdw,"CONNECTED\n");
fflush(fdw);
that was the server portion, and now below is the one I am trying to code, which is in windows.
Code:
// client.c in windows
fd_rd = _open_osfhandle(ws_sockfd, 0);
if (fd_rd == -1) exit(-1);
ws_fdr= fdopen(fd_rd,"r");
ws_fdw= fdopen(fd_rd,"w");
if( ws_fdr == NULL || ws_fdw == NULL)
err(FATAL,"STP: cannot open ws_fdw/ws_fdr\n");
/* send authorization */
printf("Sending authorization!\n");
sprintf(line,"%s %s %s %s\n","STP",PASSWD,VERSION,"stpc"); // sets line to the ip, password, version, and interface
ws_putline(line);
fflush(ws_fdw);
printf("Authorization sent, awaiting confirmation!\n");
/* get connection acknowledgement */
/*
Below is where we get our
Connection failures
*/
ws_getline(line,MAXLINE);
if(strcmp(line,"CONNECTED\n") != 0) {
err(WARN,"STP: Connection rejected by waveserver - %s\n", line);
continue;
}
int ws_getline(char *str, int maxlen)
{
char *p, *fgets();
p= fgets(str,maxlen,ws_fdr);
if(p == NULL) return(EOF);
return(strlen(p));
}
void ws_putline(char *str)
{
fwrite(str,1,strlen(str),ws_fdw);
fflush(ws_fdw);
}
|
| osal is offline | |
| | #2 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| Code: fd_rd = _open_osfhandle(ws_sockfd, _O_RDONLY); if (fd_rd == -1) exit(-1); ws_fdr= fdopen(fd_rd,"r"); ws_fdw= fdopen(fd_rd,"w"); Try: Code: fd_rd = _open_osfhandle(ws_sockfd, _O_RDWR); Also, your code is a buffer overrun waiting to happen: Code: if(sscanf(line, "%s %s %s %s",who,passwd,version,interface) < 3) goto finish;
// this printf ensures that line has an interface
// for the logs
sprintf(line, "%s %s %s %s\n",who,passwd,version,interface);
|
| anonytmouse is offline | |
| | #3 |
| Registered User Join Date: May 2004
Posts: 215
| Thanks, i changed what you said to change. I was instructed not to change the server file, this is for my work, im interning at this place, and they want me to make it run on windows. But as far as what the server is getting, the first parameter is who the user is i think, and its just STP, and then the password and version are sent in, password "stpisgreat" and version is "1.4" and then the interface, which is just a string "stpc". I dont know what the point to those are but thats the way they designed it. There a site where I can post both the client and server programs on so you can see the entire code, which so ill send you those right now. And thanks a lot for all the help, I really appreciate it, Ive been Heres the client.c program: http://sourcepost.sytes.net/sourcevi...ource_id=14705 And here's the server program: http://sourcepost.sytes.net/sourcevi...ource_id=14706 On the client.c program, the lines in question are between 00630 to 00670 and for the server program: 00210 to 00230. Thanks for all your help. I definitely need it. I hope you can help me solving this problem, Ive spent since last thursday trying to figure it out. |
| osal is offline | |
| | #4 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| You need to tell me how it is failing. Can I assume it is failing here: Code: ws_getline(line,MAXLINE);
if(strcmp(line,"CONNECTED\n") != 0) {
err(WARN,"STP: Connection rejected by waveserver - %s\n", line);
continue;
}
EDIT: Also try changing to: Code: ws_fdr= fdopen(fd_rd,"rb"); ws_fdw= fdopen(fd_rd,"wb"); Last edited by anonytmouse; 06-08-2004 at 12:23 AM. |
| anonytmouse is offline | |
| | #5 |
| Registered User Join Date: May 2004
Posts: 215
| Oh ok, well I do believe that is where it is failing, for some reason, it is not equal to CONNECTED, however, on UNIX, that function works and the server connects. I checked on the debugger, line is equal to STP stpisgreat 1.4 stpc. I dont understand why it would work on UNIX but not on windows |
| osal is offline | |
| | #6 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| Code: sprintf(line,"%s %s %s %s\n","STP",PASSWD,VERSION,"stpc");
ws_putline(line);
fflush(ws_fdw);
/* get connection acknowledgement */
ws_getline(line,MAXLINE);
if(strcmp(line,"CONNECTED\n") != 0) {
err(WARN,"STP: Connection rejected by waveserver - %s\n", line);
continue;
}
This is what you put into the line buffer with the call to sprintf(). So now we know that the ws_getline() call is failing (otherwise it would replace the contents of the line buffer). ws_getline() could be failing because ws_putline() is failing(ie. nothing has been sent to the server). You need to check the return value of fwrite() in ws_putline(). And did you try the binary mode I suggested in the previous post? |
| anonytmouse is offline | |
| | #7 |
| Registered User Join Date: May 2004
Posts: 215
| Yeah I just tried th binary right now, still didnt work. I'll work on this later tomorrow, I have work in the morning, i did try checking the ws_getline and ws_putline functions in the debugger, but line was still the same. Ill work on it tomorrow. thanks for all the help. ill get back to you tomorrow about this. gnite |
| osal is offline | |
| | #8 |
| Registered User Join Date: May 2004
Posts: 215
| ok, i tried looking through the debugger. I noticed that when it would assign the values of the password, interface, and version, etc. it would have this other character in the end, so to test it out I used strcpy(line, "STP stpisgreat 1.4 stpc"), but I still got the same error. I also noticed that in the putline function, fwrite returns 19 characters, which is right, since the string is from 0-19. Here is where I think the error is occurring. In the ws_getline() function. below is the code: Code:
int ws_getline(char *str, int maxlen)
{
char *p, *fgets();
p= fgets(str,maxlen,ws_fdr);
if(p == NULL) return(EOF);
return(strlen(p));
}
Also, one more thing. If you want to run my actual program, just copy and paste the client.c program, the server program is running on the net, so you can actually try to connect to it. I'm not suppose to change anything on the server.c program, they just let me take a look at it since I was having trouble with it. Hope you can help me solve this problem. Thanks. |
| osal is offline | |
| | #9 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| >> it would have this other character in the end << That is the new line character('\n'). Code: char *p, *fgets();
|
| anonytmouse is offline | |
| | #10 |
| Registered User Join Date: May 2004
Posts: 215
| Did that, it didnt work. |
| osal is offline | |
| | #11 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| I count 23 characters in "STP stpisgreat 1.4 stpc\n", not 19! |
| anonytmouse is offline | |
| | #12 |
| Registered User Join Date: May 2004
Posts: 215
| Youre right, the reason why it was 19 for me, and now back to 23 is because in the code, you can take out the stpc part and just insert the first three items. The server will automatically put the stpc in if im not mistaken. But Ive put back the stpc in, and now its 23 again. |
| osal is offline | |
| | #13 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| Code: if(fgets(line,MAXLINE,fdr) == NULL) goto finish; |
| anonytmouse is offline | |
| | #14 |
| Registered User Join Date: May 2004
Posts: 215
| I thought the server was receiving in the ws_putline function. Here's how it looks Code: void ws_putline(char *str)
{
fwrite(str,1,strlen(str),ws_fdw);
fflush(ws_fdw);
}
|
| osal is offline | |
| | #15 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| But is the server actually receiving what we have sent? Code: fprintf(stplog," %s %s %s",timestamp(),whoami,line); |
| anonytmouse is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| access violation when connecting to server | happyclown | Networking/Device Communication | 1 | 03-10-2009 12:46 AM |
| connecting to server with wrong port | liri | Networking/Device Communication | 3 | 11-13-2007 03:52 AM |
| socket question | Unregistered | C Programming | 3 | 07-19-2002 01:54 PM |