Hello. I'm attempting to understand network programming in particular Multicasting originally with Python but I hit upon a privilege problem when executing my Python scripts. To try and get round the problem I thought I'd try similar things in C but I still get the same problem i.e. Operation not permitted.
As my learning material I am using the book 'UNIX network programming Volume 1' from Addison Wesley and using code from chapter 21, Multicasting. At first I just simply wanted to send a multicast packet and watch the packets on the network using wireshark. The following is the some code I have taken from the above book, section 21.10 (I have commented out the functions to do with receive:
The code for send_all():Code:#include "unp.h" void recv_all(int, socklen_t); void send_all(int, SA *, socklen_t); int main(int argc, char **argv) { int sendfd, recvfd; const int on = 1; socklen_t salen; struct sockaddr *sasend, *sarecv; if (argc != 3) err_quit("usage: sendrecv <IP-multicast-address> <port#>"); sendfd = Udp_client(argv[1], argv[2], (void **) &sasend, &salen); printf("Send socket is: %i\n",sendfd); //recvfd = Socket(sasend->sa_family, SOCK_DGRAM, 0); //Setsockopt(recvfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); //sarecv = Malloc(salen); //memcpy(sarecv, sasend, salen); //Bind(recvfd, sarecv, salen); //Mcast_join(recvfd, sasend, salen, NULL, 0); //Mcast_set_loop(sendfd, 0); //if (Fork() == 0) // recv_all(recvfd, salen); /* child -> receives */ send_all(sendfd, sasend, salen); /* parent -> sends */ }
The code for Sendto() I cannot find as yet within the book, but I believe it is a wrapper function for the system function sendto().Code:#include "unp.h" #include <sys/utsname.h> #define SENDRATE 5 /* send one datagram every five seconds */ void send_all(int sendfd, SA *sadest, socklen_t salen) { char line[MAXLINE]; /* hostname and process ID */ struct utsname myname; if (uname(&myname) < 0) err_sys("uname error");; snprintf(line, sizeof(line), "%s, %d\n", myname.nodename, getpid()); for ( ; ; ) { printf("Attempting to send.\n"); Sendto(sendfd, line, strlen(line), 0, sadest, salen); sleep(SENDRATE); } }
Unfortunately, when I execute the compiled code I get the following error (even if I use 'sudo' too)
Can anyone tell me how to get permissions to do this as even 'sudo' doesn't work.sendto error: Operation not permitted
(I'm using Ubuntu 10.04)



LinkBack URL
About LinkBacks



