Skip to content

Commit

Permalink
watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-who committed Jan 11, 2024
1 parent 7279fdb commit 06d1c91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions spit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ target_link_libraries(interfaces spitlib m aio pthread numa pci)
add_executable(blockdevices blockdevicesMain.c blockdevices.c blockdevices.h keyvalue.c keyvalue.h)
target_link_libraries(blockdevices spitlib m aio pthread numa pci)

add_executable(broadcastwatch broadcastwatch.c multicast.h)

add_executable(interfacesService interfacesService.c interfaces.c interfaces.h iprange.c iprange.h httpd.c httpd.h)
target_link_libraries(interfacesService spitlib m aio pthread numa pci)

Expand Down
23 changes: 17 additions & 6 deletions spit/mc.c → spit/broadcastwatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ just one host and as a receiver on all the other hosts
#include <arpa/inet.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


#include "multicast.h"

main(int argc)
{
#define MESSAGELEN 1024

int main(int argc, char *argv[]) {
struct sockaddr_in addr;
int addrlen, sock, cnt;
socklen_t addrlen;
int sock, cnt;
struct ip_mreq mreq;
char message[200];
char message[MESSAGELEN+1]; // add one for \0

if (argv) {}

/* set up socket */
sock = socket(AF_INET, SOCK_DGRAM, 0);
Expand Down Expand Up @@ -76,18 +84,21 @@ main(int argc)
exit(1);
}
while (1) {
cnt = recvfrom(sock, message, 200, 0,
cnt = recvfrom(sock, message, MESSAGELEN, 0,
(struct sockaddr *) &addr, &addrlen);
if (cnt < 0) {
perror("recvfrom");
exit(1);
} else if (cnt == 0) {
break;
} else {
message[cnt] = '\0';
}
message[cnt] = '\0';

printf("%s: '%s' %d\n", inet_ntoa(addr.sin_addr), message, cnt);
}
}

return 0;
}

0 comments on commit 06d1c91

Please sign in to comment.