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 04-28-2010, 06:25 AM   #1
ruud
LQ Newbie
 
Registered: Sep 2007
Posts: 17

Rep: Reputation: 0
Problem While Doing Scoket Programming


Hi everyone,

I write programs for multicasting but its giving some kind of error. Can anyone help with these?

MulticastClient.cpp

Code:
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>

int main(int argc, char *argv[]) {
  struct sockaddr_in sa;
  int s, n = sizeof(struct sockaddr), on = 1, len = strlen(argv[1]);
  if ( (s = socket(AF_INET,SOCK_DGRAM,0)) < 0 ) return(1);
  if ( setsockopt(s, SOL_SOCKET, SO_BROADCAST,  // broadcast option
                  (void *)&on, sizeof(on)) != 0) return(1);
  sa.sin_family = AF_INET;
  sa.sin_addr.s_addr = htonl(INADDR_BROADCAST); // 255.255.255.255
  sa.sin_port = htons(1111);
  sendto(s, argv[1], len, 0, (const struct sockaddr *)&sa, n);
}
And MulticastServer.cpp

Code:
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>

int main(int argc, char *argv[]) {
  struct sockaddr_in sa;
  int s, n = sizeof(struct sockaddr), on = 1, len = strlen(argv[1]);
  if ( (s = socket(AF_INET,SOCK_DGRAM,0)) < 0 ) return(1);
  if ( setsockopt(s, SOL_SOCKET, SO_BROADCAST,  // broadcast option
                  (void *)&on, sizeof(on)) != 0) return(1);
  sa.sin_family = AF_INET;
  sa.sin_addr.s_addr = htonl(INADDR_BROADCAST); // 255.255.255.255
  sa.sin_port = htons(1111);
  sendto(s, argv[1], len, 0, (const struct sockaddr *)&sa, n);
}
when i try to comile it it giving following error:

Code:
bash-3.00$ CC MulticastClient.cpp -o MulticastClient
Undefined                       first referenced
 symbol                             in file
sendto                              MulticastClient.o
socket                              MulticastClient.o
setsockopt                          MulticastClient.o
ld: fatal: Symbol referencing errors. No output written to MulticastClient
bash-3.00$
can anyone tell me how to fix it??
 
Old 04-28-2010, 07:40 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
I assume you are running Solaris/OpenSolaris so you need to add the "-lsocket -lnsl" flags to your CC command.
 
  


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
Qt Programming Problem chanwing Programming 7 04-20-2005 04:18 AM

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

All times are GMT -5. The time now is 10:08 PM.

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