Changeset f4f866c in mainline for uspace/app
- Timestamp:
- 2010-04-23T21:42:26Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6c39a907
- Parents:
- 38aaacc2 (diff), 80badbe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 13 added
- 8 deleted
- 21 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/exec.c
r38aaacc2 rf4f866c 40 40 #include <str.h> 41 41 #include <fcntl.h> 42 #include <str_error.h> 42 43 43 44 #include "config.h" … … 120 121 free(found); 121 122 122 tid = task_spawn(tmp, (const char **) argv );123 tid = task_spawn(tmp, (const char **) argv, &retval); 123 124 free(tmp); 124 125 125 126 if (tid == 0) { 126 cli_error(CL_EEXEC, "Cannot spawn `%s'.", cmd); 127 cli_error(CL_EEXEC, "%s: Cannot spawn `%s' (%s)", progname, cmd, 128 str_error(retval)); 127 129 return 1; 128 130 } … … 130 132 task_wait(tid, &texit, &retval); 131 133 if (texit != TASK_EXIT_NORMAL) { 132 printf(" Command failed (unexpectedly terminated).\n");134 printf("%s: Command failed (unexpectedly terminated)\n", progname); 133 135 } else if (retval != 0) { 134 printf("Command failed (return value %d).\n", retval); 136 printf("%s: Command failed (%s)\n", 137 progname, str_error(retval)); 135 138 } 136 139 -
uspace/app/bdsh/scli.h
r38aaacc2 rf4f866c 13 13 } cliuser_t; 14 14 15 extern const char *progname; 16 15 17 #endif -
uspace/app/dummy_load/Makefile
r38aaacc2 rf4f866c 29 29 30 30 USPACE_PREFIX = ../.. 31 EXTRA_CFLAGS = -Iinclude -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include 32 LIBRARY = libnetif 31 # BINARY = dummy_load 33 32 34 33 SOURCES = \ 35 generic/netif_remote.c 34 dummy_load.c \ 35 input.c 36 36 37 37 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/edit/edit.c
r38aaacc2 rf4f866c 40 40 #include <vfs/vfs.h> 41 41 #include <io/console.h> 42 #include <io/ color.h>42 #include <io/style.h> 43 43 #include <io/keycode.h> 44 44 #include <errno.h> … … 100 100 static bool cursor_visible; 101 101 102 static int scr_rows, scr_columns; 102 static ipcarg_t scr_rows; 103 static ipcarg_t scr_columns; 103 104 104 105 #define ROW_BUF_SIZE 4096 … … 505 506 asprintf(&str, "%s: %s", prompt, init_value); 506 507 status_display(str); 507 console_ goto(con, 1 + str_length(str), scr_rows - 1);508 console_set_pos(con, 1 + str_length(str), scr_rows - 1); 508 509 free(str); 509 510 510 console_set_ color(con, COLOR_WHITE, COLOR_BLACK, 0);511 console_set_style(con, STYLE_INVERTED); 511 512 512 513 max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt)); … … 552 553 str = wstr_to_astr(buffer); 553 554 554 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);555 console_set_style(con, STYLE_NORMAL); 555 556 556 557 return str; … … 671 672 { 672 673 int sh_rows, rows; 673 int i, j;674 674 675 675 sheet_get_num_rows(&doc.sh, &sh_rows); … … 678 678 /* Draw rows from the sheet. */ 679 679 680 console_ goto(con, 0, 0);680 console_set_pos(con, 0, 0); 681 681 pane_row_range_display(0, rows); 682 682 683 683 /* Clear the remaining rows if file is short. */ 684 684 685 int i; 686 ipcarg_t j; 685 687 for (i = rows; i < pane.rows; ++i) { 686 console_ goto(con, 0, i);688 console_set_pos(con, 0, i); 687 689 for (j = 0; j < scr_columns; ++j) 688 690 putchar(' '); … … 736 738 /* Draw rows from the sheet. */ 737 739 738 console_ goto(con, 0, 0);740 console_set_pos(con, 0, 0); 739 741 for (i = r0; i < r1; ++i) { 740 742 /* Starting point for row display */ … … 756 758 coord_cmp(&rbc, &csel_end) < 0) { 757 759 fflush(stdout); 758 console_set_ color(con, COLOR_BLACK, COLOR_RED, 0);760 console_set_style(con, STYLE_SELECTED); 759 761 fflush(stdout); 760 762 } 761 763 762 console_ goto(con, 0, i);764 console_set_pos(con, 0, i); 763 765 size = str_size(row_buf); 764 766 pos = 0; … … 767 769 if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) { 768 770 fflush(stdout); 769 console_set_ color(con, COLOR_BLACK, COLOR_RED, 0);771 console_set_style(con, STYLE_SELECTED); 770 772 fflush(stdout); 771 773 } … … 773 775 if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { 774 776 fflush(stdout); 775 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);777 console_set_style(con, STYLE_NORMAL); 776 778 fflush(stdout); 777 779 } … … 793 795 if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { 794 796 fflush(stdout); 795 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);797 console_set_style(con, STYLE_NORMAL); 796 798 fflush(stdout); 797 799 } … … 807 809 putchar(' '); 808 810 fflush(stdout); 809 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);811 console_set_style(con, STYLE_NORMAL); 810 812 } 811 813 … … 824 826 const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; 825 827 826 console_ goto(con, 0, scr_rows - 1);827 console_set_ color(con, COLOR_WHITE, COLOR_BLACK, 0);828 console_set_pos(con, 0, scr_rows - 1); 829 console_set_style(con, STYLE_INVERTED); 828 830 int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit Ctrl-S Save " 829 831 "Ctrl-E Save As", coord.row, coord.column, fname); 830 832 printf("%*s", scr_columns - 1 - n, ""); 831 833 fflush(stdout); 832 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);834 console_set_style(con, STYLE_NORMAL); 833 835 834 836 pane.rflags |= REDRAW_CARET; … … 844 846 845 847 spt_get_coord(&caret_pt, &coord); 846 console_ goto(con, coord.column - pane.sh_column,848 console_set_pos(con, coord.column - pane.sh_column, 847 849 coord.row - pane.sh_row); 848 850 } … … 1149 1151 static void status_display(char const *str) 1150 1152 { 1151 console_ goto(con, 0, scr_rows - 1);1152 console_set_ color(con, COLOR_WHITE, COLOR_BLACK, 0);1153 console_set_pos(con, 0, scr_rows - 1); 1154 console_set_style(con, STYLE_INVERTED); 1153 1155 printf(" %*s ", -(scr_columns - 3), str); 1154 1156 fflush(stdout); 1155 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);1157 console_set_style(con, STYLE_NORMAL); 1156 1158 1157 1159 pane.rflags |= REDRAW_CARET; -
uspace/app/getterm/getterm.c
r38aaacc2 rf4f866c 40 40 #include <stdio.h> 41 41 #include <task.h> 42 #include <str_error.h> 42 43 #include "version.h" 44 45 #define APP_NAME "getterm" 43 46 44 47 static void usage(void) 45 48 { 46 printf("Usage: getterm <terminal> <path>\n");49 printf("Usage: %s <terminal> <path>\n", APP_NAME); 47 50 } 48 51 … … 76 79 args[1] = NULL; 77 80 78 task_id_t id = task_spawn(fname, args); 81 int err; 82 task_id_t id = task_spawn(fname, args, &err); 79 83 80 84 if (id == 0) 81 printf("Error spawning %s\n", fname); 85 printf("%s: Error spawning %s (%s)\n", APP_NAME, fname, 86 str_error(err)); 82 87 83 88 return id; -
uspace/app/init/init.c
r38aaacc2 rf4f866c 48 48 #include <str.h> 49 49 #include <devmap.h> 50 #include <str_error.h> 50 51 #include "init.h" 51 52 53 #define ROOT_DEVICE "bd/initrd" 54 #define ROOT_MOUNT_POINT "/" 55 56 #define DEVFS_FS_TYPE "devfs" 52 57 #define DEVFS_MOUNT_POINT "/dev" 58 59 #define SCRATCH_FS_TYPE "tmpfs" 60 #define SCRATCH_MOUNT_POINT "/scratch" 61 62 #define DATA_FS_TYPE "fat" 63 #define DATA_DEVICE "bd/disk0" 64 #define DATA_MOUNT_POINT "/data" 53 65 54 66 #define SRV_CONSOLE "/srv/console" … … 57 69 static void info_print(void) 58 70 { 59 printf(NAME ": HelenOS init\n"); 71 printf("%s: HelenOS init\n", NAME); 72 } 73 74 static bool mount_report(const char *desc, const char *mntpt, 75 const char *fstype, const char *dev, int rc) 76 { 77 switch (rc) { 78 case EOK: 79 if (dev != NULL) 80 printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt, 81 fstype, dev); 82 else 83 printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype); 84 break; 85 case EBUSY: 86 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt); 87 return false; 88 case ELIMIT: 89 printf("%s: %s limit exceeded\n", NAME, desc); 90 return false; 91 case ENOENT: 92 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype); 93 return false; 94 default: 95 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt, 96 str_error(rc)); 97 return false; 98 } 99 100 return true; 60 101 } 61 102 … … 63 104 { 64 105 const char *opts = ""; 65 const char *root_dev = "bd/initrd";66 106 67 107 if (str_cmp(fstype, "tmpfs") == 0) 68 108 opts = "restore"; 69 109 70 int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING); 71 72 switch (rc) { 73 case EOK: 74 printf(NAME ": Root filesystem mounted, %s at %s\n", 75 fstype, root_dev); 76 break; 77 case EBUSY: 78 printf(NAME ": Root filesystem already mounted\n"); 79 return false; 80 case ELIMIT: 81 printf(NAME ": Unable to mount root filesystem\n"); 82 return false; 83 case ENOENT: 84 printf(NAME ": Unknown filesystem type (%s)\n", fstype); 85 return false; 86 default: 87 printf(NAME ": Error mounting root filesystem (%d)\n", rc); 88 return false; 89 } 90 91 return true; 110 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts, 111 IPC_FLAG_BLOCKING); 112 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype, 113 ROOT_DEVICE, rc); 92 114 } 93 115 94 116 static bool mount_devfs(void) 95 117 { 96 int rc = mount("devfs", DEVFS_MOUNT_POINT, "", "", IPC_FLAG_BLOCKING); 97 98 switch (rc) { 99 case EOK: 100 printf(NAME ": Device filesystem mounted\n"); 101 break; 102 case EBUSY: 103 printf(NAME ": Device filesystem already mounted\n"); 104 return false; 105 case ELIMIT: 106 printf(NAME ": Unable to mount device filesystem\n"); 107 return false; 108 case ENOENT: 109 printf(NAME ": Unknown filesystem type (devfs)\n"); 110 return false; 111 default: 112 printf(NAME ": Error mounting device filesystem (%d)\n", rc); 113 return false; 114 } 115 116 return true; 118 int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "", 119 IPC_FLAG_BLOCKING); 120 return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE, 121 NULL, rc); 117 122 } 118 123 … … 125 130 return; 126 131 127 printf( NAME ": Spawning %s\n", fname);132 printf("%s: Spawning %s\n", NAME, fname); 128 133 129 134 argv[0] = fname; 130 135 argv[1] = NULL; 131 136 132 if (!task_spawn(fname, argv)) 133 printf(NAME ": Error spawning %s\n", fname); 137 int err; 138 if (!task_spawn(fname, argv, &err)) 139 printf("%s: Error spawning %s (%s)\n", NAME, fname, 140 str_error(err)); 134 141 } 135 142 … … 145 152 return; 146 153 147 printf( NAME ": Starting %s\n", fname);154 printf("%s: Starting %s\n", NAME, fname); 148 155 149 156 argv[0] = fname; 150 157 argv[1] = NULL; 151 158 152 id = task_spawn(fname, argv );159 id = task_spawn(fname, argv, &retval); 153 160 if (!id) { 154 printf(NAME ": Error spawning %s\n", fname); 161 printf("%s: Error spawning %s (%s)\n", NAME, fname, 162 str_error(retval)); 155 163 return; 156 164 } 157 165 158 166 rc = task_wait(id, &texit, &retval); 159 167 if (rc != EOK) { 160 printf(NAME ": Error waiting for %s\n", fname); 168 printf("%s: Error waiting for %s (%s(\n", NAME, fname, 169 str_error(retval)); 161 170 return; 162 171 } 163 172 164 173 if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) { 165 printf( NAME ": Server %s failed to start (returned %d)\n",166 fname, retval);174 printf("%s: Server %s failed to start (%s)\n", NAME, 175 fname, str_error(retval)); 167 176 } 168 177 } … … 176 185 snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 177 186 178 printf( NAME ": Spawning %s with %s\n", SRV_CONSOLE, hid_in);187 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in); 179 188 180 189 /* Wait for the input device to be ready */ … … 187 196 argv[2] = NULL; 188 197 189 if (!task_spawn(SRV_CONSOLE, argv)) 190 printf(NAME ": Error spawning %s with %s\n", SRV_CONSOLE, hid_in); 198 if (!task_spawn(SRV_CONSOLE, argv, &rc)) 199 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE, 200 hid_in, str_error(rc)); 191 201 } else 192 printf(NAME ": Error waiting on %s\n", hid_in); 202 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in, 203 str_error(rc)); 193 204 } 194 205 … … 201 212 snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 202 213 203 printf( NAME ": Spawning %s with %s %s\n", APP_GETTERM, term, app);214 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app); 204 215 205 216 /* Wait for the terminal device to be ready */ … … 213 224 argv[3] = NULL; 214 225 215 if (!task_spawn(APP_GETTERM, argv ))216 printf( NAME ": Error spawning %s with %s %s\n", APP_GETTERM,217 term, app );226 if (!task_spawn(APP_GETTERM, argv, &rc)) 227 printf("%s: Error spawning %s %s %s (%s)\n", NAME, APP_GETTERM, 228 term, app, str_error(rc)); 218 229 } else 219 printf(NAME ": Error waiting on %s\n", term); 220 } 221 222 static void mount_scratch(void) 223 { 224 int rc; 225 226 printf("Trying to mount null/0 on /scratch... "); 227 fflush(stdout); 228 229 rc = mount("tmpfs", "/scratch", "null/0", "", 0); 230 if (rc == EOK) 231 printf("OK\n"); 232 else 233 printf("Failed\n"); 234 } 235 236 static void mount_data(void) 237 { 238 int rc; 239 240 printf("Trying to mount bd/disk0 on /data... "); 241 fflush(stdout); 242 243 rc = mount("fat", "/data", "bd/disk0", "wtcache", 0); 244 if (rc == EOK) 245 printf("OK\n"); 246 else 247 printf("Failed\n"); 230 printf("%s: Error waiting on %s (%s)\n", NAME, term, 231 str_error(rc)); 232 } 233 234 static bool mount_scratch(void) 235 { 236 int rc = mount(SCRATCH_FS_TYPE, SCRATCH_MOUNT_POINT, "", "", 0); 237 return mount_report("Scratch filesystem", SCRATCH_MOUNT_POINT, 238 SCRATCH_FS_TYPE, NULL, rc); 239 } 240 241 static bool mount_data(void) 242 { 243 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0); 244 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE, 245 DATA_DEVICE, rc); 248 246 } 249 247 … … 253 251 254 252 if (!mount_root(STRING(RDFMT))) { 255 printf( NAME ": Exiting\n");253 printf("%s: Exiting\n", NAME); 256 254 return -1; 257 255 } 258 256 259 257 /* Make sure tmpfs is running. */ 260 258 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) { … … 266 264 267 265 if (!mount_devfs()) { 268 printf( NAME ": Exiting\n");266 printf("%s: Exiting\n", NAME); 269 267 return -2; 270 268 } 271 269 272 270 mount_scratch(); 273 271 … … 278 276 srv_start("/srv/adb_ms"); 279 277 srv_start("/srv/char_ms"); 280 278 281 279 spawn("/srv/fb"); 282 280 spawn("/srv/kbd"); … … 284 282 285 283 spawn("/srv/clip"); 286 284 287 285 /* 288 286 * Start these synchronously so that mount_data() can be … … 295 293 (void) srv_start; 296 294 #endif 297 295 298 296 #ifdef CONFIG_MOUNT_DATA 299 297 mount_data(); … … 301 299 (void) mount_data; 302 300 #endif 303 301 304 302 getterm("term/vc0", "/app/bdsh"); 305 303 getterm("term/vc1", "/app/bdsh"); … … 309 307 getterm("term/vc5", "/app/bdsh"); 310 308 getterm("term/vc6", "/app/klog"); 311 309 312 310 return 0; 313 311 } -
uspace/app/klog/klog.c
r38aaacc2 rf4f866c 64 64 int main(int argc, char *argv[]) 65 65 { 66 size_t klog_pages = sysinfo_value("klog.pages"); 66 size_t klog_pages; 67 if (sysinfo_get_value("klog.pages", &klog_pages) != EOK) { 68 printf("%s: Error getting klog address\n", NAME); 69 return -1; 70 } 71 67 72 size_t klog_size = klog_pages * PAGE_SIZE; 68 73 klog_length = klog_size / sizeof(wchar_t); … … 70 75 klog = (wchar_t *) as_get_mappable_page(klog_size); 71 76 if (klog == NULL) { 72 printf( NAME ": Error allocating memory area\n");77 printf("%s: Error allocating memory area\n", NAME); 73 78 return -1; 74 79 } … … 77 82 klog_size, SERVICE_MEM_KLOG); 78 83 if (res != EOK) { 79 printf( NAME ": Error initializing memory area\n");84 printf("%s: Error initializing memory area\n", NAME); 80 85 return -1; 81 86 } 82 87 83 88 if (event_subscribe(EVENT_KLOG, 0) != EOK) { 84 printf( NAME ": Error registering klog notifications\n");89 printf("%s: Error registering klog notifications\n", NAME); 85 90 return -1; 86 91 } -
uspace/app/netecho/Makefile
r38aaacc2 rf4f866c 35 35 SOURCES = \ 36 36 netecho.c \ 37 parse.c \38 37 print_error.c 39 38 -
uspace/app/netecho/netecho.c
r38aaacc2 rf4f866c 40 40 #include <str.h> 41 41 #include <task.h> 42 #include <arg_parse.h> 42 43 43 44 #include <in.h> … … 46 47 #include <socket.h> 47 48 #include <net_err.h> 48 49 #include "parse.h" 49 #include <socket_parse.h> 50 50 51 #include "print_error.h" 51 52 … … 128 129 int value; 129 130 130 // print the program label131 printf("Task %d - ", task_get_id());132 printf("%s\n", NAME);133 134 131 // parse the command line arguments 135 132 for(index = 1; index < argc; ++ index){ … … 137 134 switch(argv[index][1]){ 138 135 case 'b': 139 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &backlog, "accepted sockets queue size", 0));136 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 0)); 140 137 break; 141 138 case 'c': 142 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &count, "message count", 0));139 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 0)); 143 140 break; 144 141 case 'f': 145 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0,parse_protocol_family));142 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family)); 146 143 break; 147 144 case 'h': … … 150 147 break; 151 148 case 'p': 152 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "port number", 0));149 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 153 150 port = (uint16_t) value; 154 151 break; 155 152 case 'r': 156 ERROR_PROPAGATE( parse_parameter_string(argc, argv, &index, &reply, "reply string", 0));153 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 0)); 157 154 break; 158 155 case 's': 159 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "receive size", 0));156 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 160 157 size = (value >= 0) ? (size_t) value : 0; 161 158 break; 162 159 case 't': 163 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0,parse_socket_type));160 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type)); 164 161 type = (sock_type_t) value; 165 162 break; … … 170 167 case '-': 171 168 if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){ 172 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &backlog, "accepted sockets queue size", 8));169 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 8)); 173 170 }else if(str_lcmp(argv[index] + 2, "count=", 6) == 0){ 174 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &count, "message count", 8));171 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 8)); 175 172 }else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){ 176 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9,parse_protocol_family));173 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family)); 177 174 }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){ 178 175 echo_print_help(); 179 176 return EOK; 180 177 }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){ 181 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "port number", 7));178 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 182 179 port = (uint16_t) value; 183 180 }else if(str_lcmp(argv[index] + 2, "reply=", 6) == 0){ 184 ERROR_PROPAGATE( parse_parameter_string(argc, argv, &index, &reply, "reply string", 8));181 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 8)); 185 182 }else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){ 186 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "receive size", 7));183 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 187 184 size = (value >= 0) ? (size_t) value : 0; 188 185 }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){ 189 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7,parse_socket_type));186 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type)); 190 187 type = (sock_type_t) value; 191 188 }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){ 192 189 verbose = 1; 193 190 }else{ 194 print_unrecognized(index, argv[index] + 2);195 191 echo_print_help(); 196 192 return EINVAL; … … 198 194 break; 199 195 default: 200 print_unrecognized(index, argv[index] + 1);201 196 echo_print_help(); 202 197 return EINVAL; 203 198 } 204 199 }else{ 205 print_unrecognized(index, argv[index]);206 200 echo_print_help(); 207 201 return EINVAL; -
uspace/app/nettest1/Makefile
r38aaacc2 rf4f866c 36 36 nettest1.c \ 37 37 nettest.c \ 38 parse.c \39 38 print_error.c 40 39 -
uspace/app/nettest1/nettest1.c
r38aaacc2 rf4f866c 40 40 #include <task.h> 41 41 #include <time.h> 42 #include <arg_parse.h> 42 43 43 44 #include <in.h> … … 46 47 #include <socket.h> 47 48 #include <net_err.h> 49 #include <socket_parse.h> 48 50 49 51 #include "nettest.h" 50 #include "parse.h"51 52 #include "print_error.h" 52 53 … … 105 106 struct timeval time_after; 106 107 107 // print the program label108 printf("Task %d - ", task_get_id());109 printf("%s\n", NAME);110 111 108 // parse the command line arguments 112 109 // stop before the last argument if it does not start with the minus sign ('-') … … 117 114 // short options with only one letter 118 115 case 'f': 119 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0,parse_protocol_family));116 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family)); 120 117 break; 121 118 case 'h': … … 124 121 break; 125 122 case 'm': 126 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &messages, "message count", 0));123 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0)); 127 124 break; 128 125 case 'n': 129 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));126 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0)); 130 127 break; 131 128 case 'p': 132 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "port number", 0));129 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 133 130 port = (uint16_t) value; 134 131 break; 135 132 case 's': 136 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "packet size", 0));133 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 137 134 size = (value >= 0) ? (size_t) value : 0; 138 135 break; 139 136 case 't': 140 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0,parse_socket_type));137 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type)); 141 138 type = (sock_type_t) value; 142 139 break; … … 147 144 case '-': 148 145 if(str_lcmp(argv[index] + 2, "family=", 7) == 0){ 149 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9,parse_protocol_family));146 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family)); 150 147 }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){ 151 148 nettest1_print_help(); 152 149 return EOK; 153 150 }else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){ 154 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &messages, "message count", 8));151 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8)); 155 152 }else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){ 156 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));153 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8)); 157 154 }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){ 158 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "port number", 7));155 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 159 156 port = (uint16_t) value; 160 157 }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){ 161 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7,parse_socket_type));158 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type)); 162 159 type = (sock_type_t) value; 163 160 }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){ 164 161 verbose = 1; 165 162 }else{ 166 print_unrecognized(index, argv[index] + 2);167 163 nettest1_print_help(); 168 164 return EINVAL; … … 170 166 break; 171 167 default: 172 print_unrecognized(index, argv[index] + 1);173 168 nettest1_print_help(); 174 169 return EINVAL; 175 170 } 176 171 }else{ 177 print_unrecognized(index, argv[index]);178 172 nettest1_print_help(); 179 173 return EINVAL; -
uspace/app/nettest2/Makefile
r38aaacc2 rf4f866c 36 36 nettest2.c \ 37 37 nettest.c \ 38 parse.c \39 38 print_error.c 40 39 -
uspace/app/nettest2/nettest2.c
r38aaacc2 rf4f866c 40 40 #include <task.h> 41 41 #include <time.h> 42 #include <arg_parse.h> 42 43 43 44 #include <in.h> … … 46 47 #include <socket.h> 47 48 #include <net_err.h> 49 #include <socket_parse.h> 48 50 49 51 #include "nettest.h" 50 #include "parse.h"51 52 #include "print_error.h" 52 53 … … 105 106 struct timeval time_after; 106 107 107 printf("Task %d - ", task_get_id());108 printf("%s\n", NAME);109 110 108 // parse the command line arguments 111 109 // stop before the last argument if it does not start with the minus sign ('-') … … 116 114 // short options with only one letter 117 115 case 'f': 118 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0,parse_protocol_family));116 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family)); 119 117 break; 120 118 case 'h': … … 123 121 break; 124 122 case 'm': 125 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &messages, "message count", 0));123 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0)); 126 124 break; 127 125 case 'n': 128 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));126 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0)); 129 127 break; 130 128 case 'p': 131 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "port number", 0));129 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 132 130 port = (uint16_t) value; 133 131 break; 134 132 case 's': 135 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "packet size", 0));133 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 136 134 size = (value >= 0) ? (size_t) value : 0; 137 135 break; 138 136 case 't': 139 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0,parse_socket_type));137 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type)); 140 138 type = (sock_type_t) value; 141 139 break; … … 146 144 case '-': 147 145 if(str_lcmp(argv[index] + 2, "family=", 7) == 0){ 148 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9,parse_protocol_family));146 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family)); 149 147 }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){ 150 148 nettest2_print_help(); 151 149 return EOK; 152 150 }else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){ 153 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &messages, "message count", 8));151 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8)); 154 152 }else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){ 155 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));153 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8)); 156 154 }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){ 157 ERROR_PROPAGATE( parse_parameter_int(argc, argv, &index, &value, "port number", 7));155 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 158 156 port = (uint16_t) value; 159 157 }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){ 160 ERROR_PROPAGATE( parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7,parse_socket_type));158 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type)); 161 159 type = (sock_type_t) value; 162 160 }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){ 163 161 verbose = 1; 164 162 }else{ 165 print_unrecognized(index, argv[index] + 2);166 163 nettest2_print_help(); 167 164 return EINVAL; … … 169 166 break; 170 167 default: 171 print_unrecognized(index, argv[index] + 1);172 168 nettest2_print_help(); 173 169 return EINVAL; 174 170 } 175 171 }else{ 176 print_unrecognized(index, argv[index]);177 172 nettest2_print_help(); 178 173 return EINVAL; -
uspace/app/ping/Makefile
r38aaacc2 rf4f866c 35 35 SOURCES = \ 36 36 ping.c \ 37 parse.c \38 37 print_error.c 39 38 -
uspace/app/ping/ping.c
r38aaacc2 rf4f866c 28 28 29 29 /** @addtogroup ping 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Ping application.34 * Packet Internet Network Grouper. 35 35 */ 36 36 … … 41 41 #include <ipc/ipc.h> 42 42 #include <ipc/services.h> 43 #include <str_error.h> 44 #include <arg_parse.h> 43 45 44 46 #include <icmp_api.h> … … 48 50 #include <ip_codes.h> 49 51 #include <socket_errno.h> 50 #include <net_err.h> 51 52 #include "parse.h" 52 #include <socket_parse.h> 53 53 54 #include "print_error.h" 54 55 55 /** Echo module name. 56 */ 57 #define NAME "Ping" 58 59 /** Module entry point. 60 * Reads command line parameters and pings. 61 * @param[in] argc The number of command line parameters. 62 * @param[in] argv The command line parameters. 63 * @returns EOK on success. 64 */ 65 int main(int argc, char * argv[]); 66 67 /** Prints the application help. 68 */ 69 void ping_print_help(void); 70 71 int main(int argc, char * argv[]){ 72 ERROR_DECLARE; 73 74 size_t size = 38; 75 int verbose = 0; 76 int dont_fragment = 0; 77 ip_ttl_t ttl = 0; 78 ip_tos_t tos = 0; 79 int count = 3; 80 suseconds_t timeout = 3000; 81 int family = AF_INET; 82 83 socklen_t max_length = sizeof(struct sockaddr_in6); 84 uint8_t address_data[max_length]; 85 struct sockaddr * address = (struct sockaddr *) address_data; 86 struct sockaddr_in * address_in = (struct sockaddr_in *) address; 87 struct sockaddr_in6 * address_in6 = (struct sockaddr_in6 *) address; 88 socklen_t addrlen; 89 char address_string[INET6_ADDRSTRLEN]; 90 uint8_t * address_start; 91 int icmp_phone; 92 struct timeval time_before; 93 struct timeval time_after; 94 int result; 95 int value; 96 int index; 97 98 // print the program label 99 printf("Task %d - ", task_get_id()); 100 printf("%s\n", NAME); 101 102 // parse the command line arguments 103 // stop before the last argument if it does not start with the minus sign ('-') 104 for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){ 105 // options should start with the minus sign ('-') 106 if(argv[index][0] == '-'){ 107 switch(argv[index][1]){ 108 // short options with only one letter 109 case 'c': 110 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "count", 0)); 111 break; 112 case 'f': 113 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "address family", 0, parse_address_family)); 114 break; 115 case 'h': 116 ping_print_help(); 117 return EOK; 118 break; 119 case 's': 120 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0)); 121 size = (value >= 0) ? (size_t) value : 0; 122 break; 123 case 't': 124 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "timeout", 0)); 125 timeout = (value >= 0) ? (suseconds_t) value : 0; 126 break; 127 case 'v': 128 verbose = 1; 129 break; 130 // long options with the double minus sign ('-') 131 case '-': 132 if(str_lcmp(argv[index] + 2, "count=", 6) == 0){ 133 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "received count", 8)); 134 }else if(str_lcmp(argv[index] + 2, "dont_fragment", 13) == 0){ 135 dont_fragment = 1; 136 }else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){ 137 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "address family", 9, parse_address_family)); 138 }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){ 139 ping_print_help(); 140 return EOK; 141 }else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){ 142 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 7)); 143 size = (value >= 0) ? (size_t) value : 0; 144 }else if(str_lcmp(argv[index] + 2, "timeout=", 8) == 0){ 145 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "timeout", 7)); 146 timeout = (value >= 0) ? (suseconds_t) value : 0; 147 }else if(str_lcmp(argv[index] + 2, "tos=", 4) == 0){ 148 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "type of service", 7)); 149 tos = (value >= 0) ? (ip_tos_t) value : 0; 150 }else if(str_lcmp(argv[index] + 2, "ttl=", 4) == 0){ 151 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "time to live", 7)); 152 ttl = (value >= 0) ? (ip_ttl_t) value : 0; 153 }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){ 154 verbose = 1; 155 }else{ 156 print_unrecognized(index, argv[index] + 2); 157 ping_print_help(); 158 return EINVAL; 159 } 160 break; 161 default: 162 print_unrecognized(index, argv[index] + 1); 163 ping_print_help(); 164 return EINVAL; 165 } 166 }else{ 167 print_unrecognized(index, argv[index]); 168 ping_print_help(); 169 return EINVAL; 170 } 171 } 172 173 // if not before the last argument containing the address 174 if(index >= argc){ 175 printf("Command line error: missing address\n"); 176 ping_print_help(); 177 return EINVAL; 178 } 179 180 // prepare the address buffer 181 bzero(address_data, max_length); 182 switch(family){ 183 case AF_INET: 184 address_in->sin_family = AF_INET; 185 address_start = (uint8_t *) &address_in->sin_addr.s_addr; 186 addrlen = sizeof(struct sockaddr_in); 56 #define NAME "ping" 57 58 #define CL_OK 0 59 #define CL_USAGE -1 60 #define CL_MISSING -2 61 #define CL_INVALID -3 62 #define CL_UNSUPPORTED -4 63 #define CL_ERROR -5 64 65 /** Ping configuration 66 * 67 */ 68 typedef struct { 69 bool verbose; /**< Verbose printouts. */ 70 size_t size; /**< Outgoing packet size. */ 71 unsigned int count; /**< Number of packets to send. */ 72 suseconds_t timeout; /**< Reply wait timeout. */ 73 int af; /**< Address family. */ 74 ip_tos_t tos; /**< Type of service. */ 75 ip_ttl_t ttl; /**< Time-to-live. */ 76 bool fragments; /**< Fragmentation. */ 77 78 char *dest_addr; /**< Destination address. */ 79 struct sockaddr_in dest; /**< IPv4 destionation. */ 80 struct sockaddr_in6 dest6; /**< IPv6 destionation. */ 81 82 struct sockaddr *dest_raw; /**< Raw destination address. */ 83 socklen_t dest_len; /**< Raw destination address length. */ 84 85 /** Converted address string. */ 86 char dest_str[INET6_ADDRSTRLEN]; 87 } ping_config_t; 88 89 90 static void usage(void) 91 { 92 printf( 93 "Usage: ping [-c count] [-s size] [-W timeout] [-f family] [-t ttl]\n" \ 94 " [-Q tos] [--dont_fragment] destination\n" \ 95 "\n" \ 96 "Options:\n" \ 97 "\t-c count\n" \ 98 "\t--count=count\n" \ 99 "\t\tNumber of outgoing packets (default: 4)\n" \ 100 "\n" \ 101 "\t-s size\n" \ 102 "\t--size=bytes\n" \ 103 "\t\tOutgoing packet size (default: 56 bytes)\n" \ 104 "\n" \ 105 "\t-W timeout\n" \ 106 "\t--timeout=ms\n" \ 107 "\t\tReply wait timeout (default: 3000 ms)\n" \ 108 "\n" \ 109 "\t-f family\n" \ 110 "\t--family=family\n" \ 111 "\t\tDestination address family, AF_INET or AF_INET6 (default: AF_INET)\n" \ 112 "\n" \ 113 "\t-t ttl\n" \ 114 "\t--ttl=ttl\n" \ 115 "\t\tOutgoing packet time-to-live (default: 0)\n" \ 116 "\n" \ 117 "\t-Q tos\n" \ 118 "\t--tos=tos\n" \ 119 "\t\tOutgoing packet type of service (default: 0)\n" \ 120 "\n" \ 121 "\t--dont_fragment\n" \ 122 "\t\tDisable packet fragmentation (default: enabled)\n" \ 123 "\n" \ 124 "\t-v\n" \ 125 "\t--verbose\n" \ 126 "\t\tVerbose operation\n" \ 127 "\n" \ 128 "\t-h\n" \ 129 "\t--help\n" \ 130 "\t\tPrint this usage information\n" 131 ); 132 } 133 134 static int args_parse(int argc, char *argv[], ping_config_t *config) 135 { 136 if (argc < 2) 137 return CL_USAGE; 138 139 int i; 140 int ret; 141 142 for (i = 1; i < argc; i++) { 143 144 /* Not an option */ 145 if (argv[i][0] != '-') 187 146 break; 188 case AF_INET6: 189 address_in6->sin6_family = AF_INET6; 190 address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr; 191 addrlen = sizeof(struct sockaddr_in6); 147 148 /* Options terminator */ 149 if (str_cmp(argv[i], "--") == 0) { 150 i++; 151 break; 152 } 153 154 int off; 155 156 /* Usage */ 157 if ((off = arg_parse_short_long(argv[i], "-h", "--help")) != -1) 158 return CL_USAGE; 159 160 /* Verbose */ 161 if ((off = arg_parse_short_long(argv[i], "-v", "--verbose")) != -1) { 162 config->verbose = true; 163 continue; 164 } 165 166 /* Don't fragment */ 167 if (str_cmp(argv[i], "--dont_fragment") == 0) { 168 config->fragments = false; 169 continue; 170 } 171 172 /* Count */ 173 if ((off = arg_parse_short_long(argv[i], "-c", "--count=")) != -1) { 174 int tmp; 175 ret = arg_parse_int(argc, argv, &i, &tmp, off); 176 177 if ((ret != EOK) || (tmp < 0)) 178 return i; 179 180 config->count = (unsigned int) tmp; 181 continue; 182 } 183 184 /* Outgoing packet size */ 185 if ((off = arg_parse_short_long(argv[i], "-s", "--size=")) != -1) { 186 int tmp; 187 ret = arg_parse_int(argc, argv, &i, &tmp, off); 188 189 if ((ret != EOK) || (tmp < 0)) 190 return i; 191 192 config->size = (size_t) tmp; 193 continue; 194 } 195 196 /* Reply wait timeout */ 197 if ((off = arg_parse_short_long(argv[i], "-W", "--timeout=")) != -1) { 198 int tmp; 199 ret = arg_parse_int(argc, argv, &i, &tmp, off); 200 201 if ((ret != EOK) || (tmp < 0)) 202 return i; 203 204 config->timeout = (suseconds_t) tmp; 205 continue; 206 } 207 208 /* Address family */ 209 if ((off = arg_parse_short_long(argv[i], "-f", "--family=")) != -1) { 210 ret = arg_parse_name_int(argc, argv, &i, &config->af, off, 211 socket_parse_address_family); 212 213 if (ret != EOK) 214 return i; 215 216 continue; 217 } 218 219 /* Type of service */ 220 if ((off = arg_parse_short_long(argv[i], "-Q", "--tos=")) != -1) { 221 int tmp; 222 ret = arg_parse_name_int(argc, argv, &i, &tmp, off, 223 socket_parse_address_family); 224 225 if ((ret != EOK) || (tmp < 0)) 226 return i; 227 228 config->tos = (ip_tos_t) tmp; 229 continue; 230 } 231 232 /* Time to live */ 233 if ((off = arg_parse_short_long(argv[i], "-t", "--ttl=")) != -1) { 234 int tmp; 235 ret = arg_parse_name_int(argc, argv, &i, &tmp, off, 236 socket_parse_address_family); 237 238 if ((ret != EOK) || (tmp < 0)) 239 return i; 240 241 config->ttl = (ip_ttl_t) tmp; 242 continue; 243 } 244 } 245 246 if (i >= argc) 247 return CL_MISSING; 248 249 config->dest_addr = argv[i]; 250 251 /* Resolve destionation address */ 252 switch (config->af) { 253 case AF_INET: 254 config->dest_raw = (struct sockaddr *) &config->dest; 255 config->dest_len = sizeof(config->dest); 256 config->dest.sin_family = config->af; 257 ret = inet_pton(config->af, config->dest_addr, 258 (uint8_t *) &config->dest.sin_addr.s_addr); 259 break; 260 case AF_INET6: 261 config->dest_raw = (struct sockaddr *) &config->dest6; 262 config->dest_len = sizeof(config->dest6); 263 config->dest6.sin6_family = config->af; 264 ret = inet_pton(config->af, config->dest_addr, 265 (uint8_t *) &config->dest6.sin6_addr.s6_addr); 266 break; 267 default: 268 return CL_UNSUPPORTED; 269 } 270 271 if (ret != EOK) 272 return CL_INVALID; 273 274 /* Convert destination address back to string */ 275 switch (config->af) { 276 case AF_INET: 277 ret = inet_ntop(config->af, 278 (uint8_t *) &config->dest.sin_addr.s_addr, 279 config->dest_str, sizeof(config->dest_str)); 280 break; 281 case AF_INET6: 282 ret = inet_ntop(config->af, 283 (uint8_t *) &config->dest6.sin6_addr.s6_addr, 284 config->dest_str, sizeof(config->dest_str)); 285 break; 286 default: 287 return CL_UNSUPPORTED; 288 } 289 290 if (ret != EOK) 291 return CL_ERROR; 292 293 return CL_OK; 294 } 295 296 int main(int argc, char *argv[]) 297 { 298 ping_config_t config; 299 300 /* Default configuration */ 301 config.verbose = false; 302 config.size = 56; 303 config.count = 4; 304 config.timeout = 3000; 305 config.af = AF_INET; 306 config.tos = 0; 307 config.ttl = 0; 308 config.fragments = true; 309 310 int ret = args_parse(argc, argv, &config); 311 312 switch (ret) { 313 case CL_OK: 314 break; 315 case CL_USAGE: 316 usage(); 317 return 0; 318 case CL_MISSING: 319 fprintf(stderr, "%s: Destination address missing\n", NAME); 320 return 1; 321 case CL_INVALID: 322 fprintf(stderr, "%s: Destination address '%s' invalid or malformed\n", 323 NAME, config.dest_addr); 324 return 2; 325 case CL_UNSUPPORTED: 326 fprintf(stderr, "%s: Destination address '%s' unsupported\n", 327 NAME, config.dest_addr); 328 return 3; 329 case CL_ERROR: 330 fprintf(stderr, "%s: Destination address '%s' error\n", 331 NAME, config.dest_addr); 332 return 4; 333 default: 334 fprintf(stderr, "%s: Unknown or invalid option '%s'\n", NAME, 335 argv[ret]); 336 return 5; 337 } 338 339 printf("PING %s (%s) %u(%u) bytes of data\n", config.dest_addr, 340 config.dest_str, config.size, config.size); 341 342 int icmp_phone = icmp_connect_module(SERVICE_ICMP, ICMP_CONNECT_TIMEOUT); 343 if (icmp_phone < 0) { 344 fprintf(stderr, "%s: Unable to connect to ICMP service (%s)\n", NAME, 345 str_error(icmp_phone)); 346 return icmp_phone; 347 } 348 349 unsigned int seq; 350 for (seq = 0; seq < config.count; seq++) { 351 struct timeval t0; 352 ret = gettimeofday(&t0, NULL); 353 if (ret != EOK) { 354 fprintf(stderr, "%s: gettimeofday failed (%s)\n", NAME, 355 str_error(ret)); 356 357 ipc_hangup(icmp_phone); 358 return ret; 359 } 360 361 /* Ping! */ 362 int result = icmp_echo_msg(icmp_phone, config.size, config.timeout, 363 config.ttl, config.tos, !config.fragments, config.dest_raw, 364 config.dest_len); 365 366 struct timeval t1; 367 ret = gettimeofday(&t1, NULL); 368 if (ret != EOK) { 369 fprintf(stderr, "%s: gettimeofday failed (%s)\n", NAME, 370 str_error(ret)); 371 372 ipc_hangup(icmp_phone); 373 return ret; 374 } 375 376 suseconds_t elapsed = tv_sub(&t1, &t0); 377 378 switch (result) { 379 case ICMP_ECHO: 380 printf("%u bytes from ? (?): icmp_seq=%u ttl=? time=%u.%04u\n", 381 config.size, seq, elapsed / 1000, elapsed % 1000); 382 break; 383 case ETIMEOUT: 384 printf("%u bytes from ? (?): icmp_seq=%u Timed out\n", 385 config.size, seq); 192 386 break; 193 387 default: 194 fprintf(stderr, "Address family is not supported\n"); 195 return EAFNOSUPPORT; 196 } 197 198 // parse the last argument which should contain the address 199 if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){ 200 fprintf(stderr, "Address parse error %d\n", ERROR_CODE); 201 return ERROR_CODE; 202 } 203 204 // connect to the ICMP module 205 icmp_phone = icmp_connect_module(SERVICE_ICMP, ICMP_CONNECT_TIMEOUT); 206 if(icmp_phone < 0){ 207 fprintf(stderr, "ICMP connect error %d\n", icmp_phone); 208 return icmp_phone; 209 } 210 211 // print the ping header 212 printf("PING %d bytes of data\n", size); 213 if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){ 214 fprintf(stderr, "Address error %d\n", ERROR_CODE); 215 }else{ 216 printf("Address %s:\n", address_string); 217 } 218 219 // do count times 220 while(count > 0){ 221 222 // get the starting time 223 if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){ 224 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE); 225 // release the ICMP phone 226 ipc_hangup(icmp_phone); 227 return ERROR_CODE; 228 } 229 230 // request the ping 231 result = icmp_echo_msg(icmp_phone, size, timeout, ttl, tos, dont_fragment, address, addrlen); 232 233 // get the ending time 234 if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){ 235 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE); 236 // release the ICMP phone 237 ipc_hangup(icmp_phone); 238 return ERROR_CODE; 239 } 240 241 // print the result 242 switch(result){ 243 case ICMP_ECHO: 244 printf("Ping round trip time %d miliseconds\n", tv_sub(&time_after, &time_before) / 1000); 245 break; 246 case ETIMEOUT: 247 printf("Timed out.\n"); 248 break; 249 default: 250 print_error(stdout, result, NULL, "\n"); 251 } 252 -- count; 253 } 254 255 if(verbose){ 256 printf("Exiting\n"); 257 } 258 259 // release the ICMP phone 388 print_error(stdout, result, NULL, "\n"); 389 } 390 } 391 260 392 ipc_hangup(icmp_phone); 261 262 return EOK;393 394 return 0; 263 395 } 264 396 265 void ping_print_help(void){266 printf(267 "Network Ping aplication\n" \268 "Usage: ping [options] numeric_address\n" \269 "Where options are:\n" \270 "\n" \271 "-c request_count | --count=request_count\n" \272 "\tThe number of packets the application sends. The default is three (3).\n" \273 "\n" \274 "--dont_fragment\n" \275 "\tDisable packet fragmentation.\n"276 "\n" \277 "-f address_family | --family=address_family\n" \278 "\tThe given address family. Only the AF_INET and AF_INET6 are supported.\n"279 "\n" \280 "-h | --help\n" \281 "\tShow this application help.\n"282 "\n" \283 "-s packet_size | --size=packet_size\n" \284 "\tThe packet data size the application sends. The default is 38 bytes.\n" \285 "\n" \286 "-t timeout | --timeout=timeout\n" \287 "\tThe number of miliseconds the application waits for a reply. The default is three thousands (3 000).\n" \288 "\n" \289 "--tos=tos\n" \290 "\tThe type of service to be used.\n" \291 "\n" \292 "--ttl=ttl\n" \293 "\tThe time to live to be used.\n" \294 "\n" \295 "-v | --verbose\n" \296 "\tShow all output messages.\n"297 );298 }299 300 397 /** @} 301 398 */ -
uspace/app/redir/redir.c
r38aaacc2 rf4f866c 42 42 #include <stdio.h> 43 43 #include <task.h> 44 #include <str_error.h> 45 46 #define NAME "redir" 44 47 45 48 static void usage(void) 46 49 { 47 printf("Usage: redir [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n"); 50 printf("Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n", 51 NAME); 48 52 } 49 53 … … 84 88 args[argc] = NULL; 85 89 86 task_id_t id = task_spawn(argv[0], args); 90 int err; 91 task_id_t id = task_spawn(argv[0], args, &err); 87 92 88 93 free(args); 89 94 90 95 if (id == 0) 91 printf("Error spawning %s\n", argv[0]); 96 printf("%s: Error spawning %s (%s)\n", NAME, argv[0], 97 str_error(err)); 92 98 93 99 return id; -
uspace/app/sbi/src/os/helenos.c
r38aaacc2 rf4f866c 35 35 #include <task.h> 36 36 #include <tinput.h> 37 #include <str_error.h> 37 38 38 39 #include "os.h" … … 186 187 int retval; 187 188 188 tid = task_spawn(cmd[0], (char const * const *) cmd );189 tid = task_spawn(cmd[0], (char const * const *) cmd, &retval); 189 190 if (tid == 0) { 190 printf("Error: Failed spawning '%s'.\n", cmd[0]); 191 printf("Error: Failed spawning '%s' (%s).\n", cmd[0], 192 str_error(retval)); 191 193 exit(1); 192 194 } -
uspace/app/sbi/src/run_expr.c
r38aaacc2 rf4f866c 1434 1434 addr_prop->u.named->prop_d = deleg_p; 1435 1435 break; 1436 default: 1437 ritem = NULL; 1436 1438 } 1437 1439 -
uspace/app/tester/console/console1.c
r38aaacc2 rf4f866c 53 53 fflush(stdout); 54 54 console_set_style(fphone(stdout), STYLE_NORMAL); 55 printf(" normal ");55 printf(" normal "); 56 56 fflush(stdout); 57 57 console_set_style(fphone(stdout), STYLE_EMPHASIS); 58 printf("emphasized"); 58 printf(" emphasized "); 59 fflush(stdout); 60 console_set_style(fphone(stdout), STYLE_INVERTED); 61 printf(" inverted "); 62 fflush(stdout); 63 console_set_style(fphone(stdout), STYLE_SELECTED); 64 printf(" selected "); 59 65 fflush(stdout); 60 66 console_set_style(fphone(stdout), STYLE_NORMAL); 61 printf(" .\n");67 printf("\n"); 62 68 63 69 unsigned int i; … … 73 79 } 74 80 fflush(stdout); 75 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);81 console_set_style(fphone(stdout), STYLE_NORMAL); 76 82 putchar('\n'); 77 83 } … … 86 92 } 87 93 fflush(stdout); 88 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);94 console_set_style(fphone(stdout), STYLE_NORMAL); 89 95 putchar('\n'); 90 96 } … … 94 100 for (i = 0; i < 255; i += 16) { 95 101 fflush(stdout); 96 console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);102 console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16); 97 103 putchar('X'); 98 104 } … … 103 109 for (i = 0; i < 255; i += 16) { 104 110 fflush(stdout); 105 console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);111 console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8); 106 112 putchar('X'); 107 113 } … … 112 118 for (i = 0; i < 255; i += 16) { 113 119 fflush(stdout); 114 console_set_rgb_color(fphone(stdout), 0xffffff, i);120 console_set_rgb_color(fphone(stdout), 255 - i, i); 115 121 putchar('X'); 116 122 } 117 123 fflush(stdout); 118 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);124 console_set_style(fphone(stdout), STYLE_NORMAL); 119 125 putchar('\n'); 120 126 } -
uspace/app/tetris/screen.c
r38aaacc2 rf4f866c 53 53 #include <vfs/vfs.h> 54 54 #include <async.h> 55 #include <bool.h> 56 #include <io/console.h> 57 #include <io/style.h> 55 58 #include "screen.h" 56 59 #include "tetris.h" 57 #include <io/console.h>58 60 59 61 #define STOP (B_COLS - 3) … … 63 65 static int isset; /* true => terminal is in game mode */ 64 66 65 static int use_color;/* true => use colors */67 static bool use_color; /* true => use colors */ 66 68 67 69 static const struct shape *lastshape; … … 81 83 { 82 84 fflush(stdout); 83 console_set_rgb_color(fphone(stdout), 0xf 0f0f0,85 console_set_rgb_color(fphone(stdout), 0xffffff, 84 86 use_color ? color : 0x000000); 85 87 } … … 88 90 { 89 91 fflush(stdout); 90 console_set_ rgb_color(fphone(stdout), 0, 0xf0f0f0);92 console_set_style(fphone(stdout), STYLE_NORMAL); 91 93 } 92 94 … … 118 120 } 119 121 120 void moveto(i nt r, int c)122 void moveto(ipcarg_t r, ipcarg_t c) 121 123 { 122 124 fflush(stdout); 123 console_ goto(fphone(stdout), c, r);125 console_set_pos(fphone(stdout), c, r); 124 126 } 125 127 … … 131 133 } 132 134 133 static int get_display_color_sup(void) 134 { 135 int rc; 136 int ccap; 137 138 rc = console_get_color_cap(fphone(stdout), &ccap); 135 static bool get_display_color_sup(void) 136 { 137 ipcarg_t ccap; 138 int rc = console_get_color_cap(fphone(stdout), &ccap); 139 139 140 if (rc != 0) 140 return 0;141 141 return false; 142 142 143 return (ccap >= CONSOLE_CCAP_RGB); 143 144 } … … 308 309 * (We need its length in case we have to overwrite with blanks.) 309 310 */ 310 void scr_msg(char *s, intset)311 void scr_msg(char *s, bool set) 311 312 { 312 313 int l = str_size(s); -
uspace/app/tetris/screen.h
r38aaacc2 rf4f866c 48 48 49 49 #include <sys/types.h> 50 #include <ipc/ipc.h> 50 51 #include <async.h> 52 #include <bool.h> 51 53 52 54 typedef struct { 53 i nt ws_row;54 i nt ws_col;55 ipcarg_t ws_row; 56 ipcarg_t ws_col; 55 57 } winsize_t; 56 58 57 59 extern winsize_t winsize; 58 60 59 extern void moveto(i nt r, int c);61 extern void moveto(ipcarg_t r, ipcarg_t c); 60 62 extern void clear_screen(void); 61 63 … … 65 67 extern void scr_end(void); 66 68 extern void scr_init(void); 67 extern void scr_msg(char *, int);69 extern void scr_msg(char *, bool); 68 70 extern void scr_set(void); 69 71 extern void scr_update(void); -
uspace/app/top/screen.h
r38aaacc2 rf4f866c 1 1 /* 2 * Copyright (c) 2010 Stanislav Kozina 2 3 * Copyright (c) 2010 Martin Decky 3 4 * All rights reserved. … … 27 28 */ 28 29 29 /** @addtogroup netif_standalone30 * 30 /** @addtogroup top 31 * @{ 31 32 */ 32 33 33 #ifndef __NETIF_STANDALONE_H__34 #define __NETIF_STANDALONE_H__34 #ifndef TOP_SCREEN_H_ 35 #define TOP_SCREEN_H_ 35 36 36 #include <ipc/ipc.h> 37 #include <async.h> 37 #include "top.h" 38 38 39 extern int netif_module_message(ipc_callid_t callid, ipc_call_t *call, 40 ipc_call_t *answer, int *answer_count); 41 extern int netif_module_start(async_client_conn_t client_connection); 39 extern void screen_init(void); 40 extern void screen_done(void); 41 extern void print_data(data_t *); 42 extern void print_warning(const char *, ...); 42 43 43 44 #endif 44 45 45 /** @} 46 /** 47 * @} 46 48 */ -
uspace/app/trace/syscalls.c
r38aaacc2 rf4f866c 75 75 [SYS_PREEMPT_CONTROL] = { "preempt_control", 1, V_ERRNO }, 76 76 77 [SYS_SYSINFO_VALID] = { "sysinfo_valid", 2, V_HASH }, 78 [SYS_SYSINFO_VALUE] = { "sysinfo_value", 2, V_HASH }, 77 [SYS_SYSINFO_GET_TAG] = { "sysinfo_get_tag", 2, V_INTEGER }, 78 [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value", 3, V_ERRNO }, 79 [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size", 3, V_ERRNO }, 80 [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data", 4, V_ERRNO }, 81 79 82 [SYS_DEBUG_ENABLE_CONSOLE] = { "debug_enable_console", 0, V_ERRNO }, 80 83 [SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox", 1, V_ERRNO }
Note:
See TracChangeset
for help on using the changeset viewer.