Created
March 4, 2014 04:06
-
-
Save benpicco/9340116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <destiny.h> | |
#define IF_ID (0) | |
#define NODE_ID (23) | |
static void init(void) { | |
ipv6_addr_t tmp; | |
net_if_set_hardware_address(IF_ID, NODE_ID); | |
ipv6_addr_set_link_local_prefix(&tmp); | |
ipv6_addr_set_by_eui64(&tmp, IF_ID, &tmp); | |
ipv6_net_if_add_addr(IF_ID, &tmp, NDP_ADDR_STATE_PREFERRED, | |
NDP_OPT_PI_VLIFETIME_INFINITE, | |
NDP_OPT_PI_PLIFETIME_INFINITE, 0); | |
ipv6_addr_set_all_nodes_addr(&tmp); | |
ipv6_net_if_add_addr(IF_ID, &tmp, NDP_ADDR_STATE_PREFERRED, | |
NDP_OPT_PI_VLIFETIME_INFINITE, | |
NDP_OPT_PI_PLIFETIME_INFINITE, 0); | |
} | |
static void send_broadcast(void) { | |
int sock; | |
sockaddr6_t sa_bcast; | |
char addr_str[IPV6_MAX_ADDR_STR_LEN]; | |
char buffer[] = "test"; | |
sa_bcast.sin6_family = AF_INET6; | |
sa_bcast.sin6_port = HTONS(12345); | |
ipv6_addr_set_all_nodes_addr(&sa_bcast.sin6_addr); | |
printf("sending to %s\n", inet_ntop(AF_INET6, &sa_bcast.sin6_addr, addr_str, IPV6_MAX_ADDR_STR_LEN)); | |
sock = destiny_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); | |
int bytes_send = destiny_socket_sendto(sock, buffer, sizeof buffer, 0, &sa_bcast, sizeof sa_bcast); | |
printf("send: %d bytes\n", bytes_send); | |
} | |
int main(void) { | |
init(); | |
send_broadcast(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment