169
FINS/UDP Method Section 7-3
32 /*
33 bzero((char *) & s_addr,sizeof(ws_addr));
34 ws_addr.sin_family = AF_INET;
35 ws_addr.sin_addr.s_addr = htonl(INADDR_ANY);
36 ws_addr.sin_port = htons(0); /*
GET AVAILABLE PORT FOR LOCAL UDP PORT
*/
37 if (bind(sockfd,(struct sockaddr *)&ws_addr,sizeof(ws_addr)) < 0)
38 err_exit("can't bind local address");
39
40 /*
41 *
42 * (READ 150 WORDS FROM DM 100)
43 */
44 fins_cmnd[0] = 0x80; /* ICF */
45 fins_cmnd[1] = 0x00; /* RSV */
46 fins_cmnd[2] = 0x02; /* GCT */
47 fins_cmnd[3] = 0x00; /* DNA */
48 fins_cmnd[4] = 0x64; /* DA1 *//* Ethernet Unit FINS NODE NUMBER*/
49 fins_cmnd[5] = 0x00; /* DA2 */
50 fins_cmnd[6] = 0x00; /* SNA */
51 fins_cmnd[7] = 0x32; /* SA1 *//* WS FINS NODE NUMBER*/
52 fins_cmnd[8] = 0x00; /* SA2 */
53 fins_cmnd[9] = ++sid; /* SID */
54 fins_cmnd[10] = 0x01; /* MRC */
55 fins_cmnd[11] = 0x01; /* SRC */
56 fins_cmnd[12] =
0x82; /* VARIABLE TYPE: DM*/
57 fins_cmnd[13] = 0x00; /* READ START ADDRESS: DM 100*/
58 fins_cmnd[14] = 0x64;
59 fins_cmnd[15] = 0x00;
60 fins_cmnd[16] = 0x00; /* WORDS READ: 150*/
61 fins_cmnd[17] = 0x96;
62
63 /* SEND FINS COMMAND*/
64 bzero((char *) &cs_addr,sizeof(cs_addr));
65 cs_addr.sin_family = AF_INET;
66 cs_addr.sin_addr.s_addr = inet_addr(SERV_IP_ADDR);
67 cs_addr.sin_port = htons(FINS_UDP_PORT);
68
69 signal(SIGALRM,recv_fail);
70
71 CMND_SEND:
72 sendlen = 18;
73
74 if (sendto(sockfd,fins_cmnd,sendlen,0,&cs_addr,sizeof(cs_addr)) == sendlen)
75 {
76 alarm(RESP_TIMEOUT); /* START RESPONSE MONITOR TIMER*/
77 printf("send length %d¥n",sendlen);
78 }
79 else
80 {
81 err_exit("send error");
82 }
83
84
ALLOCATE IP ADDRESS AND PORT # TO SOCKET*/
GENERATE MEMORY AREA READ COMMAND