/********************************************************************** * * $Id: InPanelUDP.c,v 1.2 2001/03/28 22:23:59 gh Exp $ * * InPanelUDP.c 1.0 * Göran Hasse, Raditex AB, 1.0 * * This lissens for mulitcast packets! * * $Log: InPanelUDP.c,v $ * Revision 1.2 2001/03/28 22:23:59 gh * Strange conflict in previous checkin * * Revision 1.1 2000/03/29 00:18:12 gh * Added a listwidget that listens for Multicasts * * ***********************************************************************/ /* #include */ #include #include #include #include #include #include #include #include #include #include #include /* contains IP #defines */ #include #include #include #include #include #include #include int radius; int s, len, nbytes, one = 1; static struct sockaddr_in sin; static struct ip_mreq imr; char buf[100]; GtkWidget *showrows[10]; GtkWidget *messrow; GtkWidget *entry; struct padcmd { int fd; char string[60]; gpointer data; }; #define PORT 6060 #define GROUP "224.0.0.0" void quit() { gtk_exit(0); } int file_function( struct padcmd *cmdinfo ) { gchar *entry_text; gchar messtext[60]; static int i; int infile, ret_status; char string[80]; infile = cmdinfo->fd; strcpy(messtext, "No more messages in queue"); printf("****\n"); printf("--->Fildescriptor - i funk %d\n", infile ); printf("Funktionen har anropats %d\n", i++); len = sizeof (sin); ret_status = read(infile, string, sizeof(string)); printf("Retur status %d , string -> %s", ret_status, string ); strncpy(cmdinfo->string, string, sizeof(cmdinfo->string)); gtk_entry_set_text( GTK_ENTRY(messrow), string ); for( i = 9 ; i > 0 ; i-- ) { entry_text = gtk_entry_get_text( GTK_ENTRY(showrows[i-1])); gtk_entry_set_text( GTK_ENTRY(showrows[i]), entry_text ); } gtk_entry_set_text( GTK_ENTRY(showrows[0]), string ); fflush(stdout); return 0; } void clear_callback(GtkWidget *widget, GtkWidget *entry) { int i; gchar messtext[60]; strcpy(messtext, "Clear all messages"); gtk_entry_set_text( GTK_ENTRY(messrow), messtext ); for( i = 9 ; i >= 0 ; i-- ) { gtk_entry_set_text( GTK_ENTRY(showrows[i]), " " ); } } int main( int argc, char *argv[] ) { struct padcmd cmdinfo; int i; GtkWidget *window; GtkWidget *vbox, *vbox1, *hbox2; GtkWidget *exit_button, *clear_button; if ((s = socket (AF_INET, SOCK_DGRAM, 0)) == -1) { perror ("socket"); return 1; } if ( setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (one)) == -1 ) { perror("setsockopt: SO_REUSEADDR"); exit(1); } #ifdef SO_REUSEPORT /* * This must be added for OSF1 v2.x (and BSD 4.3) */ if ( setsockopt (s, SOL_SOCKET, SO_REUSEPORT, (char *) &one, sizeof (one)) == -1 ) { perror("setsockopt: SO_REUSEADDR"); exit(1); } #endif sin.sin_family = AF_INET; sin.sin_port = htons (PORT); sin.sin_addr.s_addr = htonl (INADDR_ANY); if (bind (s, (struct sockaddr *) & sin, sizeof (sin)) == -1) { perror ("bind"); return 1; } /* * the original posting was = htonl(inet_addr (GROUP)) * which is wrong. * * Send greeting message to multicast group: */ sin.sin_addr.s_addr = inet_addr (GROUP); if (sendto (s, "Hi!", 4, 0, (struct sockaddr *) & sin, sizeof (sin)) == -1) { perror ("socket"); return 1; } /* * Join the group: * IP multicast address of group: * local IP address of interface: */ imr.imr_multiaddr = sin.sin_addr; imr.imr_interface.s_addr = htonl (INADDR_ANY); if (setsockopt (s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &imr, sizeof (imr)) == -1) { /* * The original posting did not include this: * landmark cs tu-berlin de (Torsten Kerschat) stated: * Using setsockopt again with the same options on the * same socket would fail, although it is correct. Therefore: */ if (errno != EADDRINUSE) { perror("setsockopt: IPPROTO_IP, IP_ADD_MEMBERSHIP"); return 1; } } gtk_init(&argc, &argv); cmdinfo.fd = s; gdk_input_add( s, GDK_INPUT_READ, GTK_SIGNAL_FUNC(file_function), &cmdinfo ); /* create a new window */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize( GTK_WIDGET (window), 600, 325); gtk_window_set_title(GTK_WINDOW (window), "Very simple listwindow"); gtk_signal_connect(GTK_OBJECT (window), "delete_event", (GtkSignalFunc) gtk_exit, NULL); vbox = gtk_vbox_new (FALSE, 0); vbox1 = gtk_vbox_new (FALSE, 0); hbox2 = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_container_border_width (GTK_CONTAINER (window), 10); gtk_widget_show(vbox1); gtk_widget_show(hbox2); gtk_widget_show(vbox); /*----------------------------------------------------------------------*/ messrow = gtk_entry_new_with_max_length (60); for( i = 9 ; i >= 0 ; i-- ) { showrows[i] = gtk_entry_new_with_max_length (60); gtk_entry_set_editable( ( GtkEntry * ) showrows[i], FALSE); gtk_box_pack_start (GTK_BOX (vbox1), showrows[i], TRUE, TRUE, 0); } gtk_box_pack_start (GTK_BOX (vbox1), messrow, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0); /*----------------------------------------------------------------------*/ exit_button = gtk_button_new_with_label("Exit"); gtk_signal_connect_object (GTK_OBJECT (exit_button), "clicked", GTK_SIGNAL_FUNC(gtk_exit), GTK_OBJECT (window)); clear_button = gtk_button_new_with_label ("Clear all"); gtk_signal_connect(GTK_OBJECT(clear_button), "clicked", GTK_SIGNAL_FUNC(clear_callback), showrows[0]); gtk_box_pack_start (GTK_BOX (hbox2), exit_button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox2), clear_button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox2, TRUE, TRUE, 0); gtk_container_border_width (GTK_CONTAINER (vbox), 0); /***********************************************************************/ for( i = 0 ; i < 10 ; i++ ) { gtk_widget_show (showrows[i]); } gtk_widget_show (messrow); gtk_widget_show (exit_button); gtk_widget_show (clear_button); gtk_widget_show(vbox1); gtk_widget_show(hbox2); gtk_widget_show(vbox); gtk_widget_show(window); gtk_main(); return(0); gtk_main(); return 0; }