projects
/
my-code
/
ivac.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added SO_BROADCAST support
[my-code/ivac.git]
/
datagram.c
diff --git
a/datagram.c
b/datagram.c
index
a140c32
..
83c4bc8
100644
(file)
--- a/
datagram.c
+++ b/
datagram.c
@@
-30,7
+30,7
@@
int main(int argc, char *argv[]) {
int send_fd;
struct sockaddr_in local_addr, remote_addr;
socklen_t remote_addr_len;
int send_fd;
struct sockaddr_in local_addr, remote_addr;
socklen_t remote_addr_len;
- int send_bytes;
+ int send_bytes
, read_bytes
;
if(argc!=3) {
printf("usage: %s <target-ip/broadcast-addr> <port>\n",argv[0]);
if(argc!=3) {
printf("usage: %s <target-ip/broadcast-addr> <port>\n",argv[0]);
@@
-41,6
+41,8
@@
int main(int argc, char *argv[]) {
printf("can't open socket.\n");
exit(1);
}
printf("can't open socket.\n");
exit(1);
}
+
+ // setsockopt(send_fd,SOL_SOCKET,SO_BROADCAST,
memset(&local_addr,0,sizeof(local_addr));
local_addr.sin_family=AF_INET;
memset(&local_addr,0,sizeof(local_addr));
local_addr.sin_family=AF_INET;
@@
-53,18
+55,18
@@
int main(int argc, char *argv[]) {
exit(1);
}
exit(1);
}
-
//
remote_addr_len=sizeof(remote_addr);
+ remote_addr_len=sizeof(remote_addr);
memset(&remote_addr,0,sizeof(remote_addr));
remote_addr.sin_family=AF_INET;
remote_addr.sin_port=htons(atoi(argv[2]));
memset(&remote_addr,0,sizeof(remote_addr));
remote_addr.sin_family=AF_INET;
remote_addr.sin_port=htons(atoi(argv[2]));
- remote_addr.sin_addr=inet_addr(argv[1]);
+ remote_addr.sin_addr
.s_addr
=inet_addr(argv[1]);
/* send stuff .... */
read_bytes=1;
while(read_bytes>0) {
unsigned char buf[1000];
read_bytes=read(0,buf,sizeof(buf));
/* send stuff .... */
read_bytes=1;
while(read_bytes>0) {
unsigned char buf[1000];
read_bytes=read(0,buf,sizeof(buf));
- send_bytes=sendto(send_fd,buf,sizeof(buf),
&remote_addr,sizeof(remote_addr
);
+ send_bytes=sendto(send_fd,buf,sizeof(buf),
0,(struct sockaddr *)&remote_addr,remote_addr_len
);
}
close(send_fd);
}
close(send_fd);