Proxima ASA 7911, 7910 manual 40 hp= gethostbynameargv1 41 if hp==0, server.sinport= htonsatoiargv2

Models: 7911 7910

1 127
Download 127 pages 54.08 Kb
Page 101
Image 101
40hp= gethostbyname(argv[1]);

40hp= gethostbyname(argv[1]);

41if (hp==0) {

42fprintf(stderr, “%s: Unknown host\n”, argv[1]);

43exit(2);

44}

45memcpy( (char *)&server.sin_addr, (char *)hp->h_addr, hp-h_length);

46server.sin_port= htons(atoi(argv[2]));

47

48/* Use the connect() socket call to initiate a TCP connection with

49the remote machine. */

50printf(“Connecting...\n”);

51if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0 ) {

52perror(“Connecting stream socket”);

53exit(1);

54}

55printf(“Connected.\n”);

56

57/* Construct message, including Serial Adapter header bytes */

58buf[0]= DATA1;

59buf[3]= 0xf0;

60dataLength= strlen(DATA);

61memcpy(&buf[1], &(htons(dataLength)), sizeof(short));

62strcpy(&buf[4], DATA);

63printf(“%s\n”, &buf[4]);

64

65/* Send message */

66if(write (sock, buf, dataLength+4) < 0)

67perror(“Sending stream message”);

69/* Send $QUIT string to the serial adapter to tell it to close its

70side of the TCP connection. */

71dataLength= 5;

72memcpy(&buf[1], &(htons(dataLength)), sizeof(short));

73memcpy(&buf[4], “$QUIT”, 5);

74if(write (sock, buf, dataLength+4) < 0)

75perror(“Sending $QUIT message”);

77close(sock);

78exit(0);

80}

95

Page 101
Image 101
Proxima ASA 7911, 7910 manual 40 hp= gethostbynameargv1 41 if hp==0, fprintfstderr, “%s Unknown host\n”, argv1 43 exit2