ethernet comunication on ipbox350

Kreuzuebersetzer, Diskussion über Änderungen im Tuxbox-CDK und Tuxbox-CVS
giorgino
Neugieriger
Neugieriger
Beiträge: 10
Registriert: Montag 14. September 2009, 15:43

ethernet comunication on ipbox350

Beitrag von giorgino »

Dear all,
I try to compile and run an example about a server/client communication between my development Desktop PC and my IPBOX350. The client code is the following, but firstly I had problems with htons() htonl and after solving it using integer values,the programs not finish the execution (because it arrives here returnStatus = read(simpleSocket, buffer, sizeof(buffer));). If the program is executed in the Desktop PC (both client and server) it works. Do you are able to help me to understand where it is the problem?

Good day
G.

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main(int argc, char *argv[]) {
int simpleSocket = 0;
int simplePort = 0;
int returnStatus = 0;
char buffer[512] = "";
struct sockaddr_in simpleServer;

if (3 != argc) {
fprintf(stderr, "Usage: %s <server> <port>\n", argv[0]);
exit(1);
}

/* create a streaming socket */
simpleSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
printf("simpleSocket= %d\n",simpleSocket);
if (simpleSocket == -1) {
fprintf(stderr, "Could not create a socket!\n");
exit(1);
}
else {
fprintf(stderr, "Socket created!\n");
}

/* retrieve the port number for connecting */

simplePort = atoi(argv[2]);
//printf("simplePort=%d\n",simplePort);

/* set up the address structure */

/* use the IP address argument for the server address */
bzero(&simpleServer, sizeof(simpleServer));
simpleServer.sin_family = AF_INET;

inet_addr(argv[1], &simpleServer.sin_addr.s_addr);
printf("argv[1]=%s\n",argv[1]);
//simpleServer.sin_addr.s_addr=inet_addr(argv[1]);

//simpleServer.sin_addr.s_addr=-1305433920;
printf("addr=%d\n",simpleServer.sin_addr.s_addr);
printf("addr=%u\n",simpleServer.sin_addr.s_addr);



simpleServer.sin_port = htons(simplePort);


/* connect to the address and port with our socket */
returnStatus = connect(simpleSocket, (struct sockaddr *)&simpleServer, sizeof(simpleServer));
if (returnStatus == 0) {
fprintf(stderr, "Connect successful!\n");
}
else {
fprintf(stderr, "Could not connect to address!\n");
close(simpleSocket);
exit(1);
}

/* get the message from the server */

returnStatus = read(simpleSocket, buffer, sizeof(buffer));
printf("returnStatus=%d\n",returnStatus);
if ( returnStatus > 0 ) {
printf("%d: %s", returnStatus, buffer);
}
else {
fprintf(stderr, "Return Status = %d \n", returnStatus);
}

close(simpleSocket);

return 0;
}
hannebamb(el)
Foren-Moderator
Beiträge: 297
Registriert: Montag 11. Oktober 2004, 14:51

Re: ethernet comunication on ipbox350

Beitrag von hannebamb(el) »

AFAIK

Code: Alles auswählen

returnStatus = read(simpleSocket, buffer, sizeof(buffer));)
is a blocking call, which means it sits there and waits until data arrives or an error occurs.
So you maybe have a mismatch in portnumbers from Little <==> Big Endianess ?
giorgino
Neugieriger
Neugieriger
Beiträge: 10
Registriert: Montag 14. September 2009, 15:43

Re: ethernet comunication on ipbox350

Beitrag von giorgino »

Thank you for the answer.
It is possible considering that htons and htonl don't work. But How i can solve the problem?


G.
giorgino
Neugieriger
Neugieriger
Beiträge: 10
Registriert: Montag 14. September 2009, 15:43

Re: ethernet comunication on ipbox350

Beitrag von giorgino »

In particular when i use htons htonl I receive the following error

./clientSTB: relocation error: ./clientSTB: symbol htons, version GLIBC_2.0 not defined in file libc.so.6 with link time reference
hannebamb(el)
Foren-Moderator
Beiträge: 297
Registriert: Montag 11. Oktober 2004, 14:51

Re: ethernet comunication on ipbox350

Beitrag von hannebamb(el) »

well, you didn't have the executable in when mklibs was running, so that symbol has been stripped from libc
insert your binary before stripping the libraries, precisely before mklibs runs and you should be OK


regards


HB
giorgino
Neugieriger
Neugieriger
Beiträge: 10
Registriert: Montag 14. September 2009, 15:43

Re: ethernet comunication on ipbox350

Beitrag von giorgino »

Thank you

I solved the problem. It is a question of little and big endian.

Thanks another time