Changeset bdae198 in mainline for uspace/lib
- Timestamp:
- 2013-08-04T12:01:10Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ea509069
- Parents:
- b08879c2 (diff), d856110 (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/lib
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/dnsr.c
rb08879c2 rbdae198 67 67 } 68 68 69 int dnsr_name2host(const char *name, dnsr_hostinfo_t **rinfo )69 int dnsr_name2host(const char *name, dnsr_hostinfo_t **rinfo, uint16_t af) 70 70 { 71 71 dnsr_hostinfo_t *info = calloc(1, sizeof(dnsr_hostinfo_t)); … … 76 76 77 77 ipc_call_t answer; 78 aid_t req = async_send_0(exch, DNSR_NAME2HOST, &answer); 78 aid_t req = async_send_1(exch, DNSR_NAME2HOST, (sysarg_t) af, 79 &answer); 79 80 80 81 int rc = async_data_write_start(exch, name, str_size(name)); -
uspace/lib/c/generic/inet/addr.c
rb08879c2 rbdae198 52 52 }; 53 53 54 static const addr48_t inet_addr48_solicited_node = { 55 0x33, 0x33, 0xff, 0, 0, 0 56 }; 57 54 58 static const inet_addr_t inet_addr_any_addr = { 55 59 .family = AF_INET, … … 70 74 { 71 75 memcpy(dst, src, 16); 76 } 77 78 int addr48_compare(const addr48_t a, const addr48_t b) 79 { 80 return memcmp(a, b, 6); 81 } 82 83 int addr128_compare(const addr128_t a, const addr128_t b) 84 { 85 return memcmp(a, b, 16); 86 } 87 88 /** Compute solicited node MAC multicast address from target IPv6 address 89 * 90 * @param ip Target IPv6 address 91 * @param mac Solicited MAC address to be assigned 92 * 93 */ 94 void addr48_solicited_node(const addr128_t ip, addr48_t mac) 95 { 96 memcpy(mac, inet_addr48_solicited_node, 3); 97 memcpy(mac + 3, ip + 13, 3); 72 98 } 73 99 … … 212 238 } 213 239 240 void inet_addr_naddr(const inet_addr_t *addr, uint8_t prefix, 241 inet_naddr_t *naddr) 242 { 243 naddr->family = addr->family; 244 memcpy(naddr->addr6, addr->addr6, 16); 245 naddr->prefix = prefix; 246 } 247 214 248 void inet_addr_any(inet_addr_t *addr) 215 249 { … … 234 268 return (a->addr == b->addr); 235 269 case AF_INET6: 236 return memcmp(&a->addr6, &b->addr6, 16);270 return addr128_compare(a->addr6, b->addr6); 237 271 default: 238 272 return 0; … … 245 279 (inet_addr_compare(addr, &inet_addr_any_addr)) || 246 280 (inet_addr_compare(addr, &inet_addr_any_addr6))); 281 } 282 283 int inet_naddr_compare(const inet_naddr_t *naddr, const inet_addr_t *addr) 284 { 285 if (naddr->family != addr->family) 286 return 0; 287 288 switch (naddr->family) { 289 case AF_INET: 290 return (naddr->addr == addr->addr); 291 case AF_INET6: 292 return addr128_compare(naddr->addr6, addr->addr6); 293 default: 294 return 0; 295 } 247 296 } 248 297 -
uspace/lib/c/generic/inetping6.c
rb08879c2 rbdae198 79 79 80 80 ipc_call_t answer; 81 aid_t req = async_send_3(exch, INETPING6_SEND, (sysarg_t) sdu->src, 82 (sysarg_t) sdu->dest, sdu->seq_no, &answer); 83 sysarg_t retval = async_data_write_start(exch, sdu->data, sdu->size); 81 aid_t req = async_send_1(exch, INETPING6_SEND, sdu->seq_no, &answer); 82 83 int rc = async_data_write_start(exch, &sdu->src, sizeof(addr128_t)); 84 if (rc != EOK) { 85 async_exchange_end(exch); 86 async_forget(req); 87 return rc; 88 } 89 90 rc = async_data_write_start(exch, &sdu->dest, sizeof(addr128_t)); 91 if (rc != EOK) { 92 async_exchange_end(exch); 93 async_forget(req); 94 return rc; 95 } 96 97 rc = async_data_write_start(exch, sdu->data, sdu->size); 84 98 85 99 async_exchange_end(exch); 86 100 87 if (retval != EOK) { 88 async_forget(req); 89 return retval; 90 } 91 101 if (rc != EOK) { 102 async_forget(req); 103 return rc; 104 } 105 106 sysarg_t retval; 92 107 async_wait_for(req, &retval); 93 return retval; 108 109 return (int) retval; 94 110 } 95 111 … … 142 158 } 143 159 144 if (size != sizeof( inet_addr_t)) {160 if (size != sizeof(addr128_t)) { 145 161 async_answer_0(callid, EINVAL); 146 162 async_answer_0(iid, EINVAL); … … 161 177 } 162 178 163 if (size != sizeof( inet_addr_t)) {179 if (size != sizeof(addr128_t)) { 164 180 async_answer_0(callid, EINVAL); 165 181 async_answer_0(iid, EINVAL); -
uspace/lib/c/generic/iplink.c
rb08879c2 rbdae198 86 86 87 87 ipc_call_t answer; 88 aid_t req = async_send_0(exch, IPLINK_SEND, &answer); 89 90 int rc = async_data_write_start(exch, &sdu->src, sizeof(inet_addr_t)); 88 aid_t req = async_send_2(exch, IPLINK_SEND, (sysarg_t) sdu->src, 89 (sysarg_t) sdu->dest, &answer); 90 91 int rc = async_data_write_start(exch, sdu->data, sdu->size); 92 93 async_exchange_end(exch); 94 95 if (rc != EOK) { 96 async_forget(req); 97 return rc; 98 } 99 100 sysarg_t retval; 101 async_wait_for(req, &retval); 102 103 return (int) retval; 104 } 105 106 int iplink_send6(iplink_t *iplink, iplink_sdu6_t *sdu) 107 { 108 async_exch_t *exch = async_exchange_begin(iplink->sess); 109 110 ipc_call_t answer; 111 aid_t req = async_send_0(exch, IPLINK_SEND6, &answer); 112 113 int rc = async_data_write_start(exch, &sdu->dest, sizeof(addr48_t)); 91 114 if (rc != EOK) { 92 115 async_exchange_end(exch); … … 95 118 } 96 119 97 rc = async_data_write_start(exch, &sdu->dest, sizeof(inet_addr_t));98 if (rc != EOK) {99 async_exchange_end(exch);100 async_forget(req);101 return rc;102 }103 104 120 rc = async_data_write_start(exch, sdu->data, sdu->size); 105 121 … … 119 135 int iplink_get_mtu(iplink_t *iplink, size_t *rmtu) 120 136 { 137 async_exch_t *exch = async_exchange_begin(iplink->sess); 138 121 139 sysarg_t mtu; 122 async_exch_t *exch = async_exchange_begin(iplink->sess);123 124 140 int rc = async_req_0_1(exch, IPLINK_GET_MTU, &mtu); 125 async_exchange_end(exch); 126 141 142 async_exchange_end(exch); 143 127 144 if (rc != EOK) 128 145 return rc; 129 146 130 147 *rmtu = mtu; 131 148 return EOK; 149 } 150 151 int iplink_get_mac48(iplink_t *iplink, addr48_t *mac) 152 { 153 async_exch_t *exch = async_exchange_begin(iplink->sess); 154 155 ipc_call_t answer; 156 aid_t req = async_send_0(exch, IPLINK_GET_MAC48, &answer); 157 158 int rc = async_data_read_start(exch, mac, sizeof(addr48_t)); 159 160 loc_exchange_end(exch); 161 162 if (rc != EOK) { 163 async_forget(req); 164 return rc; 165 } 166 167 sysarg_t retval; 168 async_wait_for(req, &retval); 169 170 return (int) retval; 132 171 } 133 172 -
uspace/lib/c/generic/iplink_srv.c
rb08879c2 rbdae198 50 50 } 51 51 52 static void iplink_get_mac48_srv(iplink_srv_t *srv, ipc_callid_t iid, 53 ipc_call_t *icall) 54 { 55 addr48_t mac; 56 int rc = srv->ops->get_mac48(srv, &mac); 57 if (rc != EOK) { 58 async_answer_0(iid, rc); 59 return; 60 } 61 62 ipc_callid_t callid; 63 size_t size; 64 if (!async_data_read_receive(&callid, &size)) { 65 async_answer_0(callid, EREFUSED); 66 async_answer_0(iid, EREFUSED); 67 return; 68 } 69 70 if (size != sizeof(addr48_t)) { 71 async_answer_0(callid, EINVAL); 72 async_answer_0(iid, EINVAL); 73 return; 74 } 75 76 rc = async_data_read_finalize(callid, &mac, size); 77 if (rc != EOK) 78 async_answer_0(callid, rc); 79 80 async_answer_0(iid, (sysarg_t) rc); 81 } 82 52 83 static void iplink_addr_add_srv(iplink_srv_t *srv, ipc_callid_t iid, 53 84 ipc_call_t *icall) … … 111 142 iplink_sdu_t sdu; 112 143 144 sdu.src = IPC_GET_ARG1(*icall); 145 sdu.dest = IPC_GET_ARG2(*icall); 146 147 int rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, 148 &sdu.size); 149 if (rc != EOK) { 150 async_answer_0(iid, rc); 151 return; 152 } 153 154 rc = srv->ops->send(srv, &sdu); 155 free(sdu.data); 156 async_answer_0(iid, rc); 157 } 158 159 static void iplink_send6_srv(iplink_srv_t *srv, ipc_callid_t iid, 160 ipc_call_t *icall) 161 { 162 iplink_sdu6_t sdu; 163 113 164 ipc_callid_t callid; 114 165 size_t size; … … 119 170 } 120 171 121 if (size != sizeof( inet_addr_t)) {172 if (size != sizeof(addr48_t)) { 122 173 async_answer_0(callid, EINVAL); 123 174 async_answer_0(iid, EINVAL); … … 125 176 } 126 177 127 int rc = async_data_write_finalize(callid, &sdu. src, size);178 int rc = async_data_write_finalize(callid, &sdu.dest, size); 128 179 if (rc != EOK) { 129 180 async_answer_0(callid, (sysarg_t) rc); … … 131 182 } 132 183 133 if (!async_data_write_receive(&callid, &size)) {134 async_answer_0(callid, EREFUSED);135 async_answer_0(iid, EREFUSED);136 return;137 }138 139 if (size != sizeof(inet_addr_t)) {140 async_answer_0(callid, EINVAL);141 async_answer_0(iid, EINVAL);142 return;143 }144 145 rc = async_data_write_finalize(callid, &sdu.dest, size);146 if (rc != EOK) {147 async_answer_0(callid, (sysarg_t) rc);148 async_answer_0(iid, (sysarg_t) rc);149 }150 151 184 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, 152 185 &sdu.size); 153 if (rc != EOK) 154 return; 155 156 rc = srv->ops->send(srv, &sdu); 186 if (rc != EOK) { 187 async_answer_0(iid, rc); 188 return; 189 } 190 191 rc = srv->ops->send6(srv, &sdu); 157 192 free(sdu.data); 158 193 async_answer_0(iid, rc); … … 170 205 int iplink_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 171 206 { 172 iplink_srv_t *srv = (iplink_srv_t *) arg;207 iplink_srv_t *srv = (iplink_srv_t *) arg; 173 208 int rc; 174 209 … … 214 249 iplink_get_mtu_srv(srv, callid, &call); 215 250 break; 251 case IPLINK_GET_MAC48: 252 iplink_get_mac48_srv(srv, callid, &call); 253 break; 216 254 case IPLINK_SEND: 217 255 iplink_send_srv(srv, callid, &call); 256 break; 257 case IPLINK_SEND6: 258 iplink_send6_srv(srv, callid, &call); 218 259 break; 219 260 case IPLINK_ADDR_ADD: -
uspace/lib/c/generic/net/socket_parse.c
rb08879c2 rbdae198 53 53 int socket_parse_address_family(const char *name, int *af) 54 54 { 55 if (str_lcmp(name, "AF_INET ", 7) == 0) {56 *af = AF_INET ;55 if (str_lcmp(name, "AF_INET6", 8) == 0) { 56 *af = AF_INET6; 57 57 return EOK; 58 58 } 59 59 60 if (str_lcmp(name, "AF_INET 6", 8) == 0) {61 *af = AF_INET 6;60 if (str_lcmp(name, "AF_INET", 7) == 0) { 61 *af = AF_INET; 62 62 return EOK; 63 63 } -
uspace/lib/c/include/inet/addr.h
rb08879c2 rbdae198 73 73 extern void addr128(const addr128_t, addr128_t); 74 74 75 extern int addr48_compare(const addr48_t, const addr48_t); 76 extern int addr128_compare(const addr128_t, const addr128_t); 77 78 extern void addr48_solicited_node(const addr128_t, addr48_t); 79 75 80 extern void host2addr128_t_be(const addr128_t, addr128_t); 76 81 extern void addr128_t_be2host(const addr128_t, addr128_t); … … 87 92 extern int inet_addr_family(const char *, uint16_t *); 88 93 extern void inet_naddr_addr(const inet_naddr_t *, inet_addr_t *); 94 extern void inet_addr_naddr(const inet_addr_t *, uint8_t, inet_naddr_t *); 89 95 90 96 extern void inet_addr_any(inet_addr_t *); … … 94 100 extern int inet_addr_is_any(const inet_addr_t *); 95 101 102 extern int inet_naddr_compare(const inet_naddr_t *, const inet_addr_t *); 96 103 extern int inet_naddr_compare_mask(const inet_naddr_t *, const inet_addr_t *); 97 104 -
uspace/lib/c/include/inet/dnsr.h
rb08879c2 rbdae198 51 51 52 52 extern int dnsr_init(void); 53 extern int dnsr_name2host(const char *, dnsr_hostinfo_t ** );53 extern int dnsr_name2host(const char *, dnsr_hostinfo_t **, uint16_t); 54 54 extern void dnsr_hostinfo_destroy(dnsr_hostinfo_t *); 55 55 extern int dnsr_get_srvaddr(inet_addr_t *); -
uspace/lib/c/include/inet/iplink.h
rb08879c2 rbdae198 47 47 } iplink_t; 48 48 49 /** I nternetlink Service Data Unit */49 /** IPv4 link Service Data Unit */ 50 50 typedef struct { 51 51 /** Local source address */ 52 inet_addr_t src;52 addr32_t src; 53 53 /** Local destination address */ 54 inet_addr_t dest;54 addr32_t dest; 55 55 /** Serialized IP packet */ 56 56 void *data; … … 58 58 size_t size; 59 59 } iplink_sdu_t; 60 61 /** IPv6 link Service Data Unit */ 62 typedef struct { 63 /** Local MAC destination address */ 64 addr48_t dest; 65 /** Serialized IP packet */ 66 void *data; 67 /** Size of @c data in bytes */ 68 size_t size; 69 } iplink_sdu6_t; 60 70 61 71 /** Internet link receive Service Data Unit */ … … 74 84 extern void iplink_close(iplink_t *); 75 85 extern int iplink_send(iplink_t *, iplink_sdu_t *); 86 extern int iplink_send6(iplink_t *, iplink_sdu6_t *); 76 87 extern int iplink_addr_add(iplink_t *, inet_addr_t *); 77 88 extern int iplink_addr_remove(iplink_t *, inet_addr_t *); 78 89 extern int iplink_get_mtu(iplink_t *, size_t *); 90 extern int iplink_get_mac48(iplink_t *, addr48_t *); 79 91 80 92 #endif -
uspace/lib/c/include/inet/iplink_srv.h
rb08879c2 rbdae198 57 57 int (*close)(iplink_srv_t *); 58 58 int (*send)(iplink_srv_t *, iplink_sdu_t *); 59 int (*send6)(iplink_srv_t *, iplink_sdu6_t *); 59 60 int (*get_mtu)(iplink_srv_t *, size_t *); 61 int (*get_mac48)(iplink_srv_t *, addr48_t *); 60 62 int (*addr_add)(iplink_srv_t *, inet_addr_t *); 61 63 int (*addr_remove)(iplink_srv_t *, inet_addr_t *); -
uspace/lib/c/include/ipc/iplink.h
rb08879c2 rbdae198 40 40 typedef enum { 41 41 IPLINK_GET_MTU = IPC_FIRST_USER_METHOD, 42 IPLINK_GET_MAC48, 42 43 IPLINK_SEND, 44 IPLINK_SEND6, 43 45 IPLINK_ADDR_ADD, 44 46 IPLINK_ADDR_REMOVE -
uspace/lib/posix/include/posix/stdio.h
rb08879c2 rbdae198 65 65 66 66 #define BUFSIZ 4096 67 #define SEEK_SET 068 #define SEEK_CUR 169 #define SEEK_END 270 67 71 68 typedef struct _IO_FILE FILE; -
uspace/lib/posix/include/posix/stdlib.h
rb08879c2 rbdae198 46 46 #define NULL ((void *) 0) 47 47 #endif 48 49 #define RAND_MAX 714025 48 50 49 51 /* Process Termination */ … … 122 124 extern int __POSIX_DEF__(mkstemp)(char *tmpl); 123 125 126 /* Pseudo-random number generator */ 127 extern int __POSIX_DEF__(rand)(void); 128 extern void __POSIX_DEF__(srand)(unsigned int seed); 129 124 130 /* Legacy Declarations */ 125 131 extern char *__POSIX_DEF__(mktemp)(char *tmpl); -
uspace/lib/posix/include/posix/unistd.h
rb08879c2 rbdae198 44 44 #include "stddef.h" 45 45 46 #define SEEK_SET 0 47 #define SEEK_CUR 1 48 #define SEEK_END 2 49 46 50 /* Process Termination */ 47 51 #define _exit exit … … 77 81 extern ssize_t __POSIX_DEF__(read)(int fildes, void *buf, size_t nbyte); 78 82 extern ssize_t __POSIX_DEF__(write)(int fildes, const void *buf, size_t nbyte); 83 extern __POSIX_DEF__(off_t) __POSIX_DEF__(lseek)(int fildes, 84 __POSIX_DEF__(off_t) offset, int whence); 79 85 extern int __POSIX_DEF__(fsync)(int fildes); 80 86 extern int __POSIX_DEF__(ftruncate)(int fildes, __POSIX_DEF__(off_t) length); -
uspace/lib/posix/source/stdlib.c
rb08879c2 rbdae198 394 394 395 395 /** 396 * Generate a pseudo random integer in the range 0 to RAND_MAX inclusive. 397 * 398 * @return The pseudo random integer. 399 */ 400 int posix_rand(void) 401 { 402 return (int) random(); 403 } 404 405 /** 406 * Initialize a new sequence of pseudo-random integers. 407 * 408 * @param seed The seed of the new sequence. 409 */ 410 void posix_srand(unsigned int seed) 411 { 412 srandom(seed); 413 } 414 415 /** 396 416 * Creates and opens an unique temporary file from template. 397 417 * -
uspace/lib/posix/source/unistd.c
rb08879c2 rbdae198 221 221 { 222 222 return errnify(write, fildes, buf, nbyte); 223 } 224 225 /** 226 * Reposition read/write file offset 227 * 228 * @param fildes File descriptor of the opened file. 229 * @param offset New offset in the file. 230 * @param whence The position from which the offset argument is specified. 231 * @return Upon successful completion, returns the resulting offset 232 * as measured in bytes from the beginning of the file, -1 otherwise. 233 */ 234 posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence) 235 { 236 return errnify(lseek, fildes, offset, whence); 223 237 } 224 238
Note:
See TracChangeset
for help on using the changeset viewer.