ChamSys MagicQ User Manual User Manual

Page 271

Advertising
background image

MagicQ User Manual

242 / 355

\{

struct

sockaddr_in name;

char

opts[100];

socklen_t optlen = 100;

int

flags;

int

i;

// For Windows OS we need to start winsocket

#ifndef

LINUX

\{

WSAData ws;

int

code;

code = WSAStartup(MAKEWORD(1,1),&ws);

}

#endif

if

(remote_ether_sock)

\{

return

(TRUE);

}

remote_ether_sock = socket (PF_INET, SOCK_DGRAM, 0);

getsockopt (remote_ether_sock,SOL_SOCKET,SO_REUSEADDR, opts, &optlen);

opts[0] = 1;

setsockopt (remote_ether_sock,SOL_SOCKET,SO_REUSEADDR, opts, optlen);

/* Give the socket a name. */

name.sin_family = AF_INET;

name.sin_port = htons (REMOTE_ETHER_PORT);

name.sin_addr.s_addr = htonl (INADDR_ANY);

if

(bind (remote_ether_sock, (

struct

sockaddr *) &name,

sizeof

(name)) <

)

\{

closesocket(remote_ether_sock);

return

(FALSE);

}

getsockopt (remote_ether_sock,SOL_SOCKET,SO_BROADCAST, opts, &optlen);

opts[0] = 1;

setsockopt (remote_ether_sock,SOL_SOCKET,SO_BROADCAST, opts, optlen);

\{

u_long block;

block = 1;

ioctlsocket(remote_ether_sock,FIONBIO,&block);

}

return

TRUE;

}

int

remote_ether_rx(

char

*data, word16 size)

\{

char

message[MAX_CREP_MSG];

int

nbytes;

remote_ether_message_t *rem = (remote_ether_message_t *) message;

struct

sockaddr_in name;

int

name_len =

sizeof

(name);

if

(!remote_ether_sock)

return

(0);

nbytes = recvfrom (remote_ether_sock,

message,

MAX_CREP_MSG,

0,

(

struct

sockaddr *) &name,

&name_len);

if

(nbytes > 0)

\{

Advertising
This manual is related to the following products: