![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| network and broadcast address | scofiled83 | Shell Programming and Scripting | 4 | 11-09-2008 08:55 AM |
| broadcast | SEB | UNIX Desktop for Dummies Questions & Answers | 1 | 07-08-2003 10:40 AM |
| Broadcast IP Address | PBNOSGT | IP Networking | 4 | 03-11-2002 09:43 PM |
| broadcast email??? | solvman | UNIX for Dummies Questions & Answers | 1 | 10-08-2001 11:20 AM |
| broadcast address | 98_1LE | IP Networking | 1 | 02-06-2001 02:54 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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! |
|
||||
|
Hi, you need to set SO_BROADCAST option for the socket with 'setsockopt' function.
And you need suitable server to respond... |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|