- Timestamp:
- Mar 9, 2006, 8:27:14 PM (17 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/build-kernel
r573 r575 34 34 35 35 # For further development: create floppy images using the kernel 36 #gcc -traditional -c -o bootsect.obootsect.S37 #ld -Ttext 0x0 -s --oformat binary bootsect.o -o cacafire.img36 gcc -traditional -c -o bootsect.o /usr/src/linux/arch/i386/boot/bootsect.S 37 ld -Ttext 0x0 -s --oformat binary bootsect.o -o cacafire.img 38 38 -
libcaca/trunk/caca/driver_network.c
r560 r575 26 26 #include <sys/socket.h> 27 27 #include <arpa/inet.h> 28 #include <fcntl.h> 28 29 #include <string.h> 29 30 … … 50 51 int clilen; 51 52 char buffer[256]; 53 54 int client_count; 55 int *fd_list; 56 52 57 }; 53 58 … … 70 75 { 71 76 int yes=1; 77 72 78 printf("Initing network stack.\n"); 73 79 74 80 kk->drv.p = malloc(sizeof(struct driver_private)); 75 81 if(kk->drv.p == NULL) 82 return -1; 76 83 77 84 kk->drv.p->width = 80; 78 85 kk->drv.p->height = 24; 79 86 kk->drv.p->port = 7575; // 75 75 decimal ASCII -> KK // FIXME, sadly 87 kk->drv.p->client_count = 0; 88 kk->drv.p->fd_list = NULL; 89 80 90 81 91 … … 93 103 return -1; 94 104 } 95 96 105 97 106 kk->drv.p->my_addr.sin_family = AF_INET; … … 106 115 return -1; 107 116 } 117 118 /* Non blocking socket */ 119 fcntl(kk->drv.p->sockfd, F_SETFL, O_NONBLOCK); 120 121 108 122 printf("listen\n"); 109 123 if (listen(kk->drv.p->sockfd, BACKLOG) == -1) { … … 112 126 } 113 127 114 printf("accept\n"); 128 printf("network ok.\n"); 129 130 return 0; 131 } 132 133 static int network_end_graphics(caca_t *kk) 134 { 135 int i; 136 for(i = 0; i < kk->drv.p->client_count; i++) { 137 close(kk->drv.p->fd_list[i]); 138 } 139 return 0; 140 } 141 142 static int network_set_window_title(caca_t *kk, char const *title) 143 { 144 /* Not handled (yet)*/ 145 return 0; 146 } 147 148 static unsigned int network_get_window_width(caca_t *kk) 149 { 150 return kk->drv.p->width * 6; 151 } 152 153 static unsigned int network_get_window_height(caca_t *kk) 154 { 155 return kk->drv.p->height * 10; 156 } 157 158 static void network_display(caca_t *kk) 159 { 160 int size, i; 161 char *to_send = cucul_get_ansi(kk->qq, 0, &size);; 162 115 163 kk->drv.p->clilen = sizeof(kk->drv.p->remote_addr); 116 164 kk->drv.p->new_fd = accept(kk->drv.p->sockfd, (struct sockaddr *) &kk->drv.p->remote_addr, &kk->drv.p->clilen); 117 if (kk->drv.p->new_fd < 0) { 118 perror("ERROR on accept"); 119 return -1; 120 } 121 122 123 printf("Got connexion from %d.%d.%d.%d\n", 124 (unsigned int)((kk->drv.p->remote_addr.sin_addr.s_addr)&0x000000FF), 125 (unsigned int)((kk->drv.p->remote_addr.sin_addr.s_addr)&0x0000FF00)>>8, 126 (unsigned int)((kk->drv.p->remote_addr.sin_addr.s_addr)&0x00FF0000)>>16, 127 (unsigned int)((kk->drv.p->remote_addr.sin_addr.s_addr)&0xFF000000)>>24); 165 if(kk->drv.p->new_fd != -1) 166 { 167 168 if(kk->drv.p->fd_list == NULL) { 169 kk->drv.p->fd_list = malloc(sizeof(int)); 170 if(kk->drv.p->fd_list == NULL) 171 return; 172 kk->drv.p->fd_list[kk->drv.p->client_count] = kk->drv.p->new_fd; 173 } else { 174 kk->drv.p->fd_list = realloc(kk->drv.p->fd_list, (kk->drv.p->client_count+1) * sizeof(int)); 175 kk->drv.p->fd_list[kk->drv.p->client_count] = kk->drv.p->new_fd; 176 } 177 178 kk->drv.p->client_count++; 179 180 } 181 182 for(i = 0; i < kk->drv.p->client_count; i++) { 183 if(kk->drv.p->fd_list[i] == -1) 184 continue; 185 186 /* FIXME, handle >255 sizes */ 187 codes[16] = (unsigned char) kk->drv.p->width&0xff; 188 codes[18] = (unsigned char) kk->drv.p->height&0xff; 189 190 /* Send basic telnet codes */ 191 if (send(kk->drv.p->fd_list[i], codes,sizeof(codes) , 0) == -1) { 192 kk->drv.p->fd_list[i] = -1; 193 } 194 195 /* ANSI code for move(0,0)*/ 196 if (send(kk->drv.p->fd_list[i], "\033[1,1H", 6, 0) == -1) { 197 kk->drv.p->fd_list[i] = -1; 198 } 199 200 if (send(kk->drv.p->fd_list[i], to_send, size, 0) == -1) { 201 kk->drv.p->fd_list[i] = -1; 202 } 203 } 128 204 129 /* FIXME, handle >255 sizes */130 codes[16] = (unsigned char) kk->drv.p->width&0xff;131 codes[18] = (unsigned char) kk->drv.p->height&0xff;132 133 /* Send basic telnet codes */134 if (send(kk->drv.p->new_fd, codes,sizeof(codes) , 0) == -1) {135 perror("send");136 return -1;137 }138 139 printf("network ok.\n");140 141 return 0;142 }143 144 static int network_end_graphics(caca_t *kk)145 {146 printf("network end graphics\n");147 return 0;148 }149 150 static int network_set_window_title(caca_t *kk, char const *title)151 {152 printf("network_set_window_title(%s) not implemented yet.\n", title);153 return 0;154 }155 156 static unsigned int network_get_window_width(caca_t *kk)157 {158 return kk->drv.p->width * 6;159 }160 161 static unsigned int network_get_window_height(caca_t *kk)162 {163 return kk->drv.p->height * 10;164 }165 166 static void network_display(caca_t *kk)167 {168 int size;169 char *to_send = cucul_get_ansi(kk->qq, 0, &size);;170 171 172 /* ANSI code for move(0,0)*/173 if (send(kk->drv.p->new_fd, "\033[1,1H", 6, 0) == -1) {174 perror("send");175 return;176 }177 178 if (send(kk->drv.p->new_fd, to_send, size, 0) == -1) {179 perror("send");180 return;181 }182 183 205 } 184 206 static void network_handle_resize(caca_t *kk) 185 207 { 186 printf("Resize\n"); 187 208 /* Not handled */ 188 209 } 189 210 190 211 static unsigned int network_get_event(caca_t *kk) 191 212 { 213 /* Not handled */ 192 214 return 0; 193 215 } … … 213 235 214 236 #endif // USE_NETWORK 237
Note: See TracChangeset
for help on using the changeset viewer.