Chamsys MagicQ User Manual Uživatelský manuál Strana 271

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 384
  • Tabulka s obsahem
  • ŘEŠENÍ PROBLÉMŮ
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 270
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)
\{
Zobrazit stránku 270
1 2 ... 266 267 268 269 270 271 272 273 274 275 276 ... 383 384

Komentáře k této Příručce

Žádné komentáře