🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

someone please tell me what this means?

Started by
15 comments, last by kalldrex 23 years, 4 months ago
Here''s the line that''s causing the error: int err = recvfrom(s,username_buf,25,0); E:\Programming\Test\winsock acctpass test.cpp(47) : error C2660: ''recvfrom'' : function does not take 4 parameters any ideas?
ALL YOUR BASE ARE BELONG TO US!!!!
Advertisement
It''s exactly what the error says... you have either passed too few or too many variables into the function.
quote: Original post by kalldrex

Here''s the line that''s causing the error:

int err = recvfrom(s,username_buf,25,0);

E:\Programming\Test\winsock acctpass test.cpp(47) : error C2660: ''recvfrom'' : function does not take 4 parameters

any ideas?


It means that you have the wrong number of parameters for that function.

  int PASCAL FAR recvfrom ( int s, char FAR * buf, int len, int flags, struct sockaddr FAR * from, int FAR * fromlen );   


-------
Andrew
the document at ftp://ftp.stardust.com/pub/winsock/version1/docs/spec/winsock.html

It says the last 2 paramaters are optional. Evne so i can''t figure out what i would put in the struct sockaddr FAR * from! I don''t know how to set it up!
ALL YOUR BASE ARE BELONG TO US!!!!
quote: Original post by kalldrex
It says the last 2 paramaters are optional.


They may be optional but you still need to pass something into it, even if it is just null:

recvfrom(s,username_buf,25,0,NULL,NULL);


The important part is:

"If from is non-zero, and the socket is of type SOCK_DGRAM, the network address of the peer which sent the data is copied to the corresponding struct sockaddr. The value pointed to by fromlen is initialized to the size of this structure, and is modified on return to indicate the actual size of the address stored there."

Just in this case from is NULL(ie 0) so it won''t do this.

-------
Andrew
THANK YOU I LOVE YOU IT WORKED :D
ALL YOUR BASE ARE BELONG TO US!!!!
now what's wrong with this?
    #include <stdio.h>#include <winsock2.h>#include <iostream.h>int main(int argc, char* argv[]){		sockaddr_in me;	struct you;	WSADATA wsaData;		SOCKET s;	char *username_buf=NULL;	char *password_buf=NULL;	int nRet = 0;		if((nRet = WSAStartup(MAKEWORD(2,0), &wsaData)))		{				switch(nRet)				{				case WSASYSNOTREADY:					printf("WSASYSNOTREADY\n");				case WSAVERNOTSUPPORTED:					printf("WSAVERNOTSUPPORTED\n");		case WSAEINPROGRESS:		printf("WSAEINPROGRESS\n");		case WSAEPROCLIM:				printf("WSAEPROCLIM\n");		case WSAEFAULT:					printf("WSAEFAULT\n");	};		return 1;	}	s=socket(AF_INET, SOCK_DGRAM, 0);	if (s==INVALID_SOCKET)	{		printf("Could not create socket: %d\n",WSAGetLastError());		return 1;	}	me.sin_family = AF_INET;	me.sin_port = htons(5151); 	me.sin_addr.s_addr = htonl(INADDR_ANY);	cout <<"Testing\n";	if (bind(s, (SOCKADDR *)&me, sizeof(me)) == SOCKET_ERROR){	cout <<"bind() failed: ";WSAGetLastError();	return 1;}//allocate dataint err = recvfrom(s,username_buf,25,0,NULL,NULL);if (err==0 || err==INVALID_SOCKET){	cout <<"Couldn't recieve username: "<<WSAGetLastError()<<'\n';	return 1;}err = recvfrom(s,password_buf,25,0,NULL,NULL);if (err==0 || err==INVALID_SOCKET){	cout <<"Couldn't recieve password: "<<WSAGetLastError()<<'\n';	return 1;}cout <<"everything works right now\n";return 1;}    


There aren't any compiling errors but if you run it your'll see that you get the message:"Could not recieve username: 10014". I looked that error code up and saw that it meant WSAEFAULT:The namelen argument is incorrect. I tried to correct this by putting the var "int len=25" and having int err = recvfrom(s,username_buf,len,0,NULL,NULL); so i'm confused. any ideas?

*UPDATE*
well i found out that for some reason it doesn't like the last NULL char but i can't figure out how to fix it



Edited by - kalldrex on February 20, 2001 6:12:45 PM
ALL YOUR BASE ARE BELONG TO US!!!!
I cant imagine the last 2 parameters being optional. The function is recvfrom, meaning "receive data sent from the specified socket". In otherwords, you need to indicate which socket you want to check on (thats the first parameter), and which address you are expecting the data to come from (the 5th and 6th parameters). If the last 2 were optional, not specifying then would just make this the same as recv, so wouldnt it be better to just call recv instead?
OKay well tell me this. i changed it to:

int err = recv(s,username_buf,dwLength,0);

and it''s doing the same thing!
ALL YOUR BASE ARE BELONG TO US!!!!
Do you create username_buf anywhere? At the top you set it to NULL and then try and pass it into recv(...). You have to pass in a valid buffer that that recv() can fill up with incomming data. Since you are sending in NULL for the buffer recv() cannot work.

int PASCAL FAR recv ( int s, char FAR * buf, int len, int flags); s A descriptor identifying a connected socket. buf A buffer for the incoming data. <---len The length of buf. flags Specifies the way in which the call is made.


Try to create the buffer first like:
   username_buf = new char[25];  




-------
Andrew

This topic is closed to new replies.

Advertisement