Omron CJ1W-ETN21 Network Card User Manual


 
187
FINS/TCP Method Section 7-4
33
34 /*
35 bzero((char *) &ws_addr,sizeof(ws_addr));
36 ws_addr.sin_family = AF_INET;
37 ws_addr.sin_addr.s_addr = htonl(INADDR_ANY);
38 ws_addr.sin_port = htons(0); /*
39
40 if (bind(sockfd,(struct sockaddr *)&ws_addr,sizeof(ws_addr)) < 0)
41 err_exit(“can’t bind local address”);
42
43 /* ESTABLISH CONNECTION WITH FINS/TCP SERVER*/
44 bzero((char *) &cs_addr,sizeof(cs_addr));
45 cs_addr.sin_family = AF_INET;
46 cs_addr.sin_addr.s_addr = inet_addr(SERV_IP_ADDR);
47 cs_addr.sin_port = htons(FINS_TCP_PORT);
48
49 if (connect(sockfd,(struct sockaddr *)&cs_addr,sizeof(cs_addr)) < 0)
50 err_exit(“can’t connect to FINS/TCP server”);
51
52
53 /* SEND FINS/TCP COMMAND*/
54 /*
55 * GENERATE FINS NODE NUMBER DATA SEND COMMAND (CLIENT TO SERVER)
56 */
57 fins_tcp_header[0] = ‘F’; /* Header */
58 fins_tcp_header[1] = ‘I’;
59 fins_tcp_header[2] = ‘N’;
60 fins_tcp_header[3] = ‘S’;
61 fins_tcp_header[4] = 0x00; /* Length */
62 fins_tcp_header[5] = 0x00;
63 fins_tcp_header[6] = 0x00;
64 fins_tcp_header[7] = 0x0C;
65 fins_tcp_header[8] = 0x00; /* Command */
66 fins_tcp_header[9] = 0x00;
67 fins_tcp_header[10] = 0x00;
68 fins_tcp_header[11] = 0x00;
69 fins_tcp_header[12] = 0x00; /* Error Code */
70 fins_tcp_header[13] = 0x00;
71 fins_tcp_header[14] = 0x00;
72 fins_tcp_header[15] = 0x00;
73 fins_tcp_header[17] = 0x00; /* Client Node Add */
74 fins_tcp_header[18] = 0x00;
75 fins_tcp_header[19] = 0x00;
76 fins_tcp_header[20] = 0x00; /*
77
78 /*
79 sendlen = 20;
80
81 if (send(sockfd,fins_tcp_header,sendlen,0) == sendlen)
82 {
83 alarm(RESP_TIMEOUT); /*
84 printf(“FINS/TCP header send length %d¥n”,sendlen);
85 }
ALLOCATE IP ADDRESS AND PORT # TO SOCKET*/
ASSIGN LOCAL TCP PORT NUMBER
AUTOMATICALLY GET FINS CLIENT FINS NODE NUMBER*/
START RESPONSE MONITOR TIMER*/
SEND FINS/TCP COMMAND*/