154 Chapter 3
Programming Examples
Using C Programming Over Socket LAN
memcpy(&peeraddr_in.sin_addr.s_addr, hostPtr->h_addr, hostPtr->h_length);
peeraddr_in.sin_family = AF_INET;
peeraddr_in.sin_port = htons((unsigned short)portNumber);
if (connect(s, (const struct sockaddr*)&peeraddr_in,
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{
fprintf(stderr,"unable to create socket to ’%s’: %s\n",
hostname, strerror(errno));
return INVALID_SOCKET;
}
return s;
}
/***************************************************************************
*
> $Function: commandInstrument$
*
* $Description: send a SCPI command to the instrument.$
*
* $Parameters: $
* (FILE *) . . . . . . . . . file pointer associated with TCP/IP socket.
* (const char *command) . . SCPI command string.
* $Return: (char *) . . . . . . a pointer to the result string.
*
* $Errors: returns 0 if send fails $
*
***************************************************************************/
int commandInstrument(SOCKET sock,
const char *command)
{
int count;