Sponsored Content
Full Discussion: Why UDP broadcast don't run?
Top Forums UNIX for Advanced & Expert Users Why UDP broadcast don't run? Post 302266311 by konvalo on Wednesday 10th of December 2008 12:06:22 AM
Old 12-10-2008
Question Why UDP broadcast don't run?

I use FreeBSD7.0, I want to use UDP broadcast,my code is following:
/*udpcli01.c*/
int
main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("usage: udpcli <IPaddress>");
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(13);
inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
sockfd = Socket(AF_INET, SOCK_DGRAM, 0);
dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr));
exit(0);
}

/*dg_cli.c*/
void
dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen)
{
int n;
char sendline[MAXLINE], recvline[MAXLINE + 1];
while (fgets(sendline, MAXLINE, fp) != NULL) {
sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);
n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);
recvline[n] = 0; /* null terminate */
fputs(recvline, stdout);
}
}

When I run above code,10.1.2.255 is broadcast address,and input a line,like following:
$./udpcli01 10.1.2.255
Hi

It should receive many machine response,but I don't receive any message!
If I ping 10.1.2.255,I can receive many machine response message,why my code can't receive message? How can I modify above code to receive message?

Thanks in advance!
 

8 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

broadcast

Can anybody hellp me troubleshoot this error. Using HP-Uxix B.10.X " *****ARPA/9000 NETWORKING***** Mon Jun 30 SAT 2003 20:18:12.xxxxxxx DISASTER Subsys: NS_LS_PROBE LOC:01001 Network NS_LS_PROBE DISASTER 1001, pid arp: ether address is broadcast for IP address zzzzzzz! " where... (1 Reply)
Discussion started by: SEB
1 Replies

2. Shell Programming and Scripting

Run expect script in systems that don't support it out of box

Noob question .. My Java based application needs to change some user passwords based on some user actions. Since this application can run on Redhat AS2.1 / AS4.0 / Solaris 9 etc, the most safe and portable solution that I could think of was: Use expect. Now, expect is not available on all... (1 Reply)
Discussion started by: namityadav
1 Replies

3. Programming

How to broadcast a message ?

My problem definition is ,I have to send a message from one node in a network and it has to be broadcasted to all other nodes in the network.The program what I have given below will be running in all the nodes in the network.The same program should be capable of sending(broadcasting) and receiving.... (0 Replies)
Discussion started by: vigneshinbox
0 Replies

4. IP Networking

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (0 Replies)
Discussion started by: moti12
0 Replies

5. Programming

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (6 Replies)
Discussion started by: moti12
6 Replies

6. Shell Programming and Scripting

Background processes in a pipeline don't run asynchronously?

I'm wondering about what causes this behavior. Mainly, given the first case below, why the second changes the behavior of ''&'' to execute sequentially merely because the command group containing calls to f() is part of a pipeline. The 4th example bizarrely once again works as the first, even with... (2 Replies)
Discussion started by: ormaaj
2 Replies

7. Shell Programming and Scripting

Nc won't send udp broadcast!?

Greetings, I want to send broadcast udp from a script. This works but is not broadcast: echo -n "this is my message\r\n" | nc -u 192.168.0.12 5100 The broadcast version does not work: echo -n "this is my message\r\n" | nc -u 192.168.0.255 5100 Suggestions on the right way to do this... (2 Replies)
Discussion started by: anotherstevest
2 Replies

8. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies
udp(n)								 Tcl UDP extension							    udp(n)

__________________________________________________________________________________________________________________________________________________

NAME
udp - Create UDP sockets in Tcl SYNOPSIS
package require Tcl 8.2 package require udp 1.0 udp_open ?port? udp_conf sock host port udp_conf sock ?-myport? ?-remote? ?-peer? ?-broadcast bool? ?-ttl count? udp_conf ?-mcastadd groupaddr? udp_conf ?-mcastdrop groupaddr? udp_peek sock ?buffersize? _________________________________________________________________ DESCRIPTION
This package provides support for using UDP through Tcl. The package provides a new channel type and attempts to permit the use of packet oriented UDP over stream oriented Tcl channels. The package defined three commands but udp_conf should be considered depreciated in favour of the standard Tcl command fconfigure. COMMANDS
udp_open ?port? udp_open will open a UDP socket. If port is specified the UDP socket will be opened on that port. Otherwise the system will choose a port and the user can use the udp_conf command to obtain the port number if required. udp_conf sock host port udp_conf in this configuration is used to specify the remote destination for packets written to this sock. You must call this com- mand before writing data to the UDP socket. udp_conf sock ?-myport? ?-remote? ?-peer? ?-broadcast bool? ?-ttl count? In addition to being used to configure the remote host, the udp_conf command is used to obtain information about the UDP socket. -myport Returns the local port number of the socket. -remote Returns the remote hostname and port number as set using udp_conf sock host port. -peer Returns the remote hostname and port number for the packet most recently received by this socket. -broadcast ?boolean? UDP packets can listen and send on the broadcast address. For some systems a flag must be set on the socket to use broadcast. With no argument this option will return the broadcast setting. With a boolean argument the setting can be modified. -ttl ?count? The time-to-live is given as the number of router hops the packet may do. For multicast packets this is important in specify- ing the distribution of the packet. The system default for multicast is 1 which restricts the packet to the local subnet. To permit packets to pass routers, you must increase the ttl. A value of 31 should keep it within a site, while 255 is global. udp_conf ?-mcastadd groupaddr? udp_conf ?-mcastdrop groupaddr? tcludp sockets can support IPv4 multicast operations. To recieve multicast packets the application has to notify the operating sys- tem that it should join a particular multicast group. These are specified as addresses in the range 224.0.0.0 to 239.255.255.255. udp_peek sock ?buffersize? Examine a packet without removing it from the buffer. This function is not available on windows. EXAMPLES
# Send data to a remote UDP socket proc udp_puts {host port} { set s [udp_open] fconfigure $s -remote [list $host $port] puts $s "Hello, World" close $f } # A simple UDP server package require udp proc udpEventHandler {sock} { set pkt [read $sock] set peer [fconfigure $sock -peer] puts "$peer: [string length $pkt] {$pkt}" return } proc udp_listen {port} { set srv [udp_open $port] fconfigure $srv -buffering none -translation binary fileevent $srv readable [list ::udpEventHandler $srv] puts "Listening on udp port: [fconfigure $srv -myport]" return $srv } set sock [udp_listen 53530] vwait forever close $sock # A multicast demo. proc udpEvent {chan} { set data [read $chan] set peer [fconfigure $chan -peer] puts "$peer [string length $data] '$data'" if {[string match "QUIT*" $data]} { close $chan set ::forever 1 } return } set group 224.5.1.21 set port 7771 set s [udp_open $port] fconfigure $s -buffering none -blocking 0 fconfigure $s -mcastadd $group -remote [list $group $port] fileevent $s readable [list udpEvent $s] puts -nonewline $s "hello, world" set ::forever 0 vwait ::forever exit HISTORY
Some of the code in this extension is copied from Michael Miller's tcludp package. (http://www.neosoft.com/tcl/ftparchive/sorted/comm/tcludp-1.0/) Compared with Michael's UDP extension, this extension provides Windows sup- port and provides the ability of using 'gets/puts' to read/write the socket. In addition, it provides more configuration ability. Enhancements to support binary data and to setup the package for the Tcl Extension Architecture by Pat Thoyts. SEE ALSO
socket(n) KEYWORDS
networking, socket, udp COPYRIGHT
Copyright (c) 1999-2000 Columbia University; all rights reserved udp 1.0.7 udp(n)
All times are GMT -4. The time now is 09:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy