Date: Mon, 18 Jul 2011 17:04:27 +0300 From: Daniel Braniss <danny@cs.huji.ac.il> To: freebsd-net@freebsd.org Cc: freebsd-hackers@freebsd.org Subject: broadcast oddity Message-ID: <E1QioQt-000MJQ-T9@kabab.cs.huji.ac.il>
next in thread | raw e-mail | index | archive | help
this code behaves correctly when run from a diskless host which booted via PXE, but fails on a host that was booted from disk. hint: the non working sends a packet with a non ethernet broadcast address and an ip address of 255.255.255.255, the working version sets the ethernet address to 0xffffffff and the ip to the network broadcast address. what am I doing wrong? danny PS: what is the correct way to obtain the network broadcast address? #include <sys/types.h> #include <netinet/in.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <stdio.h> void bcast() { int so, on; char msg[BUFSIZ]; struct timespec t2; struct sockaddr_in soin; if((so = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { perror("socket"); exit(-1); } on = 1; if(setsockopt(so, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on))) { perror("setsockopt"); exit(-1); } bzero(&soin, sizeof(struct sockaddr_in)); soin.sin_len = sizeof(struct sockaddr_in); soin.sin_family = AF_INET; soin.sin_addr.s_addr = INADDR_BROADCAST; soin.sin_port = htons(12345); while(1) { clock_gettime(CLOCK_REALTIME, &t2); sprintf(msg, "0x%016x", t2.tv_sec); if(sendto(so, msg, strlen(msg)+1, 0, (struct sockaddr *)&soin, sizeof(struct sockaddr)) < 0) { perror("sendto"); break; } sleep(10); } } main(int cc, char **vv) { bcast(); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1QioQt-000MJQ-T9>