Changeset 3e66428 in mainline
- Timestamp:
- 2013-06-20T14:10:51Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 19a4f73
- Parents:
- b49d872
- Location:
- uspace
- Files:
-
- 2 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dnscfg/dnscfg.c
rb49d872 r3e66428 36 36 37 37 #include <errno.h> 38 #include <inet/addr .h>38 #include <inet/addr2.h> 39 39 #include <inet/dnsr.h> 40 40 #include <ipc/services.h> … … 49 49 static void print_syntax(void) 50 50 { 51 printf("syntax:\n"); 52 printf("\t" NAME " set-ns <server-addr>\n"); 53 printf("\t" NAME " unset-ns\n"); 51 printf("Syntax:\n"); 52 printf("\t%s get-ns\n", NAME); 53 printf("\t%s set-ns <server-addr>\n", NAME); 54 printf("\t%s unset-ns\n", NAME); 54 55 } 55 56 56 57 static int dnscfg_set_ns(int argc, char *argv[]) 57 58 { 58 char *srv_addr;59 inet_addr_t addr;60 int rc;61 62 59 if (argc < 1) { 63 printf( NAME ": Missing arguments.\n");60 printf("%s: Missing arguments.\n", NAME); 64 61 print_syntax(); 65 62 return EINVAL; 66 63 } 67 64 68 65 if (argc > 1) { 69 printf( NAME ": Too many arguments.\n");66 printf("%s: Too many arguments.\n", NAME); 70 67 print_syntax(); 71 68 return EINVAL; 72 69 } 73 74 srv_addr = argv[0]; 75 76 rc = inet_addr_parse(srv_addr, &addr); 70 71 char *srv_addr = argv[0]; 72 73 inet2_addr_t addr; 74 int rc = inet2_addr_parse(srv_addr, &addr); 75 77 76 if (rc != EOK) { 78 printf( NAME ": Invalid address format '%s'.\n", srv_addr);79 return EINVAL;77 printf("%s: Invalid address format '%s'.\n", NAME, srv_addr); 78 return rc; 80 79 } 81 80 82 81 rc = dnsr_set_srvaddr(&addr); 83 82 if (rc != EOK) { 84 printf( NAME ": Failed settingserver address '%s' (%s)\n",85 srv_addr, str_error(rc));86 return EIO;83 printf("%s: Failed setting nameserver address '%s' (%s)\n", 84 NAME, srv_addr, str_error(rc)); 85 return rc; 87 86 } 88 87 89 88 return EOK; 90 89 } 91 90 92 static int dnscfg_unset_ns( int argc, char *argv[])91 static int dnscfg_unset_ns(void) 93 92 { 94 inet_addr_t addr; 95 int rc; 96 97 if (argc > 0) { 98 printf(NAME ": Too many arguments.\n"); 99 print_syntax(); 100 return EINVAL; 93 inet2_addr_t addr; 94 inet2_addr_empty(&addr); 95 96 int rc = dnsr_set_srvaddr(&addr); 97 if (rc != EOK) { 98 printf("%s: Failed unsetting server address (%s)\n", 99 NAME, str_error(rc)); 100 return rc; 101 101 } 102 103 addr.ipv4 = 0; 104 rc = dnsr_set_srvaddr(&addr); 105 if (rc != EOK) { 106 printf(NAME ": Failed unsetting server address (%s)\n", 107 str_error(rc)); 108 return EIO; 109 } 110 102 111 103 return EOK; 112 104 } … … 114 106 static int dnscfg_print(void) 115 107 { 116 inet_addr_t addr; 117 char *addr_str; 118 int rc; 119 120 rc = dnsr_get_srvaddr(&addr); 108 inet2_addr_t addr; 109 int rc = dnsr_get_srvaddr(&addr); 121 110 if (rc != EOK) { 122 printf( NAME ": Failed getting DNS server address.\n");111 printf("%s: Failed getting DNS server address.\n", NAME); 123 112 return rc; 124 113 } 125 126 rc = inet_addr_format(&addr, &addr_str); 114 115 char *addr_str; 116 rc = inet2_addr_format(&addr, &addr_str); 127 117 if (rc != EOK) { 128 printf( NAME ": Out of memory.\n");118 printf("%s: Out of memory.\n", NAME); 129 119 return rc; 130 120 } 131 132 printf(" Server: %s\n", addr_str);121 122 printf("Nameserver: %s\n", addr_str); 133 123 free(addr_str); 134 124 return EOK; … … 137 127 int main(int argc, char *argv[]) 138 128 { 139 int rc; 140 141 if (argc < 2) { 142 rc = dnscfg_print(); 143 if (rc != EOK) 144 return 1; 145 return 0; 146 } 147 148 if (str_cmp(argv[1], "set-ns") == 0) { 149 rc = dnscfg_set_ns(argc - 2, argv + 2); 150 if (rc != EOK) 151 return 1; 152 } else if (str_cmp(argv[1], "unset-ns") == 0) { 153 rc = dnscfg_unset_ns(argc - 2, argv + 2); 154 if (rc != EOK) 155 return 1; 156 } else { 157 printf(NAME ": Unknown command '%s'.\n", argv[1]); 129 if ((argc < 2) || (str_cmp(argv[1], "get-ns") == 0)) 130 return dnscfg_print(); 131 else if (str_cmp(argv[1], "set-ns") == 0) 132 return dnscfg_set_ns(argc - 2, argv + 2); 133 else if (str_cmp(argv[1], "unset-ns") == 0) 134 return dnscfg_unset_ns(); 135 else { 136 printf("%s: Unknown command '%s'.\n", NAME, argv[1]); 158 137 print_syntax(); 159 138 return 1; 160 139 } 161 162 140 163 141 return 0; 164 142 } -
uspace/app/dnsres/dnsres.c
rb49d872 r3e66428 34 34 35 35 #include <errno.h> 36 #include <inet/addr .h>36 #include <inet/addr2.h> 37 37 #include <inet/dnsr.h> 38 38 #include <stdio.h> … … 66 66 } 67 67 68 rc = inet _addr_format(&hinfo->addr, &saddr);68 rc = inet2_addr_format(&hinfo->addr, &saddr); 69 69 if (rc != EOK) { 70 70 dnsr_hostinfo_destroy(hinfo); -
uspace/app/nettest1/nettest1.c
rb49d872 r3e66428 359 359 return rc; 360 360 } 361 362 address_in.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4); 361 362 rc = inet2_addr_sockaddr_in(&hinfo->addr, &address_in); 363 if (rc != EOK) { 364 printf("Host '%s' not resolved as IPv4 address.\n", argv[argc - 1]); 365 return rc; 366 } 363 367 } 364 368 -
uspace/app/nettest2/nettest2.c
rb49d872 r3e66428 305 305 return rc; 306 306 } 307 308 address_in.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4); 307 308 rc = inet2_addr_sockaddr_in(&hinfo->addr, &address_in); 309 if (rc != EOK) { 310 printf("Host '%s' not resolved as IPv4 address.\n", argv[argc - 1]); 311 return rc; 312 } 309 313 } 310 314 -
uspace/app/nettest3/nettest3.c
rb49d872 r3e66428 83 83 return rc; 84 84 } 85 86 addr.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4); 87 addr.sin_family = AF_INET; 85 86 rc = inet2_addr_sockaddr_in(&hinfo->addr, &addr); 87 if (rc != EOK) { 88 printf("Host '%s' not resolved as IPv4 address.\n", argv[1]); 89 return rc; 90 } 88 91 } 89 92 printf("result: rc=%d, family=%d, addr=%x\n", rc, -
uspace/app/nterm/conn.c
rb49d872 r3e66428 90 90 goto error; 91 91 } 92 93 addr.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4); 92 93 rc = inet2_addr_sockaddr_in(&hinfo->addr, &addr); 94 if (rc != EOK) { 95 printf("Host '%s' not resolved as IPv4 address.\n", addr_s); 96 return rc; 97 } 94 98 } 95 99 -
uspace/app/ping/ping.c
rb49d872 r3e66428 63 63 }; 64 64 65 static inet_addr_t src_addr;66 static inet_addr_t dest_addr;65 static uint32_t src; 66 static uint32_t dest; 67 67 68 68 static bool ping_repeat = false; … … 83 83 static int ping_ev_recv(inetping_sdu_t *sdu) 84 84 { 85 char *asrc, *adest; 86 int rc; 87 88 rc = inet_addr_format(&sdu->src, &asrc); 85 inet2_addr_t src_addr; 86 inet2_addr_unpack(sdu->src, &src_addr); 87 88 inet2_addr_t dest_addr; 89 inet2_addr_unpack(sdu->dest, &dest_addr); 90 91 char *asrc; 92 int rc = inet2_addr_format(&src_addr, &asrc); 89 93 if (rc != EOK) 90 94 return ENOMEM; 91 92 rc = inet_addr_format(&sdu->dest, &adest); 95 96 char *adest; 97 rc = inet2_addr_format(&dest_addr, &adest); 93 98 if (rc != EOK) { 94 99 free(asrc); 95 100 return ENOMEM; 96 101 } 102 97 103 printf("Received ICMP echo reply: from %s to %s, seq. no %u, " 98 104 "payload size %zu\n", asrc, adest, sdu->seq_no, sdu->size); 99 100 if (!ping_repeat) {105 106 if (!ping_repeat) 101 107 ping_signal_done(); 102 } 103 108 104 109 free(asrc); 105 110 free(adest); … … 112 117 int rc; 113 118 114 sdu.src = src _addr;115 sdu.dest = dest _addr;119 sdu.src = src; 120 sdu.dest = dest; 116 121 sdu.seq_no = seq_no; 117 122 sdu.data = (void *) "foo"; … … 202 207 203 208 /* Parse destination address */ 204 rc = inet_addr_parse(argv[argi], &dest_addr); 209 inet2_addr_t dest_addr; 210 rc = inet2_addr_parse(argv[argi], &dest_addr); 205 211 if (rc != EOK) { 206 212 /* Try interpreting as a host name */ … … 210 216 goto error; 211 217 } 212 218 213 219 dest_addr = hinfo->addr; 214 220 } 215 221 222 rc = inet2_addr_pack(&dest_addr, &dest); 223 if (rc != EOK) { 224 printf(NAME ": Destination '%s' is not an IPv4 address.\n", 225 argv[argi]); 226 goto error; 227 } 228 216 229 /* Determine source address */ 217 rc = inetping_get_srcaddr( &dest_addr, &src_addr);230 rc = inetping_get_srcaddr(dest, &src); 218 231 if (rc != EOK) { 219 232 printf(NAME ": Failed determining source address.\n"); 220 233 goto error; 221 234 } 222 223 rc = inet_addr_format(&src_addr, &asrc); 235 236 inet2_addr_t src_addr; 237 inet2_addr_unpack(src, &src_addr); 238 239 rc = inet2_addr_format(&src_addr, &asrc); 224 240 if (rc != EOK) { 225 241 printf(NAME ": Out of memory.\n"); 226 242 goto error; 227 243 } 228 229 rc = inet _addr_format(&dest_addr, &adest);244 245 rc = inet2_addr_format(&dest_addr, &adest); 230 246 if (rc != EOK) { 231 247 printf(NAME ": Out of memory.\n"); 232 248 goto error; 233 249 } 234 250 235 251 if (hinfo != NULL) { 236 252 rc = asprintf(&sdest, "%s (%s)", hinfo->cname, adest); … … 287 303 dnsr_hostinfo_destroy(hinfo); 288 304 return 0; 305 289 306 error: 290 307 free(asrc); -
uspace/lib/c/Makefile
rb49d872 r3e66428 93 93 generic/futex.c \ 94 94 generic/inet/addr.c \ 95 generic/inet/addr2.c \ 95 96 generic/inet.c \ 96 97 generic/inetcfg.c \ -
uspace/lib/c/generic/dnsr.c
rb49d872 r3e66428 44 44 static async_exch_t *dnsr_exchange_begin(void) 45 45 { 46 async_sess_t *sess;47 service_id_t dnsr_svc;48 49 46 fibril_mutex_lock(&dnsr_sess_mutex); 50 47 51 48 if (dnsr_sess == NULL) { 49 service_id_t dnsr_svc; 50 52 51 (void) loc_service_get_id(SERVICE_NAME_DNSR, &dnsr_svc, 53 52 IPC_FLAG_BLOCKING); 54 53 55 54 dnsr_sess = loc_service_connect(EXCHANGE_SERIALIZE, dnsr_svc, 56 55 IPC_FLAG_BLOCKING); 57 56 } 58 59 sess = dnsr_sess;57 58 async_sess_t *sess = dnsr_sess; 60 59 fibril_mutex_unlock(&dnsr_sess_mutex); 61 60 62 61 return async_exchange_begin(sess); 63 62 } … … 109 108 110 109 info->cname = str_dup(cname_buf); 111 in fo->addr.ipv4 = IPC_GET_ARG1(answer);110 inet2_addr_unpack(IPC_GET_ARG1(answer), &info->addr); 112 111 113 112 *rinfo = info; … … 119 118 if (info == NULL) 120 119 return; 121 120 122 121 free(info->cname); 123 122 free(info); 124 123 } 125 124 126 int dnsr_get_srvaddr(inet _addr_t *srvaddr)125 int dnsr_get_srvaddr(inet2_addr_t *srvaddr) 127 126 { 128 sysarg_t addr;129 127 async_exch_t *exch = dnsr_exchange_begin(); 130 131 int rc = async_req_0_1(exch, DNSR_GET_SRVADDR, &addr); 132 dnsr_exchange_end(exch); 133 134 if (rc != EOK) 128 129 ipc_call_t answer; 130 aid_t req = async_send_0(exch, DNSR_GET_SRVADDR, &answer); 131 int rc = async_data_read_start(exch, srvaddr, sizeof(inet2_addr_t)); 132 133 loc_exchange_end(exch); 134 135 if (rc != EOK) { 136 async_forget(req); 135 137 return rc; 136 137 srvaddr->ipv4 = addr; 138 return EOK; 138 } 139 140 sysarg_t retval; 141 async_wait_for(req, &retval); 142 143 return (int) retval; 139 144 } 140 145 141 int dnsr_set_srvaddr(inet _addr_t *srvaddr)146 int dnsr_set_srvaddr(inet2_addr_t *srvaddr) 142 147 { 143 148 async_exch_t *exch = dnsr_exchange_begin(); 144 145 int rc = async_req_1_0(exch, DNSR_SET_SRVADDR, srvaddr->ipv4); 146 dnsr_exchange_end(exch); 147 148 if (rc != EOK) 149 150 ipc_call_t answer; 151 aid_t req = async_send_0(exch, DNSR_SET_SRVADDR, &answer); 152 int rc = async_data_write_start(exch, srvaddr, sizeof(inet2_addr_t)); 153 154 loc_exchange_end(exch); 155 156 if (rc != EOK) { 157 async_forget(req); 149 158 return rc; 150 151 return EOK; 159 } 160 161 sysarg_t retval; 162 async_wait_for(req, &retval); 163 164 return (int) retval; 152 165 } 153 166 -
uspace/lib/c/generic/inetping.c
rb49d872 r3e66428 79 79 { 80 80 async_exch_t *exch = async_exchange_begin(inetping_sess); 81 81 82 82 ipc_call_t answer; 83 aid_t req = async_send_3(exch, INETPING_SEND, sdu->src.ipv4,84 sdu->dest.ipv4, sdu->seq_no, &answer);83 aid_t req = async_send_3(exch, INETPING_SEND, (sysarg_t) sdu->src, 84 (sysarg_t) sdu->dest, sdu->seq_no, &answer); 85 85 sysarg_t retval = async_data_write_start(exch, sdu->data, sdu->size); 86 86 87 87 async_exchange_end(exch); 88 88 89 89 if (retval != EOK) { 90 90 async_forget(req); 91 91 return retval; 92 92 } 93 93 94 94 async_wait_for(req, &retval); 95 95 return retval; 96 96 } 97 97 98 int inetping_get_srcaddr( inet_addr_t *remote, inet_addr_t *local)98 int inetping_get_srcaddr(uint32_t remote, uint32_t *local) 99 99 { 100 async_exch_t *exch = async_exchange_begin(inetping_sess); 101 100 102 sysarg_t local_addr; 101 async_exch_t *exch = async_exchange_begin(inetping_sess); 102 103 int rc = async_req_1_1(exch, INETPING_GET_SRCADDR, remote->ipv4, 103 int rc = async_req_1_1(exch, INETPING_GET_SRCADDR, (sysarg_t) remote, 104 104 &local_addr); 105 105 106 async_exchange_end(exch); 106 107 107 108 if (rc != EOK) 108 109 return rc; 109 110 local->ipv4 =local_addr;110 111 *local = (uint32_t) local_addr; 111 112 return EOK; 112 113 } … … 114 115 static void inetping_ev_recv(ipc_callid_t callid, ipc_call_t *call) 115 116 { 116 int rc;117 117 inetping_sdu_t sdu; 118 119 sdu.src .ipv4= IPC_GET_ARG1(*call);120 sdu.dest .ipv4= IPC_GET_ARG2(*call);118 119 sdu.src = IPC_GET_ARG1(*call); 120 sdu.dest = IPC_GET_ARG2(*call); 121 121 sdu.seq_no = IPC_GET_ARG3(*call); 122 123 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size);122 123 int rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size); 124 124 if (rc != EOK) { 125 125 async_answer_0(callid, rc); 126 126 return; 127 127 } 128 128 129 129 rc = inetping_ev_ops->recv(&sdu); 130 130 free(sdu.data); -
uspace/lib/c/generic/net/inet.c
rb49d872 r3e66428 94 94 } 95 95 96 static int inet_pton4(const char *address, uint8_t *data) 97 { 98 memset(data, 0, 4); 99 100 const char *cur = address; 101 size_t i = 0; 102 103 while (i < 4) { 104 int rc = str_uint8_t(cur, &cur, 10, false, &data[i]); 105 if (rc != EOK) 106 return rc; 107 108 i++; 109 110 if (*cur == 0) 111 break; 112 113 if (*cur != '.') 114 return EINVAL; 115 116 if (i < 4) 117 cur++; 118 } 119 120 if ((i == 4) && (*cur != 0)) 121 return EINVAL; 122 123 return EOK; 124 } 125 126 static int inet_pton6(const char *address, uint8_t *data) 127 { 128 // FIXME TODO 129 return ENOTSUP; 130 } 131 96 132 /** Parses the character string into the address. 97 133 * 98 * If the string is shorter than the full address, zero bytes are added. 134 * @param[in] family The address family. 135 * @param[in] address The character buffer to be parsed. 136 * @param[out] data The address data to be filled. 99 137 * 100 * @param[in] family The address family. 101 * @param[in] address The character buffer to be parsed. 102 * @param[out] data The address data to be filled. 103 * @return EOK on success. 104 * @return EINVAL if the data parameter is NULL. 105 * @return ENOENT if the address parameter is NULL. 106 * @return ENOTSUP if the address family is not supported. 138 * @return EOK on success. 139 * @return EINVAL if the data parameter is NULL. 140 * @return ENOENT if the address parameter is NULL. 141 * @return ENOTSUP if the address family is not supported. 142 * 107 143 */ 108 144 int inet_pton(uint16_t family, const char *address, uint8_t *data) 109 145 { 110 /** The base number of the values. */111 int base;112 /** The number of bytes per a section. */113 size_t bytes;114 /** The number of bytes of the address data. */115 int count;116 117 const char *next;118 char *last;119 int index;120 size_t shift;121 unsigned long value;122 123 if (!data)124 return EINVAL;125 126 /* Set processing parameters */127 146 switch (family) { 128 147 case AF_INET: 129 count = 4; 130 base = 10; 131 bytes = 1; 132 break; 133 148 return inet_pton4(address, data); 134 149 case AF_INET6: 135 count = 16; 136 base = 16; 137 bytes = 4; 138 break; 139 150 return inet_pton6(address, data); 140 151 default: 152 /** Unknown address family */ 141 153 return ENOTSUP; 142 154 } 143 144 /* Erase if no address */145 if (!address) {146 memset(data, 0, count);147 return ENOENT;148 }149 150 /* Process string from the beginning */151 next = address;152 index = 0;153 do {154 /* If the actual character is set */155 if (next && *next) {156 157 /* If not on the first character */158 if (index) {159 /* Move to the next character */160 ++next;161 }162 163 /* Parse the actual integral value */164 value = strtoul(next, &last, base);165 /*166 * Remember the last problematic character167 * should be either '.' or ':' but is ignored to be168 * more generic169 */170 next = last;171 172 /* Fill the address data byte by byte */173 shift = bytes - 1;174 do {175 /* like little endian */176 data[index + shift] = value;177 value >>= 8;178 } while(shift --);179 180 index += bytes;181 } else {182 /* Erase the rest of the address */183 memset(data + index, 0, count - index);184 return EOK;185 }186 } while (index < count);187 188 return EOK;189 155 } 190 156 -
uspace/lib/c/include/inet/dnsr.h
rb49d872 r3e66428 37 37 38 38 #include <inet/inet.h> 39 #include <inet/addr2.h> 39 40 40 41 enum { … … 46 47 char *cname; 47 48 /** Host address */ 48 inet _addr_t addr;49 inet2_addr_t addr; 49 50 } dnsr_hostinfo_t; 50 51 … … 52 53 extern int dnsr_name2host(const char *, dnsr_hostinfo_t **); 53 54 extern void dnsr_hostinfo_destroy(dnsr_hostinfo_t *); 54 extern int dnsr_get_srvaddr(inet _addr_t *);55 extern int dnsr_set_srvaddr(inet _addr_t *);55 extern int dnsr_get_srvaddr(inet2_addr_t *); 56 extern int dnsr_set_srvaddr(inet2_addr_t *); 56 57 57 58 #endif -
uspace/lib/c/include/inet/inetping.h
rb49d872 r3e66428 40 40 41 41 typedef struct { 42 inet_addr_t src;43 inet_addr_t dest;42 uint32_t src; 43 uint32_t dest; 44 44 uint16_t seq_no; 45 45 void *data; … … 53 53 extern int inetping_init(inetping_ev_ops_t *); 54 54 extern int inetping_send(inetping_sdu_t *); 55 extern int inetping_get_srcaddr(inet_addr_t *, inet_addr_t *); 56 55 extern int inetping_get_srcaddr(uint32_t, uint32_t *); 57 56 58 57 #endif -
uspace/lib/c/include/net/socket_codes.h
rb49d872 r3e66428 45 45 46 46 enum { 47 AF_ UNKNOWN= 0,47 AF_NONE = 0, 48 48 AF_INET, /* IPv4 address */ 49 49 AF_INET6 /* IPv6 address */ -
uspace/srv/net/dnsrsrv/dns_msg.c
rb49d872 r3e66428 299 299 assert(buf_size >= 4); 300 300 301 w = ((uint32_t) buf[0] << 24) +302 ((uint32_t) buf[1] << 16) +303 ((uint32_t) buf[2] << 8) +301 w = ((uint32_t) buf[0] << 24) + 302 ((uint32_t) buf[1] << 16) + 303 ((uint32_t) buf[2] << 8) + 304 304 buf[3]; 305 305 -
uspace/srv/net/dnsrsrv/dns_type.h
rb49d872 r3e66428 39 39 #include <adt/list.h> 40 40 #include <inet/inet.h> 41 #include <inet/addr2.h> 41 42 #include <stdbool.h> 42 43 #include <stdint.h> … … 115 116 char *cname; 116 117 /** Host address */ 117 inet _addr_t addr;118 inet2_addr_t addr; 118 119 } dns_host_info_t; 119 120 -
uspace/srv/net/dnsrsrv/dnsrsrv.c
rb49d872 r3e66428 116 116 return; 117 117 } 118 119 uint32_t addr; 120 rc = inet2_addr_pack(&hinfo->addr, &addr); 121 if (rc != EOK) { 122 async_answer_0(rcallid, rc); 123 async_answer_0(callid, rc); 124 return; 125 } 118 126 119 127 act_size = str_size(hinfo->cname); … … 125 133 126 134 retval = async_data_read_finalize(rcallid, hinfo->cname, act_size); 127 async_answer_1(callid, retval, hinfo->addr.ipv4);135 async_answer_1(callid, retval, (sysarg_t) addr); 128 136 129 137 dns_hostinfo_destroy(hinfo); 130 138 } 131 139 132 static void dnsr_get_srvaddr_srv(dnsr_client_t *client, ipc_callid_t callid,133 ipc_call_t * call)140 static void dnsr_get_srvaddr_srv(dnsr_client_t *client, ipc_callid_t iid, 141 ipc_call_t *icall) 134 142 { 135 143 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srvaddr_srv()"); 136 async_answer_1(callid, EOK, dns_server_addr.ipv4); 137 } 138 139 static void dnsr_set_srvaddr_srv(dnsr_client_t *client, ipc_callid_t callid, 140 ipc_call_t *call) 144 145 ipc_callid_t callid; 146 size_t size; 147 if (!async_data_read_receive(&callid, &size)) { 148 async_answer_0(callid, EREFUSED); 149 async_answer_0(iid, EREFUSED); 150 return; 151 } 152 153 if (size != sizeof(inet2_addr_t)) { 154 async_answer_0(callid, EINVAL); 155 async_answer_0(iid, EINVAL); 156 return; 157 } 158 159 // FIXME locking 160 161 sysarg_t retval = 162 async_data_read_finalize(callid, &dns_server_addr, size); 163 async_answer_0(iid, retval); 164 } 165 166 static void dnsr_set_srvaddr_srv(dnsr_client_t *client, ipc_callid_t iid, 167 ipc_call_t *icall) 141 168 { 142 169 log_msg(LOG_DEFAULT, LVL_DEBUG, "dnsr_set_srvaddr_srv()"); 143 144 dns_server_addr.ipv4 = IPC_GET_ARG1(*call); 145 146 async_answer_0(callid, EOK); 170 171 ipc_callid_t callid; 172 size_t size; 173 if (!async_data_write_receive(&callid, &size)) { 174 async_answer_0(callid, EREFUSED); 175 async_answer_0(iid, EREFUSED); 176 return; 177 } 178 179 if (size != sizeof(inet2_addr_t)) { 180 async_answer_0(callid, EINVAL); 181 async_answer_0(iid, EINVAL); 182 return; 183 } 184 185 // FIXME locking 186 187 sysarg_t retval = 188 async_data_write_finalize(callid, &dns_server_addr, size); 189 async_answer_0(iid, retval); 147 190 } 148 191 -
uspace/srv/net/dnsrsrv/query.c
rb49d872 r3e66428 128 128 129 129 info->cname = str_dup(rr->name); 130 info->addr.ipv4 = dns_uint32_t_decode(rr->rdata, rr->rdata_size); 131 log_msg(LOG_DEFAULT, LVL_DEBUG, "info->name = '%s' " 132 "info->addr = %x", info->cname, info->addr.ipv4); 133 130 inet2_addr_unpack(dns_uint32_t_decode(rr->rdata, rr->rdata_size), 131 &info->addr); 132 134 133 dns_message_destroy(msg); 135 134 dns_message_destroy(amsg); -
uspace/srv/net/dnsrsrv/transport.c
rb49d872 r3e66428 52 52 53 53 /** Request timeout (microseconds) */ 54 #define REQ_TIMEOUT (5 *1000*1000)54 #define REQ_TIMEOUT (5 * 1000 * 1000) 55 55 56 56 /** Maximum number of retries */ 57 57 #define REQ_RETRY_MAX 3 58 59 inet2_addr_t dns_server_addr; 58 60 59 61 typedef struct { … … 72 74 static fid_t recv_fid; 73 75 static int transport_fd = -1; 74 inet_addr_t dns_server_addr;75 76 76 77 /** Outstanding requests */ … … 194 195 addr.sin_family = AF_INET; 195 196 addr.sin_port = htons(DNS_SERVER_PORT); 196 addr.sin_addr.s_addr = host2uint32_t_be(dns_server_addr.ipv4);197 inet2_addr_sockaddr_in(&dns_server_addr, &addr); 197 198 198 199 rc = dns_message_encode(req, &req_data, &req_size); … … 204 205 while (ntry < REQ_RETRY_MAX) { 205 206 rc = sendto(transport_fd, req_data, req_size, 0, 206 (struct sockaddr *) &addr, sizeof(addr));207 (struct sockaddr *) &addr, sizeof(addr)); 207 208 if (rc != EOK) 208 209 goto error; -
uspace/srv/net/dnsrsrv/transport.h
rb49d872 r3e66428 37 37 #define TRANSPORT_H 38 38 39 #include <inet/addr .h>39 #include <inet/addr2.h> 40 40 #include "dns_type.h" 41 42 extern inet2_addr_t dns_server_addr; 41 43 42 44 extern int transport_init(void); … … 44 46 extern int dns_request(dns_message_t *, dns_message_t **); 45 47 46 extern inet_addr_t dns_server_addr;47 48 49 48 #endif 50 49
Note:
See TracChangeset
for help on using the changeset viewer.