4 #include <sys/socket.h>
6 #include <netinet/in.h>
11 #include <sys/types.h>
22 #include <qstringlist.h>
25 #include <libconfig.h>
27 #define REMOTE_PATH "REMOTE"
31 #define CODEPORT1 3800
33 #define FILE_BUFFER_SIZE 2048
37 /*************** Interpreter slot ********************/
52 /********************* Network slot ********************/
73 for(i = 0; i < 5; i++)
78 code_transmit = FALSE;
81 /*********************** NET Module *****************************/
93 /* List of the Interpeter slots */
94 QList<INTlink> Interpreters;
95 /* List of the Network slots */
100 void load_config(char*);
101 void write_at_console(char*);
102 void send_to_kernel(MESSAGE*);
103 void sock_reopen(NETlink*);
104 void send_connect_info(NETlink*);
105 void send_accept_info(NETlink*);
106 void send_to_node(NETlink*, MESSAGE*);
107 void send_to_int(MESSAGE*);
108 void send_code_ack(NETlink*);
109 void send_to_all(MESSAGE *);
111 NETlink *findNETlink(int node);
112 INTlink *findINTlink(int id);
113 void transmit_file(int ton, char *fname, int fromINT);
114 void propagate_msg(MESSAGE *msg);
115 void check_node(int, int);
118 void exit_sequence();
119 void disconnect_seq();
120 void connect_seq(char*);
121 void accept_connection();
123 void remote_messages();
125 void get_message(NETlink*);
132 NETMOD::NETMOD(char *kernel_name)
137 struct sockaddr_in svr;
138 struct sockaddr_un svr1;
143 Interpreters.clear();
145 bzero(&svr, sizeof(svr));
146 listen_sock = socket(AF_INET, SOCK_STREAM, 0);
147 svr.sin_family = AF_INET;
148 svr.sin_addr.s_addr = INADDR_ANY;
149 svr.sin_port = htons(LOGPORT);
150 bind(listen_sock, (struct sockaddr*)&svr, sizeof(svr));
151 listen(listen_sock,5);
152 fcntl(listen_sock, F_SETFL, O_NONBLOCK | fcntl(listen_sock, F_GETFL,
156 all_connected = FALSE;
157 load_config("vlp.cfg");
159 kernel_sock = socket(AF_UNIX, SOCK_STREAM, 0);
160 bzero(&svr1, sizeof(svr1));
161 svr1.sun_family = AF_UNIX;
162 strcpy(svr1.sun_path, kernel_name);
163 strcpy(kername, kernel_name);
164 len = strlen(svr1.sun_path) + sizeof(svr1.sun_family);
165 i = connect(kernel_sock, (struct sockaddr*)&svr1, len);
167 fcntl(kernel_sock, F_SETFL, O_NONBLOCK|fcntl(kernel_sock, F_GETFL, 0));
169 setsockopt(kernel_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
171 m.msg_type = MSG_NET;
172 m.param.pword[0] = NET_NODE;
173 m.param.pword[1] = MyNode;
176 /* if (regme) regme_sequence();*/
178 if (to_connect > 0) {
179 write_at_console("Connecting remote VLPs...");
180 while (!all_connected) {
184 sprintf(s, "Local node number %d", MyNode);
188 /*##################### Load configuration ##########################*/
190 void NETMOD::load_config(char *fname)
193 config_setting_t *setting;
200 /* Hack for checking if file exists without using external libs.*/
201 FILE * file = fopen(fname, "rt");
203 fprintf(stderr, "Error: Cannot load configuration file %s!\n",
205 write_at_console("Cannot load configuration file!");
210 /* Read the file. If there is an error, report it and exit. */
211 if (!config_read(&cfg, file)) {
212 fprintf(stderr, "%s: In file %s, line %d\n",
213 config_error_text(&cfg),
214 config_error_file(&cfg),
215 config_error_line(&cfg));
216 config_destroy(&cfg);
218 /* from original code. */
222 setting = config_lookup(&cfg, "node_number");
224 MyNode = config_setting_get_int(setting);
227 if (!setting || MyNode == -1) {
228 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
229 "Error", fname, "node_number");
230 write_at_console("Node number must be specified");
231 config_destroy(&cfg);
236 setting = config_lookup(&cfg, "host");
239 pomlink = new NETlink;
241 switch(config_setting_type(setting)) {
242 /* TODO: Deprecated. Made for back compatibility. */
243 case CONFIG_TYPE_STRING:
244 strncpy(pomlink->addr,
245 config_setting_get_string(setting), 255);
247 case CONFIG_TYPE_ARRAY:
248 strncpy(pomlink->addr,
249 config_setting_get_string_elem(setting, 0),
253 fprintf(stderr, "%s! In file %s, bad entry type for %s."
254 " Will not be read.\n",
255 "Fatal error", fname, "host");
256 config_destroy(&cfg);
260 pomlink->connected = FALSE;
261 pomlink->sock = socket(AF_INET, SOCK_STREAM, 0);
262 fcntl(pomlink->sock, F_SETFL,O_NONBLOCK |
263 fcntl(pomlink->sock, F_GETFL, 0));
265 setsockopt(pomlink->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
267 Links.append(pomlink);
270 fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
271 "Warning", fname, "host");
274 config_destroy(&cfg);
278 all_connected = TRUE;
282 void NETMOD::write_at_console(char *s)
286 msg.msg_type = MSG_NET;
287 msg.param.pword[0] = NET_CSWRITELN;
288 strcpy(msg.param.pstr, s);
289 send_to_kernel(&msg);
292 void NETMOD::send_to_kernel(MESSAGE *msg)
294 write(kernel_sock, msg, sizeof(MESSAGE));
297 void NETMOD::send_to_node(NETlink *lnk, MESSAGE *msg)
299 msg->msg_type = MSG_NET;
300 /* msg2netmsg(msg);*/
302 write(lnk->sock, msg, sizeof(MESSAGE));
306 void NETMOD::send_to_int(MESSAGE *msg)
310 pomlink = findINTlink(msg->param.pword[5]);
311 if (pomlink != NULL) {
312 write(pomlink->sock, msg, sizeof(MESSAGE));
318 void NETMOD::accept_connection()
323 struct sockaddr_in svr;
326 struct timeval tout = {0, 0};
331 FD_SET(listen_sock, &rset);
333 if (select(listen_sock + 1, &rset, &wset, 0, (struct timeval *)&tout) >
335 if (FD_ISSET(listen_sock,&rset)) {
336 /* accept connection on listen socket */
338 bzero(&svr, sizeof(svr));
339 nsock = accept(listen_sock, (struct sockaddr*)&svr,
344 /* i<0 someone wants to connect us */
345 pomlink = new NETlink;
346 strcpy(pomlink->addr, inet_ntoa(svr.sin_addr));
347 pomlink->sock = nsock;
348 pomlink->connected = TRUE;
349 fcntl(pomlink->sock, F_SETFL, O_NONBLOCK |
350 fcntl(pomlink->sock, F_GETFL,0));
352 setsockopt(pomlink->sock, IPPROTO_TCP,
353 TCP_NODELAY, (char*)&on, sizeof(on));
354 Links.append(pomlink);
361 void NETMOD::check_node(int n, int sc)
366 m.msg_type = MSG_NET;
367 m.param.pword[0] = NET_NODE_EXIST;
369 pomlink = Links.first();
370 m.param.pword[1] = 0;
371 while (pomlink != NULL) {
372 if (pomlink->node_number == n) {
373 m.param.pword[1] = 1;
374 strcpy(m.param.pstr, pomlink->addr);
377 pomlink = Links.next();
379 write(sc, &m, sizeof(MESSAGE));
383 /************** Internal message from kernel or INT ********************/
385 void NETMOD::get_internal()
394 struct timeval tout={0, 0};
396 struct sockaddr_un svr;
400 FD_SET(kernel_sock, &readset);
403 pomlink = Interpreters.first();
404 while (pomlink != NULL) {
405 FD_SET(pomlink->sock, &readset);
406 if (nrset < pomlink->sock) {
407 nrset = pomlink->sock;
409 pomlink = Interpreters.next();
412 if (select(nrset + 1, &readset, &writeset, 0, (struct timeval *)&tout) >
415 /* Check request sockets */
416 pomlink = Interpreters.first();
417 while (pomlink != NULL) {
418 if (FD_ISSET(pomlink->sock, &readset)) {
419 nr = read(pomlink->sock, &msg, sizeof(MESSAGE));
421 if (msg.msg_type == MSG_NET) {
422 switch(msg.param.pword[0]) {
427 check_node(msg.param.pword[1], pomlink->sock);
430 conn_info(pomlink->sock);
433 msg.param.pword[0] = NET_NODES_NUM_RESPONSE;
434 msg.param.pword[1] = Links.count();
435 write(pomlink->sock, &msg, sizeof(MESSAGE));
441 pomlink=Interpreters.next();
444 /* Check internal socket */
445 if (FD_ISSET(kernel_sock,&readset)) {
446 nr = read(kernel_sock, &msg, sizeof(MESSAGE));
448 if (msg.msg_type == MSG_NET) {
449 switch(msg.param.pword[0]) {
450 case NET_TRANSMIT_CODE:
451 transmit_file(msg.param.pword[2],
460 conn_info(kernel_sock);
469 check_node(msg.param.pword[1], kernel_sock);
472 connect_seq(msg.param.pstr);
476 if (msg.msg_type == MSG_VLP) {
477 switch(msg.param.pword[0]) {
479 pomlink = new INTlink;
480 pomlink->sock = socket(AF_UNIX, SOCK_STREAM, 0);
481 bzero(&svr,sizeof(svr));
482 svr.sun_family = AF_UNIX;
483 strcpy(svr.sun_path, msg.param.pstr);
484 si = strlen(svr.sun_path) + sizeof(svr.sun_family);
485 sj = connect(pomlink->sock, (struct sockaddr*)&svr, si);
487 fcntl(pomlink->sock, F_SETFL, O_NONBLOCK | fcntl(pomlink->sock, F_GETFL, 0));
489 setsockopt(pomlink->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
490 pomlink->ID = msg.param.pword[1];
491 pomlink->connected=TRUE;
492 Interpreters.append(pomlink);
495 case VLP_INTERPRETER_DOWN: {
496 pomlink = findINTlink(msg.param.pword[1]);
497 if (pomlink != NULL) {
498 close(pomlink->sock);
499 Interpreters.remove(pomlink);
511 void NETMOD::get_message(NETlink *lnk)
521 struct sockaddr_in svr;
522 unsigned char buffer[FILE_BUFFER_SIZE];
525 if (lnk->connected) {
526 nr = read(lnk->sock, &msg, sizeof(MESSAGE));
528 /* netmsg2msg(&msg); */
529 if (msg.msg_type == MSG_NET) {
530 switch(msg.param.pword[0]) {
532 lnk->code_transmit = TRUE;
533 sprintf(pomstr, "%s/%s", REMOTE_PATH, msg.param.pstr);
534 strcat(pomstr,".ccd");
535 lnk->CodeFile = fopen(pomstr, "wb");
536 if (lnk->CodeFile == NULL) {
537 write_at_console("Cannot open file\n");
538 lnk->code_transmit = FALSE;
540 lnk->CodeSize = msg.param.pword[1];
541 psock = socket(AF_INET, SOCK_STREAM, 0);
542 bzero(&svr, sizeof(svr));
543 svr.sin_family = AF_INET;
544 svr.sin_port = htons(CODEPORT);
545 svr.sin_addr.s_addr = inet_addr(lnk->addr);
546 j = connect(psock, (struct sockaddr*)&svr, sizeof(svr));
548 /*fcntl(psock, F_SETFL,O_NONBLOCK | fcntl(psock, F_GETFL,0));*/
550 while (sz < lnk->CodeSize) {
551 rd = read(psock, &buffer, sizeof(buffer));
552 rdbt = fwrite(&buffer, sizeof(unsigned char), rd, lnk->CodeFile);
556 fclose(lnk->CodeFile);
560 lnk->code_transmit = TRUE;
561 sprintf(pomstr, "%s/%s", REMOTE_PATH, msg.param.pstr);
562 strcat(pomstr, ".pcd");
563 lnk->CodeFile = fopen(pomstr, "wb");
564 if (lnk->CodeFile == NULL) {
565 write_at_console("Cannot open file\n");
566 lnk->code_transmit = FALSE;
568 lnk->CodeSize = msg.param.pword[1];
569 psock = socket(AF_INET, SOCK_STREAM, 0);
570 bzero(&svr, sizeof(svr));
571 svr.sin_family = AF_INET;
572 svr.sin_port = htons(CODEPORT1);
573 svr.sin_addr.s_addr = inet_addr(lnk->addr);
574 j = connect(psock, (struct sockaddr*)&svr, sizeof(svr));
576 /*fcntl(psock, F_SETFL,O_NONBLOCK | fcntl(psock, F_GETFL,0));*/
578 while (sz < lnk->CodeSize) {
579 rd = read(psock, &proto, sizeof(proto));
580 rdbt = fwrite(&proto, sizeof(unsigned char), rd, lnk->CodeFile);
584 fclose(lnk->CodeFile);
588 sprintf(pomstr, "Node: %d Addr: %s",
589 msg.param.pword[1], lnk->addr);
590 lnk->node_number = msg.param.pword[1];
591 write_at_console(pomstr);
592 send_accept_info(lnk);
595 sprintf(pomstr, "Node: %d Addr: %s",
596 msg.param.pword[1], lnk->addr);
597 lnk->node_number = msg.param.pword[1];
598 write_at_console(pomstr);
601 sprintf(pomstr,"Node: %d disconnected",
603 write_at_console(pomstr);
609 if (msg.param.pword[1] == MSG_VLP) {
610 send_to_kernel(&msg);
611 } else if (msg.param.pword[1] == MSG_INT) {
624 void NETMOD::remote_messages()
628 struct timeval tout={0, 0};
635 pomlink = Links.first();
636 while (pomlink != NULL) {
637 if (pomlink->connected) {
638 FD_SET(pomlink->sock, &rset);
639 if (max < pomlink->sock){
643 pomlink=Links.next();
646 if (select(max + 1, &rset, &wset, 0, (struct timeval *)&tout) > 0) {
647 pomlink=Links.first();
648 while (pomlink!=NULL) {
649 if (FD_ISSET(pomlink->sock,&rset)) {
650 get_message(pomlink);
652 pomlink=Links.next();
657 /******************************2010********************************************/
658 void NETMOD::doitall() {
660 int nsock,max = 0, on, nr, si, sj;
661 struct sockaddr_in svr;
665 struct sockaddr_un svr2;
669 FD_SET(listen_sock, &rset);
671 FD_SET(kernel_sock, &rset);
672 if (max < kernel_sock) {
675 pomlink2 = Interpreters.first();
676 while (pomlink2 != NULL) {
677 FD_SET(pomlink2->sock, &rset);
678 if (max < pomlink2->sock) {
681 pomlink2 = Interpreters.next();
683 pomlink = Links.first();
684 while (pomlink != NULL) {
685 if (pomlink->connected) {
686 FD_SET(pomlink->sock, &rset);
687 if (max < pomlink->sock) {
691 pomlink=Links.next();
695 if (select(max + 1, &rset, 0, 0, NULL) > 0) {
696 /* accept connection */
697 if (FD_ISSET(listen_sock,&rset)) {
698 /* accept connection on listen socket */
700 bzero(&svr, sizeof(svr));
701 nsock = accept(listen_sock, (struct sockaddr*)&svr, &sz);
703 pomlink = new NETlink;
704 strcpy(pomlink->addr, inet_ntoa(svr.sin_addr));
705 pomlink->sock = nsock;
706 pomlink->connected = TRUE;
707 fcntl(pomlink->sock, F_SETFL,O_NONBLOCK |
708 fcntl(pomlink->sock, F_GETFL, 0));
710 setsockopt(pomlink->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
711 Links.append(pomlink);
715 /* get internal message*/
716 /* Check request sockets */
717 pomlink2 = Interpreters.first();
718 while (pomlink2 != NULL) {
719 if (FD_ISSET(pomlink2->sock,&rset)) {
720 nr = read(pomlink2->sock, &msg, sizeof(MESSAGE));
722 if (msg.msg_type == MSG_NET) {
723 switch(msg.param.pword[0]) {
728 check_node(msg.param.pword[1], pomlink2->sock);
731 conn_info(pomlink2->sock);
734 msg.param.pword[0] = NET_NODES_NUM_RESPONSE;
735 msg.param.pword[1] = Links.count();
736 write(pomlink2->sock, &msg, sizeof(MESSAGE));
742 pomlink2 = Interpreters.next();
745 /* Check internal socket */
746 if (FD_ISSET(kernel_sock, &rset)) {
747 nr = read(kernel_sock, &msg, sizeof(MESSAGE));
749 if (msg.msg_type == MSG_NET) {
750 switch(msg.param.pword[0]) {
751 case NET_TRANSMIT_CODE:
752 transmit_file(msg.param.pword[2], msg.param.pstr, msg.param.pword[1]);
759 conn_info(kernel_sock);
768 check_node(msg.param.pword[1], kernel_sock);
771 connect_seq(msg.param.pstr);
774 if (msg.msg_type == MSG_VLP) {
775 switch(msg.param.pword[0]) {
777 pomlink2 = new INTlink;
778 pomlink2->sock = socket(AF_UNIX, SOCK_STREAM, 0);
779 bzero(&svr2, sizeof(svr2));
780 svr2.sun_family = AF_UNIX;
781 strcpy(svr2.sun_path, msg.param.pstr);
782 si = strlen(svr2.sun_path) + sizeof(svr2.sun_family);
783 sj = connect(pomlink2->sock,(struct sockaddr*)&svr2, si);
785 fcntl(pomlink2->sock,F_SETFL, O_NONBLOCK | fcntl(pomlink2->sock, F_GETFL, 0));
787 setsockopt(pomlink2->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
788 pomlink2->ID = msg.param.pword[1];
789 pomlink2->connected = TRUE;
790 Interpreters.append(pomlink2);
793 case VLP_INTERPRETER_DOWN: {
794 pomlink2 = findINTlink(msg.param.pword[1]);
795 if (pomlink2 != NULL) {
796 close(pomlink2->sock);
797 Interpreters.remove(pomlink2);
806 /* get remote message*/
808 pomlink=Links.first();
809 while (pomlink != NULL) {
810 if (FD_ISSET(pomlink->sock, &rset))
811 get_message(pomlink);
812 pomlink=Links.next();
816 /****************************** END 2010 **************************************/
820 void NETMOD::propagate_msg(MESSAGE *msg)
825 pomlink = findNETlink(msg->param.pword[4]);
826 if ((pomlink != NULL) && (pomlink->connected))
827 send_to_node(pomlink,msg);
829 if (msg->param.pword[1] == MSG_INT) {
832 sprintf(ss, "Not connected to Node %d",
833 msg->param.pword[4]);
834 write_at_console(ss);
839 void NETMOD::connect_seq(char *a)
842 struct sockaddr_in svr;
846 while (pom != NULL) {
847 if (strcmp(pom->addr, a) == 0)
852 strcpy(pom->addr, a);
853 pom->connected = FALSE;
854 pom->sock = socket(AF_INET, SOCK_STREAM, 0);
855 bzero(&svr, sizeof(svr));
856 svr.sin_family = AF_INET;
857 svr.sin_port = htons(LOGPORT);
858 svr.sin_addr.s_addr = inet_addr(pom->addr);
859 j = connect(pom->sock, (struct sockaddr*)&svr, sizeof(svr));
861 pom->connected = TRUE;
862 fcntl(pom->sock, F_SETFL, O_NONBLOCK | fcntl(pom->sock, F_GETFL,
865 setsockopt(pom->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
867 send_connect_info(pom);
870 write_at_console("Connection failed");
874 void NETMOD::check_links()
877 struct sockaddr_in svr;
880 /* connect to all other nodes */
881 if (!all_connected) {
882 pomlink = Links.first();
883 while (pomlink != NULL) {
884 if (!(pomlink->connected)) {
885 bzero(&svr, sizeof(svr));
886 svr.sin_family = AF_INET;
887 svr.sin_port = htons(LOGPORT);
888 svr.sin_addr.s_addr = inet_addr(pomlink->addr);
890 j = connect(pomlink->sock,
891 (struct sockaddr*)&svr, sizeof(svr));
893 pomlink->connected = TRUE;
894 fcntl(pomlink->sock, F_SETFL, O_NONBLOCK
895 | fcntl(pomlink->sock, F_GETFL,
897 send_connect_info(pomlink);
899 if (errno == ECONNREFUSED) {
900 sock_reopen(pomlink);
902 } /* not connected */
903 pomlink = Links.next();
906 all_connected = TRUE;
907 pomlink = Links.first();
908 while(pomlink != NULL) {
909 if (pomlink->connected == FALSE) {
910 all_connected = FALSE;
913 pomlink = Links.next();
917 void NETMOD::sock_reopen(NETlink *lnk)
922 lnk->sock = socket(AF_INET, SOCK_STREAM, 0);
923 fcntl(lnk->sock, F_SETFL,O_NONBLOCK | fcntl(lnk->sock, F_GETFL, 0));
924 setsockopt(lnk->sock, IPPROTO_TCP,TCP_NODELAY, (char*)&on, sizeof(on));
927 /***************** Acknowledges **************************/
929 void NETMOD::send_connect_info(NETlink *lnk)
933 m.param.pword[0] = NET_CONNECT;
934 m.param.pword[1] = MyNode;
935 m.msg_type = MSG_NET;
938 write(lnk->sock, &m, sizeof(MESSAGE));
941 void NETMOD::send_accept_info(NETlink *lnk)
945 m.param.pword[0] = NET_ACCEPT;
946 m.param.pword[1] = MyNode;
947 m.msg_type = MSG_NET;
950 write(lnk->sock, &m, sizeof(MESSAGE));
953 void NETMOD::send_code_ack(NETlink *lnk)
957 m.param.pword[0] = NET_CODESTREAM_OK;
958 m.msg_type = MSG_NET;
961 write(lnk->sock, &m, sizeof(MESSAGE));
964 void NETMOD::send_to_all(MESSAGE *msg)
967 pomlink = Links.first();
968 while (pomlink != NULL) {
969 write(pomlink->sock, msg, sizeof(MESSAGE));
970 pomlink = Links.next();
987 void NETMOD::exit_sequence()
991 ::close(kernel_sock);
992 ::close(listen_sock);
994 pomlink = Links.first();
995 while (pomlink != NULL) {
996 ::close(pomlink->sock);
997 pomlink = Links.next();
1002 void NETMOD::disconnect_seq()
1007 bzero(&m, sizeof(MESSAGE));
1008 m.msg_type = MSG_NET;
1009 m.param.pword[0] = NET_DISCONNECT;
1010 m.param.pword[1] = MyNode;
1014 send_to_node(p, &m);
1025 NETlink *NETMOD::findNETlink(int node)
1028 pomlink = Links.first();
1029 while(pomlink != NULL) {
1030 if (pomlink->node_number == node)
1033 pomlink = Links.next();
1038 INTlink *NETMOD::findINTlink(int id)
1041 pomlink = Interpreters.first();
1042 while(pomlink != NULL) {
1043 if (pomlink->ID == id)
1045 pomlink = Interpreters.next();
1051 /* ---------------- Sending code to a remote node -------------- */
1053 void NETMOD::transmit_file(int ton, char *fname, int fromINT)
1059 unsigned char buffer[FILE_BUFFER_SIZE];
1064 struct sockaddr_in svr;
1068 /***************** CCD FILE*/
1071 f = fopen(fn, "rb");
1073 fseek(f, 0, SEEK_END);
1074 msg.param.pword[1] = ftell(f);
1076 f = fopen(fn, "rb");
1078 strcpy(b, rindex(fname, '/'));
1079 for(i = 0; i < strlen(b); i++)
1082 msg.param.pword[0] = NET_CCD_START;
1083 strcpy(msg.param.pstr, b);
1085 outlink = findNETlink(ton);
1086 if (outlink == NULL)
1088 bzero(&svr, sizeof(svr));
1089 sock = socket(AF_INET, SOCK_STREAM, 0);
1090 svr.sin_family = AF_INET;
1091 svr.sin_addr.s_addr = INADDR_ANY;
1092 svr.sin_port = htons(CODEPORT);
1093 bind(sock, (struct sockaddr*)&svr, sizeof(svr));
1095 send_to_node(outlink, &msg);
1099 FD_SET(sock, &rset);
1100 if (select(sock + 1, &rset, &wset, 0, 0))
1101 if (FD_ISSET(sock,&rset))
1102 tsock = accept(sock, (struct sockaddr*)&svr,
1107 i = fread(&buffer, 1, sizeof(buffer), f);
1108 write(tsock, &buffer, i);
1111 FD_SET(tsock, &wset);
1112 select(tsock + 1, &rset, &wset, 0, 0);
1119 sprintf(b, "Cannot open file to send %s\n", fname);
1120 write_at_console(b);
1124 /**************** PCD FILE */
1130 fseek(f, 0, SEEK_END);
1131 msg.param.pword[1] = ftell(f);
1133 f = fopen(fn, "rb");
1135 strcpy(b, rindex(fname, '/'));
1136 for(i = 0; i < strlen(b); i++)
1138 msg.param.pword[0] = NET_PCD_START;
1139 strcpy(msg.param.pstr, b);
1141 outlink = findNETlink(ton);
1142 if (outlink == NULL)
1144 bzero(&svr, sizeof(svr));
1145 sock = socket(AF_INET, SOCK_STREAM, 0);
1146 svr.sin_family = AF_INET;
1147 svr.sin_addr.s_addr = INADDR_ANY;
1148 svr.sin_port = htons(CODEPORT1);
1149 bind(sock, (struct sockaddr*)&svr, sizeof(svr));
1151 send_to_node(outlink, &msg);
1155 FD_SET(sock, &rset);
1156 if (select(sock + 1, &rset, &wset, 0, 0))
1157 if (FD_ISSET(sock, &rset))
1158 tsock = accept(sock, (struct sockaddr*)&svr,
1163 i = fread(&proto, 1, sizeof(proto), f);
1164 write(tsock, &proto, i);
1167 FD_SET(tsock, &wset);
1168 select(tsock + 1, &rset, &wset, 0, 0);
1175 sprintf(b, "Cannot open file to send %s\n", fname);
1176 write_at_console(b);
1179 msg.msg_type = MSG_NET;
1180 msg.param.pword[0] = NET_TRANSMITTED;
1181 msg.param.pword[1] = fromINT;
1182 send_to_kernel(&msg);
1185 void NETMOD::conn_info(int sk)
1192 m.msg_type = MSG_NET;
1193 m.param.pword[0] = NET_INFO;
1194 strcpy(m.param.pstr, "");
1195 pom = Links.first();
1196 while (pom != NULL) {
1197 sprintf(poms, "%d=%s;", pom->node_number, pom->addr);
1198 strcat(m.param.pstr, poms);
1201 m.param.pword[1] = 12;
1202 write(sk, &m, sizeof(MESSAGE));
1208 m.param.pword[1] = k;
1209 write(sk, &m, sizeof(MESSAGE));
1211 m.msg_type = MSG_NET;
1212 m.param.pword[0] = NET_INFO_END;
1213 write(sk, &m, sizeof(MESSAGE));
1216 int main(int argc,char **argv)
1218 NETMOD netter(argv[1]);