[En-Nut-Discussion] UDP problem to recv datagram bigger than 1500
SnailHero
yegnem at gmail.com
Tue Sep 2 22:12:06 CEST 2014
Good morning everyone,
I am writing an application for NUT/OS 5.2 and I am facing some problem:
When sending datagram smaller than 1500 everything is ok.
But when I try to send something bigger
The function:
got = NutUdpReceiveFrom(sock, &clientIP, &clientPort, buf, 2600,
LISTEN_TIMEOUT);
always timeout and return 0
I am checking the Ethernet connection with wireshark and it looks like that
the datagram is sent correctly (image)
<http://microcontrollers.2385.n7.nabble.com/file/n191873/udp_1550.jpg>
i really do not understand why it does not work.
Can any one help me? please?
ps: i am using ethernut 5 and windows 7. i put here the code
//UDP SERVER ETHERNUT 5
#include <io.h> #include <stdio.h> #include <dev/board.h> #include
<sys/socket.h>
#include <sys/confnet.h> #include <arpa/inet.h> #include <netinet/in.h>
#define LISTEN_PORT 9806
#define LISTEN_TIMEOUT 1000
UDPSOCKET *sock;
int main(void)
{
u_long baud = 115200;
int got = 0;
NutRegisterDevice(&DEV_DEBUG, 0, 0);
freopen(DEV_DEBUG_NAME, "w", stdout);
_ioctl(_fileno(stdout), UART_SETSPEED, &baud);
puts("\nNut/OS UDP server");
uint8_t initial_mac[6] = { 0x00, 0x06, 0x98, 0x00, 0x00, 0x00 };
u_long initial_ip_addr = inet_addr("192.168.0.118");
u_long initial_ip_mask = inet_addr("255.255.255.0");
if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
puts("Registering " DEV_ETHER_NAME " failed.");
}
else if (NutNetIfConfig(DEV_ETHER_NAME, initial_mac, initial_ip_addr,
initial_ip_mask)) {
puts("Configuring " DEV_ETHER_NAME " failed.");
}
if ((sock = NutUdpCreateSocket(LISTEN_PORT)) == 0) {
puts("Error while creating the UDP socket.");
}
uint16_t length;
length = 1600;
if (NutUdpSetSockOpt(sock, SO_RCVBUF, &length, sizeof(length))) {;
printf("Could not set UDP receive buffer size (%d)\r\n",
length);
puts("Demo halted...\r\n");
while (1);
}
puts("The UDP server is now running. Please launch the Nut/OS discoverer
to send some telegrams.\n\n");
char buf[2600];
int alive = 0;
uint32_t clientIP;
uint16_t clientPort;
for (;;) {
got = NutUdpReceiveFrom(sock, &clientIP, &clientPort, buf, 2600,
LISTEN_TIMEOUT);
if (got < 0){printf("error recv: %d", got);}
//plot each 10 timeout, so i will now that the application did not freeze
alive++;
if (alive >= 10){alive = 0; printf("alive got = %d\n",got);}
if (got > 0){
printf("read %d byte\n",got);
}
}
return 0;
}
//WINDOWS WINSOCK CLIENT
#include <iostream>
using namespace std;
#include <winsock2.h>
#include <stdio.h>
#pragma comment(lib,"ws2_32.lib")
const int CLIENT_PORT=9807; /*the client port number*/
int main(int argc,char* argv[]){
struct sockaddr_in serverAddr; /*server address*/
struct sockaddr_in clientAddr; /*client address*/
int clientSock; /*client sock*/
char buf[2600]; /*buffer the message send and receive*/
char buf2[2600];
int serverPort; /*protocl port*/
int len=sizeof(struct sockaddr);
WSADATA wsaData;
//WSAStartup(0x0202,&wsaData); /*windows socket startup */
int iResult;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
memset((char*)&clientAddr,0,sizeof(clientAddr));
clientAddr.sin_family=AF_INET; /*set client address protocol family*/
clientAddr.sin_addr.s_addr=INADDR_ANY;
clientAddr.sin_port=htons((u_short)CLIENT_PORT); /*set client port*/
serverAddr.sin_family=AF_INET;
serverAddr.sin_addr.s_addr=inet_addr("192.168.0.118");/*get the ip
address*/
if (serverAddr.sin_addr.s_addr==INADDR_NONE){
fprintf(stderr,"bad ip address %s\n",argv[1]);
exit(1);
}
serverPort=9806;
if (serverPort>0)
serverAddr.sin_port=htons((u_short)serverPort);/*get the port*/
else{
fprintf(stderr,"bad port number %s\n",argv[2]);
exit(1);
}
clientSock=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);/*create a socket*/
if (clientSock<0){
fprintf(stderr,"socket creating failed\n");
exit(1);
}
/*
char yes = 1;
if ( setsockopt(clientSock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) ==
-1 )
{
perror("setsockopt");
}
*/
/* if (bind(clientSock,(LPSOCKADDR)&clientAddr,len)<0){//bind a client
address and port
fprintf(stderr,"bind failed\n");
int errorID = WSAGetLastError();
printf("%d",errorID);
exit(1);
}
*/
int i;
for(i = 0; i<2600;i++){
buf[i] = 1;
}
while(1)
{
int sentNbyte, recvNbyte;
//sentNbyte =
sendto(clientSock,buf,strlen(buf),0,(LPSOCKADDR)&serverAddr,len);
sentNbyte = sendto(clientSock,buf,1550,0,(LPSOCKADDR)&serverAddr,len);
printf("sent = %d \n",sentNbyte);
int i;
printf("0 repeat, 1 exit : ");
scanf("%d",&i);
if (i==1){break;}
}
closesocket(clientSock);
WSACleanup();
return 1;
}
--
View this message in context: http://microcontrollers.2385.n7.nabble.com/UDP-problem-to-recv-datagram-bigger-than-1500-tp191873.html
Sent from the MicroControllers - Ethernut mailing list archive at Nabble.com.
More information about the En-Nut-Discussion
mailing list