LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-28-2010, 10:02 PM   #1
jamesbon
Member
 
Registered: Jun 2010
Posts: 147

Rep: Reputation: 9
error in a program for udpserver


Code:
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
#define REQUEST 10
#define REPLY 10
int main(int argc,char *argv[]){
struct sockaddr_in serv;
char request[REQUEST],reply[REPLY];
int sockfd,n;
if(argc!=2)
 err_quit("usage: udpcli <IP add of server>");
if((sockfd =socket(PF_INET,SOCK_DGRAM,0))<0)
 err_sys("socket error");
  memset(&serv,0,sizeof(serv));
 serv.sin_family = AF_INET;
 serv.sin_addr.s_addr = inet_addr(argv[1]);
 serv.sin_port = htons(UDP_SERV_PORT);
 if(sendto(sockfd,request,REQUEST,0,(SA),&serv,sizeof(serv))!=REQUEST)
  err_sys("sendto error");
 if((n=recvfrom(sockfd,reply,REPLY,0,(SA)NULL,(int *)NULL))<0)
 err_sys("recvfrom error");
exit(0);
}
Above is a code for UDP server which I am trying.
When I compile it I get following errors
Code:
udpserver.c: In function ‘main’:
udpserver.c:18: warning: incompatible implicit declaration of built-in function ‘memset’
udpserver.c:21: error: ‘UDP_SERV_PORT’ undeclared (first use in this function)
udpserver.c:21: error: (Each undeclared identifier is reported only once
udpserver.c:21: error: for each function it appears in.)
udpserver.c:22: error: ‘SA’ undeclared (first use in this function)
udpserver.c:22: warning: passing argument 6 of ‘sendto’ makes integer from pointer without a cast
/usr/include/sys/socket.h:155: note: expected ‘socklen_t’ but argument is of type ‘struct sockaddr_in *’
udpserver.c:22: error: too many arguments to function ‘sendto’
Any suggestions.

Last edited by jamesbon; 10-28-2010 at 10:13 PM.
 
Old 10-28-2010, 10:36 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
man memset and see what header you to include for it (guessing string.h)
define UDP_SERV_PORT with the value you want to use for your port

guessing SA is supposed to be a typedef for struct sockaddr* and I'm also guessing you have an extra , in your sendto between the (SA) and &serv
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile C program error vuhuynh Linux - Newbie 1 07-06-2010 12:11 PM
Qt program: compile error creolophus Programming 2 08-24-2006 02:53 PM
Error in program dludenar Fedora 1 10-07-2005 03:20 AM
Program error mdkusr Linux - General 2 03-12-2005 01:19 PM
C Program Error? linux_GNUbie Programming 5 12-01-2003 03:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration