Sponsored Content
Top Forums Programming Help needed linux socket programming in c Post 302251648 by esmeco on Monday 27th of October 2008 03:47:17 PM
Old 10-27-2008
Help needed linux socket programming in c

Good evening everyone! Smilie

I'm doing a small client / server application for sharing files in C, and I am trying to implement the following:

The client of my application sends to the address 255.255.255.255 a message requesting a particular file.In the network there is only one server, however, there may be multiple clients.
The server responds with an ACK if it has the file specified by the client.Until now,everythings' allright.
The question arises now,as I want the client, after receiving the confirmation (ACK) from the server, making sure that the reply message comes from the server or if the message is of uknown origin.As so,I have the following code in Client:

Code:
 ... 
 msg_tam = recvfrom (socketfd, buffer, BUFFERSIZE, 0, (struct sockaddr *) & serv_addr, & Nbytes); 

     if (msg_tam <0) 
      Abort ("..."); 

     buffer [msg_tam] = 0; 

    if (SERV_HOST_PORT == ntohs (serv_addr.sin_port) & & strcmp (SERV_HOST_ADDR, (char *) inet_ntoa (serv_addr.sin_addr) == 0) 
 ( 
 ... 
 ) 
 else 
     printf ( "message of unknown origin!");

The SERV_HOST_ADDR is set to "255.255.255.255" so the client can send the file request to the network and the port is also set with a value.Well, the problem arises when the call to the function recvfrom is made, where the ip address of who sent the message is filled in the structure.That address is ,thus, the address where the server is.
As so, when making the comparison between the SERV_HOST_ADDR in the if statement with the address serv_addr.sin_addr filled in the recvfrom call, they will never be the same (even if the reply has come from the server) ,as a it will always enter the else statement.

I would appreciate if someone could help me solve this problem, so that it would be a way the client could check you check whether the reply comes from the server where the client sent the message or from another place.

Thanks in advance for your help!
 

10 More Discussions You Might Find Interesting

1. Programming

Socket programming

Suppose i am writing a C program which is going to use Socket calls. I want to use a Unix port for my Socket. How can i determine a port which is not already in use? (1 Reply)
Discussion started by: Nadeem Mistry
1 Replies

2. Programming

Socket Programming socket

Hello, I actually try to make client-server program. I'm using SCO OpenServer Release 5.0.0 and when I try to compile my code (by TELNET) I've got this error : I'm just using this simple code : and I get the same error if I use : If someone can help me, Thanks (2 Replies)
Discussion started by: soshell
2 Replies

3. UNIX for Advanced & Expert Users

socket programming

Hi, I am trying to connect to more than 60 servers to perform some actions remotely. for this I am using ssh2. But its taking lot of time. Though i am running the command in background, still its taking long time to execute.. Any one let me know can we use sockets instead of ssh2 for... (3 Replies)
Discussion started by: pvamsikr
3 Replies

4. Programming

Socket programming in C

Hi, i know how to use socket for TCP applications, i also know how to use RAW socket, but i would like to use socket just over IP and bellow TCP, do you know how to do that ? i don't want to reimplement IP :) thanks for your answer. (2 Replies)
Discussion started by: nameless`
2 Replies

5. UNIX for Dummies Questions & Answers

Socket programming

in c socket programming, how can I send and received on the same port? (7 Replies)
Discussion started by: Peevish
7 Replies

6. Programming

Help with socket programming in C

hi guys i got this code trying to make connection between the server and multi clients but when i do ./server i got message server waiting then when i run ./client it says client 1 nosuch file i dont know whats that should i use any argument plz help how to compile and run and whats the expected... (1 Reply)
Discussion started by: kedah160
1 Replies

7. UNIX for Dummies Questions & Answers

hi i need help with socket programming

in socket programming how can i : Create for example 3 blank files, namely: server, client, network •Server: act as servers/provider, will receive all requests from different client •Client: requesters •Network: middle-layer of communication between server & client any tips or... (6 Replies)
Discussion started by: kedah160
6 Replies

8. Programming

Socket programming

Hi everyone, I'm new to this forum. I'm working on new project for last few days and this forum already helped me on couple of occasions. I don't have any prior experience with network programming so I'll appreciate any advise given. I'm trying to do the following: 1. open user... (2 Replies)
Discussion started by: _thomas
2 Replies

9. Programming

socket programming

how to include socket.h in visual studio 2005.. (2 Replies)
Discussion started by: asd123
2 Replies

10. IP Networking

help implementing an ip filter in linux/net/socket.c (kernel programming)

hi there so, i was given an assignment: implement a linux system call that blocks all packets that are sent to a given IP (i have to do it without using iptables) i'm really new to kernel programming btw (and i'm enjoying it a lot) so, my syscall is called ip_block() and receives a... (1 Reply)
Discussion started by: lgfaria
1 Replies
pbuilder-uml.conf(5)						     pbuilder						      pbuilder-uml.conf(5)

NAME
pbuilder-uml.conf - configuration file for user-mode-linux port of pbuilder DESCRIPTION
/etc/pbuilder/pbuilder-uml.conf contains default values used in pbuilder-user-mode-linux program invocation. FORMAT
MY_ETH0=tuntap,,,192.168.0.2 Configures ethernet setting used for booting linux. See how rootstrap boots your system, and copy that. Specify --eth0=slirp,12345,/usr/bin/slirp-fullbolt to use the slirp connection. UML_IP=192.168.0.3 IP address to use for guest OS. This can be set to dhcp for obtaining IP address through DHCP. UML_NETMASK=255.255.255.0 Guest OS netmask UML_NETWORK=192.168.0.0 Guest OS network UML_BROADCAST=255.255.255.255 Guest OS broadcast UML_GATEWAY=192.168.0.1 Guest OS gateway PBUILDER_UML_IMAGE=${HOME}/uml-image Guest OS file system image. UML_MOUNT_TMPFS=no Whether to mount tmpfs inside the guest image. This is probably mostly useless. BUILDPLACE=${HOME}/tmp/ The location which build will take place. pbuilder-user-mode-linux will place temporary COW files to there. The user running UML needs to be able to access that directory. UML_MEM=128 The amount of memory allowed for UML. Give more value to here. UML_HOSTNAME=uml-host The hostname for the UML. The hostname should be available in /etc/hosts so that hostname -f will be able to return the FQDN. UML_BUILDRESULT=/directory/of/build/result The directory where build result of pbuilder-user-mode-linux is stored. ROOTSTRAP_IMAGESIZE=size-in-megabytes The size, in MB, of the disk iamge to create. Defaults to 1000. NOTES
It is advised to set APTCACHEHARDLINK to no in ~/.pbuilderrc. see pbuilderrc(5) for details. AUTHOR
Initial coding, and main maintenance is done by Junichi Uekawa <dancer@debian.org>. The homepage is available at http://pbuilder.alioth.debian.org FILES
/etc/pbuilder/pbuilder-uml.conf, ${HOME}/.pbuilderrc SEE ALSO
/usr/share/doc/pbuilder/pbuilder-doc.html, pbuilder-user-mode-linux(1), pbuilder(8), pbuilderrc(5), pdebuild(1) Debian 2003 Jan 8 pbuilder-uml.conf(5)
All times are GMT -4. The time now is 07:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy