Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom network ports #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions artnet/artnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ artnet_node artnet_new(const char *ip, int verbose) {
n->state.report_code = ARTNET_RCPOWEROK;
n->state.reply_addr.s_addr = 0;
n->state.mode = ARTNET_STANDBY;
n->receive_port = ARTNET_PORT;
n->send_port = ARTNET_PORT;

// set all ports to MERGE HTP mode and disable
for (i=0; i < ARTNET_MAX_PORTS; i++) {
Expand Down Expand Up @@ -220,6 +222,11 @@ int artnet_destroy(artnet_node vn) {
return ARTNET_EOK;
}

void artnet_set_network_ports(artnet_node vn, uint16_t receive_port, uint16_t send_port) {
node n = (node)vn;
n->receive_port = receive_port;
n->send_port = send_port;
}

/*
* Set the OEM code
Expand Down
5 changes: 5 additions & 0 deletions artnet/artnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ EXTERN int artnet_start(artnet_node n);
EXTERN int artnet_read(artnet_node n, int timeout);
EXTERN int artnet_stop(artnet_node n);
EXTERN int artnet_destroy(artnet_node n);
// Changes the network ports used by the node. This function is useful for debugging
// (it makes it possible to run multiple devices on the same computer), but must not
// be used in production, because the network port is fixed by the spec.
// Must be called before artnet_start().
EXTERN void artnet_set_network_ports(artnet_node n, uint16_t receive_port, uint16_t send_port);

int artnet_join(artnet_node vn1, artnet_node vn2);

Expand Down
11 changes: 7 additions & 4 deletions artnet/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ int artnet_net_start(node n) {

memset(&servAddr, 0x00, sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_port = htons(ARTNET_PORT);
servAddr.sin_port = htons(n->receive_port);
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);

if (n->state.verbose)
Expand Down Expand Up @@ -628,8 +628,11 @@ int artnet_net_recv(node n, artnet_packet p, int delay) {
return ARTNET_ENET;
}

if (cliAddr.sin_addr.s_addr == n->state.ip_addr.s_addr ||
ntohl(cliAddr.sin_addr.s_addr) == LOOPBACK_IP) {
// Prevent receiving our own messages, except if using non-standard ports,
// in which case the user is running several nodes on the same machine for debugging.
if ((cliAddr.sin_addr.s_addr == n->state.ip_addr.s_addr ||
ntohl(cliAddr.sin_addr.s_addr) == LOOPBACK_IP) &&
n->send_port == n->receive_port ) {
p->length = 0;
return ARTNET_EOK;
}
Expand All @@ -652,7 +655,7 @@ int artnet_net_send(node n, artnet_packet p) {
return ARTNET_EACTION;

addr.sin_family = AF_INET;
addr.sin_port = htons(ARTNET_PORT);
addr.sin_port = htons(n->send_port);
addr.sin_addr = p->to;
p->from = n->state.ip_addr;

Expand Down
2 changes: 2 additions & 0 deletions artnet/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ typedef struct artnet_node_s{
node_list_t node_list; // node list
firmware_transfer_t firmware; // firmware details
node_peering_t peering; // peer if we've joined a group
uint16_t receive_port; // The network port on which we receive data.
uint16_t send_port; // The network port on which we send data.
} artnet_node_t;


Expand Down
2 changes: 1 addition & 1 deletion artnet/transmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ int artnet_tx_build_art_poll_reply(node n) {
memcpy(&ar->id, ARTNET_STRING, ARTNET_STRING_SIZE);
ar->opCode = htols(ARTNET_REPLY);
memcpy(&ar->ip, &n->state.ip_addr.s_addr, 4);
ar->port = htols(ARTNET_PORT);
ar->port = htols(n->send_port);
ar->verH = 0;
ar->ver = 0;
ar->subH = 0;
Expand Down