Changeset a62ceaf in mainline for uspace/app
- Timestamp:
- 2016-02-29T19:19:19Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 129b92c6
- Parents:
- 5147ff1
- Location:
- uspace/app
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dnscfg/dnscfg.c
r5147ff1 ra62ceaf 72 72 73 73 inet_addr_t addr; 74 int rc = inet_addr_parse(srv_addr, &addr );74 int rc = inet_addr_parse(srv_addr, &addr, NULL); 75 75 76 76 if (rc != EOK) { -
uspace/app/inet/inet.c
r5147ff1 ra62ceaf 88 88 } 89 89 90 rc = inet_naddr_parse(addr_spec, &naddr );90 rc = inet_naddr_parse(addr_spec, &naddr, NULL); 91 91 if (rc != EOK) { 92 92 printf(NAME ": Invalid network address format '%s'.\n", … … 177 177 route_name = argv[2]; 178 178 179 rc = inet_naddr_parse(dest_str, &dest );179 rc = inet_naddr_parse(dest_str, &dest, NULL); 180 180 if (rc != EOK) { 181 181 printf(NAME ": Invalid network address format '%s'.\n", … … 184 184 } 185 185 186 rc = inet_addr_parse(router_str, &router );186 rc = inet_addr_parse(router_str, &router, NULL); 187 187 if (rc != EOK) { 188 188 printf(NAME ": Invalid address format '%s'.\n", router_str); -
uspace/app/netecho/comm.c
r5147ff1 ra62ceaf 37 37 #include <errno.h> 38 38 #include <fibril.h> 39 #include <inet/dnsr.h>40 39 #include <inet/endpoint.h> 40 #include <inet/hostport.h> 41 41 #include <inet/udp.h> 42 42 #include <macros.h> … … 109 109 } 110 110 111 int comm_open (const char *host,const char *port_s)111 int comm_open_listen(const char *port_s) 112 112 { 113 113 inet_ep2_t epp; 114 inet_addr_t iaddr;115 114 int rc; 116 117 if (host != NULL) {118 /* Interpret as address */119 inet_addr_t iaddr;120 int rc = inet_addr_parse(host, &iaddr);121 122 if (rc != EOK) {123 /* Interpret as a host name */124 dnsr_hostinfo_t *hinfo = NULL;125 rc = dnsr_name2host(host, &hinfo, ip_any);126 127 if (rc != EOK) {128 printf("Error resolving host '%s'.\n", host);129 goto error;130 }131 132 iaddr = hinfo->addr;133 }134 }135 115 136 116 char *endptr; … … 142 122 143 123 inet_ep2_init(&epp); 144 if (host != NULL) { 145 /* Talk to remote host */ 146 remote.addr = iaddr; 147 remote.port = port; 124 epp.local.port = port; 148 125 149 printf("Talking to host %s port %u\n", host, port); 150 } else { 151 /* Listen on local port */ 152 epp.local.port = port; 126 printf("Listening on port %u\n", port); 153 127 154 printf("Listening on port %u\n", port); 128 rc = udp_create(&udp); 129 if (rc != EOK) 130 goto error; 131 132 rc = udp_assoc_create(udp, &epp, &comm_udp_cb, NULL, &assoc); 133 if (rc != EOK) 134 goto error; 135 136 return EOK; 137 error: 138 udp_assoc_destroy(assoc); 139 udp_destroy(udp); 140 141 return EIO; 142 } 143 144 int comm_open_talkto(const char *hostport) 145 { 146 inet_ep2_t epp; 147 const char *errmsg; 148 int rc; 149 150 inet_ep2_init(&epp); 151 rc = inet_hostport_plookup_one(hostport, ip_any, &epp.remote, NULL, 152 &errmsg); 153 if (rc != EOK) { 154 printf("Error: %s (host:port %s).\n", errmsg, hostport); 155 goto error; 155 156 } 157 158 printf("Talking to %s\n", hostport); 156 159 157 160 rc = udp_create(&udp); -
uspace/app/netecho/comm.h
r5147ff1 ra62ceaf 39 39 #include <sys/types.h> 40 40 41 extern int comm_open(const char *, const char *); 41 extern int comm_open_listen(const char *); 42 extern int comm_open_talkto(const char *); 42 43 extern void comm_close(void); 43 44 extern int comm_send(void *, size_t); -
uspace/app/netecho/netecho.c
r5147ff1 ra62ceaf 115 115 printf("syntax:\n"); 116 116 printf("\t%s -l <port>\n", NAME); 117 printf("\t%s -d <host> 117 printf("\t%s -d <host>:<port> [<message> [<message...>]]\n", NAME); 118 118 } 119 119 … … 151 151 int main(int argc, char *argv[]) 152 152 { 153 char *host ;153 char *hostport; 154 154 char *port; 155 155 char **msgs; … … 167 167 } 168 168 169 host = NULL;170 169 port = argv[2]; 171 170 msgs = NULL; 171 172 rc = comm_open_listen(port); 173 if (rc != EOK) { 174 printf("Error setting up communication.\n"); 175 return 1; 176 } 172 177 } else if (str_cmp(argv[1], "-d") == 0) { 173 if (argc < 4) {178 if (argc < 3) { 174 179 print_syntax(); 175 180 return 1; 176 181 } 177 182 178 host = argv[2]; 179 port = argv[3]; 180 msgs = argv + 4; 183 hostport = argv[2]; 184 port = NULL; 185 msgs = argv + 3; 186 187 rc = comm_open_talkto(hostport); 188 if (rc != EOK) { 189 printf("Error setting up communication.\n"); 190 return 1; 191 } 181 192 } else { 182 193 print_syntax(); 183 return 1;184 }185 186 rc = comm_open(host, port);187 if (rc != EOK) {188 printf("Error setting up communication.\n");189 194 return 1; 190 195 } -
uspace/app/nterm/conn.c
r5147ff1 ra62ceaf 37 37 #include <errno.h> 38 38 #include <fibril.h> 39 #include <inet/dnsr.h>40 39 #include <inet/endpoint.h> 40 #include <inet/hostport.h> 41 41 #include <inet/tcp.h> 42 42 #include <stdio.h> … … 86 86 } 87 87 88 int conn_open(const char *host , const char *port_s)88 int conn_open(const char *hostport) 89 89 { 90 90 inet_ep2_t epp; 91 const char *errmsg; 92 int rc; 91 93 92 /* Interpret as address */ 93 inet_addr_t iaddr; 94 int rc = inet_addr_parse(host, &iaddr); 95 94 inet_ep2_init(&epp); 95 rc = inet_hostport_plookup_one(hostport, ip_any, &epp.remote, NULL, 96 &errmsg); 96 97 if (rc != EOK) { 97 /* Interpret as a host name */ 98 dnsr_hostinfo_t *hinfo = NULL; 99 rc = dnsr_name2host(host, &hinfo, ip_any); 100 101 if (rc != EOK) { 102 printf("Error resolving host '%s'.\n", host); 103 goto error; 104 } 105 106 iaddr = hinfo->addr; 107 } 108 109 char *endptr; 110 uint16_t port = strtol(port_s, &endptr, 10); 111 if (*endptr != '\0') { 112 printf("Invalid port number %s\n", port_s); 98 printf("Error: %s (host:port %s).\n", errmsg, hostport); 113 99 goto error; 114 100 } 115 101 116 inet_ep2_init(&epp);117 epp.remote.addr = iaddr;118 epp.remote.port = port;119 120 printf("Connecting to host %s port %u\n", host, port);102 printf("Connecting to %s\n", hostport); 103 char *s; 104 rc = inet_addr_format(&epp.remote.addr, &s); 105 if (rc != EOK) 106 goto error; 121 107 122 108 rc = tcp_create(&tcp); -
uspace/app/nterm/conn.h
r5147ff1 ra62ceaf 39 39 #include <sys/types.h> 40 40 41 extern int conn_open(const char * , const char *);41 extern int conn_open(const char *); 42 42 extern int conn_send(void *, size_t); 43 43 -
uspace/app/nterm/nterm.c
r5147ff1 ra62ceaf 104 104 static void print_syntax(void) 105 105 { 106 printf("syntax: nterm <host> 106 printf("syntax: nterm <host>:<port>\n"); 107 107 } 108 108 … … 112 112 int rc; 113 113 114 if (argc != 3) {114 if (argc != 2) { 115 115 print_syntax(); 116 116 return 1; 117 117 } 118 118 119 rc = conn_open(argv[1] , argv[2]);119 rc = conn_open(argv[1]); 120 120 if (rc != EOK) { 121 121 printf("Error connecting.\n"); -
uspace/app/ping/ping.c
r5147ff1 ra62ceaf 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <inet/dnsr.h>40 39 #include <inet/addr.h> 40 #include <inet/host.h> 41 41 #include <inet/inetping.h> 42 42 #include <io/console.h> … … 214 214 int main(int argc, char *argv[]) 215 215 { 216 dnsr_hostinfo_t *hinfo = NULL;217 216 char *asrc = NULL; 218 217 char *adest = NULL; 219 218 char *sdest = NULL; 219 char *host; 220 const char *errmsg; 220 221 ip_ver_t ip_ver = ip_any; 221 222 … … 260 261 } 261 262 262 /* Parse destination address */ 263 rc = inet_addr_parse(argv[optind], &dest_addr); 264 if (rc != EOK) { 265 /* Try interpreting as a host name */ 266 rc = dnsr_name2host(argv[optind], &hinfo, ip_ver); 267 if (rc != EOK) { 268 printf("Error resolving host '%s'.\n", argv[optind]); 269 goto error; 270 } 271 272 dest_addr = hinfo->addr; 263 host = argv[optind]; 264 265 /* Look up host */ 266 rc = inet_host_plookup_one(host, ip_ver, &dest_addr, NULL, &errmsg); 267 if (rc != EOK) { 268 printf("Error resolving host '%s' (%s).\n", host, errmsg); 269 goto error; 273 270 } 274 271 … … 292 289 } 293 290 294 if (hinfo != NULL) { 295 rc = asprintf(&sdest, "%s (%s)", hinfo->cname, adest); 296 if (rc < 0) { 297 printf("Out of memory.\n"); 298 goto error; 299 } 300 } else { 301 sdest = adest; 302 adest = NULL; 291 rc = asprintf(&sdest, "%s (%s)", host, adest); 292 if (rc < 0) { 293 printf("Out of memory.\n"); 294 goto error; 303 295 } 304 296 … … 330 322 free(adest); 331 323 free(sdest); 332 dnsr_hostinfo_destroy(hinfo);333 324 return 0; 334 325 … … 337 328 free(adest); 338 329 free(sdest); 339 dnsr_hostinfo_destroy(hinfo);340 330 return 1; 341 331 }
Note:
See TracChangeset
for help on using the changeset viewer.