[331] | 1 | /*
|
---|
| 2 | * TINET (UDP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
| 5 | * Tomakomai National College of Technology, JAPAN
|
---|
| 6 | *
|
---|
| 7 | * ä¸è¨èä½æ¨©è
|
---|
| 8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 9 | * ã«ãã£ã¦å
|
---|
| 10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 13 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 19 | * ç¨ã§ããå½¢ã§åé
|
---|
| 20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 22 | * è
|
---|
| 23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
| 28 | * (a) åé
|
---|
| 29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 35 | 責ãããã¨ï¼
|
---|
| 36 | *
|
---|
| 37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 38 | ã
|
---|
| 39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 42 | *
|
---|
| 43 | * @(#) $Id$
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
|
---|
| 48 | * The Regents of the University of California. All rights reserved.
|
---|
| 49 | *
|
---|
| 50 | * Redistribution and use in source and binary forms, with or without
|
---|
| 51 | * modification, are permitted provided that the following conditions
|
---|
| 52 | * are met:
|
---|
| 53 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 54 | * notice, this list of conditions and the following disclaimer.
|
---|
| 55 | * 2. Redistributions in binary form must ceproduce the above copyright
|
---|
| 56 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 57 | * documentation and/or other materials provided with the distribution.
|
---|
| 58 | * 3. All advertising materials mentioning features or use of this software
|
---|
| 59 | * must display the following acknowledgement:
|
---|
| 60 | * This product includes software developed by the University of
|
---|
| 61 | * California, Berkeley and its contributors.
|
---|
| 62 | * 4. Neither the name of the University nor the names of its contributors
|
---|
| 63 | * may be used to endorse or promote products derived from this software
|
---|
| 64 | * without specific prior written permission.
|
---|
| 65 | *
|
---|
| 66 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
| 67 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 68 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 69 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
| 70 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 71 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 72 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 73 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 74 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 75 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 76 | * SUCH DAMAGE.
|
---|
| 77 | *
|
---|
| 78 | * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
|
---|
| 79 | * $FreeBSD: src/sys/netinet/udp_usrreq.c,v 1.49.2.2 1999/08/29 16:29:58 peter Exp $
|
---|
| 80 | */
|
---|
| 81 |
|
---|
| 82 | #ifdef __udp_send_data
|
---|
| 83 |
|
---|
| 84 | /*
|
---|
| 85 | * udp_send_data -- ãã±ããéä¿¡ã®ä¸»è¦é¨
|
---|
| 86 | */
|
---|
| 87 |
|
---|
| 88 | ER_UINT
|
---|
| 89 | UDP_SEND_DATA (T_UDP_CEP *cep, T_IPEP *p_dstaddr, void *data, int_t len, TMO tmout)
|
---|
| 90 | {
|
---|
| 91 | T_NET_BUF *output;
|
---|
| 92 | T_UDP_HDR *udph;
|
---|
| 93 | SYSTIM before, after;
|
---|
| 94 | ER error = E_OK;
|
---|
| 95 |
|
---|
| 96 | #ifdef UDP_CFG_OUT_CHECKSUM
|
---|
| 97 | uint16_t sum;
|
---|
| 98 | #endif /* of #ifdef UDP_CFG_OUT_CHECKSUM */
|
---|
| 99 |
|
---|
| 100 | NET_COUNT_UDP(net_count_udp.out_octets, len);
|
---|
| 101 | NET_COUNT_UDP(net_count_udp.out_packets, 1);
|
---|
| 102 |
|
---|
| 103 | /* IP ãã¼ã¿ã°ã©ã å²ãå½ã¦ã®æéã tmout ããæ¸ããã*/
|
---|
| 104 | if (!(tmout == TMO_POL || tmout == TMO_FEVR))
|
---|
| 105 | syscall(get_tim(&before));
|
---|
| 106 |
|
---|
| 107 | /* IP ãã¼ã¿ã°ã©ã ãå²ãå½ã¦ãã*/
|
---|
| 108 | if ((error = IN_GET_DATAGRAM(&output, (uint_t)(UDP_HDR_SIZE + len), 0,
|
---|
| 109 | &p_dstaddr->ipaddr,
|
---|
| 110 | &cep->myaddr.ipaddr,
|
---|
| 111 | IPPROTO_UDP, IP_DEFTTL,
|
---|
| 112 | NBA_SEARCH_ASCENT, tmout)) != E_OK)
|
---|
| 113 | goto err_ret;
|
---|
| 114 |
|
---|
| 115 | /* IP ãã¼ã¿ã°ã©ã å²ãå½ã¦ã®æéã tmout ããæ¸ããã*/
|
---|
| 116 | if (!(tmout == TMO_POL || tmout == TMO_FEVR)) {
|
---|
| 117 | syscall(get_tim(&after));
|
---|
| 118 | if (after - before > tmout) {
|
---|
| 119 | syscall(rel_net_buf(output));
|
---|
| 120 | error = E_TMOUT;
|
---|
| 121 | goto err_ret;
|
---|
| 122 | }
|
---|
| 123 | tmout -= (TMO)(after - before);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | /* UDP ãããã«æ
|
---|
| 127 | å ±ãè¨å®ããã*/
|
---|
| 128 | udph = GET_UDP_HDR(output, IF_IP_UDP_HDR_OFFSET(output));
|
---|
| 129 | udph->sport = htons(cep->myaddr.portno);
|
---|
| 130 | udph->dport = htons(p_dstaddr->portno);
|
---|
| 131 | udph->ulen = htons(UDP_HDR_SIZE + len);
|
---|
| 132 | udph->sum = 0;
|
---|
| 133 |
|
---|
| 134 | /* ãã¼ã¿ãã³ãã¼ããã*/
|
---|
| 135 | memcpy((void*)GET_UDP_SDU(output, IF_IP_UDP_HDR_OFFSET(output)), data, (size_t)len);
|
---|
| 136 |
|
---|
| 137 | #ifdef UDP_CFG_OUT_CHECKSUM
|
---|
| 138 |
|
---|
| 139 | sum = IN_CKSUM(output, IPPROTO_UDP, IF_IP_UDP_HDR_OFFSET(output), (uint_t)(UDP_HDR_SIZE + len));
|
---|
| 140 |
|
---|
| 141 | /* è¨ç®ãããã§ãã¯ãµã ã®å¤ã 0 ãªã 0xffff ãå
|
---|
| 142 | ¥ããã*/
|
---|
| 143 | if (sum == 0)
|
---|
| 144 | sum = 0xffff;
|
---|
| 145 | udph->sum = sum;
|
---|
| 146 |
|
---|
| 147 | #endif /* of #ifdef UDP_CFG_OUT_CHECKSUM */
|
---|
| 148 |
|
---|
| 149 | /* ãããã¯ã¼ã¯ãããã¡é·ã調æ´ããã*/
|
---|
| 150 | output->len = (uint16_t)(IF_IP_UDP_HDR_SIZE(output) + len);
|
---|
| 151 |
|
---|
| 152 | /* ãããã¯ã¼ã¯å±¤ (IP) ã®åºåé¢æ°ãå¼ã³åºãã*/
|
---|
| 153 | if ((error = IP_OUTPUT(output, tmout)) == E_OK) {
|
---|
| 154 | NET_COUNT_MIB(udp_stats.udpOutDatagrams, 1);
|
---|
| 155 | cep->snd_tskid = TA_NULL;
|
---|
| 156 | return len;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | err_ret:
|
---|
| 160 | NET_COUNT_UDP(net_count_udp.out_err_packets, 1);
|
---|
| 161 | cep->snd_tskid = TA_NULL;
|
---|
| 162 | return error;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | #endif /* of #ifdef __udp_send_data */
|
---|
| 166 |
|
---|
| 167 | /*
|
---|
| 168 | * udp_cancel_cep -- ãã³ãã£ã³ã°ãã¦ããå¦çããã£ã³ã»ã«ããã
|
---|
| 169 | *
|
---|
| 170 | * udp_can_cep ããå¼åºãããã¡ã¤ã³é¢æ°
|
---|
| 171 | */
|
---|
| 172 |
|
---|
| 173 | #ifdef __udp_can_cep
|
---|
| 174 |
|
---|
| 175 | static ER
|
---|
| 176 | UDP_CANCEL_CEP (T_UDP_CEP *cep, FN fncd)
|
---|
| 177 | {
|
---|
| 178 | ER error = E_OK, snd_err, rcv_err;
|
---|
| 179 |
|
---|
| 180 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 181 | if (!VALID_UDP_CEP(cep))
|
---|
| 182 | return E_NOEXS;
|
---|
| 183 |
|
---|
| 184 | /* API æ©è½ã³ã¼ãããã§ãã¯ããã*/
|
---|
| 185 | if (!VALID_TFN_UDP_CAN(fncd))
|
---|
| 186 | return E_PAR;
|
---|
| 187 |
|
---|
| 188 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 189 | syscall(wai_sem(cep->semid_lock));
|
---|
| 190 |
|
---|
| 191 | if (fncd == TFN_UDP_ALL) { /* TFN_UDP_ALL ã®å¦ç */
|
---|
| 192 |
|
---|
| 193 | snd_err = UDP_CAN_SND(cep, E_RLWAI);
|
---|
| 194 | rcv_err = UDP_CAN_RCV(cep, E_RLWAI);
|
---|
| 195 |
|
---|
| 196 | /*
|
---|
| 197 | * snd_err 㨠rcv_err ã®ã©ã¡ãã EV_NOPND
|
---|
| 198 | * ãªãããã³ãã£ã³ã°ãã¦ããªãã®ã§ã¨ã©ã¼
|
---|
| 199 | */
|
---|
| 200 | if (snd_err == EV_NOPND && rcv_err == EV_NOPND)
|
---|
| 201 | error = E_OBJ;
|
---|
| 202 | else {
|
---|
| 203 | if (snd_err == EV_NOPND)
|
---|
| 204 | snd_err = E_OK;
|
---|
| 205 | if (rcv_err == EV_NOPND)
|
---|
| 206 | rcv_err = E_OK;
|
---|
| 207 |
|
---|
| 208 | if (snd_err != E_OK)
|
---|
| 209 | error = snd_err;
|
---|
| 210 | else if (rcv_err != E_OK)
|
---|
| 211 | error = rcv_err;
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 | else if (fncd == TFN_UDP_SND_DAT) { /* éä¿¡å¦çã®ãã£ã³ã»ã« */
|
---|
| 215 | if ((error = UDP_CAN_SND(cep, E_RLWAI)) == EV_NOPND)
|
---|
| 216 | error = E_OBJ;
|
---|
| 217 | }
|
---|
| 218 | else if (fncd == TFN_UDP_RCV_DAT) { /* åä¿¡å¦çã®ãã£ã³ã»ã« */
|
---|
| 219 | if ((error = UDP_CAN_RCV(cep, E_RLWAI)) == EV_NOPND)
|
---|
| 220 | error = E_OBJ;
|
---|
| 221 | }
|
---|
| 222 | else
|
---|
| 223 | error = E_PAR;
|
---|
| 224 |
|
---|
| 225 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 226 | syscall(sig_sem(cep->semid_lock));
|
---|
| 227 |
|
---|
| 228 | return error;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | #endif /* of #ifdef __udp_can_cep */
|
---|
| 232 |
|
---|
| 233 | #if defined(SUPPORT_INET6) && (defined(SUPPORT_INET4) && TNUM_UDP4_CEPID > 0)
|
---|
| 234 |
|
---|
| 235 | #else /* of #if defined(SUPPORT_INET6) && (defined(SUPPORT_INET4) && TNUM_UDP4_CEPID > 0) */
|
---|
| 236 |
|
---|
| 237 | /*
|
---|
| 238 | * udp_can_cep -- ãã³ãã£ã³ã°ãã¦ããå¦çã®ãã£ã³ã»ã«ãæ¨æºæ©è½ã
|
---|
| 239 | */
|
---|
| 240 |
|
---|
| 241 | #ifdef __udp_can_cep
|
---|
| 242 |
|
---|
| 243 | ER
|
---|
| 244 | udp_can_cep (ID cepid, FN fncd)
|
---|
| 245 | {
|
---|
| 246 | T_UDP_CEP *cep;
|
---|
| 247 |
|
---|
| 248 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 249 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 250 | return E_ID;
|
---|
| 251 |
|
---|
| 252 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 253 | cep = GET_UDP_CEP(cepid);
|
---|
| 254 |
|
---|
| 255 | /* ã¡ã¤ã³é¢æ°ãå¼ã³åºãã*/
|
---|
| 256 | return UDP_CANCEL_CEP(cep, fncd);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | #endif /* of #ifdef __udp_can_cep */
|
---|
| 260 |
|
---|
| 261 | #endif /* of #if defined(SUPPORT_INET6) && (defined(SUPPORT_INET4) && TNUM_UDP4_CEPID > 0) */
|
---|
| 262 |
|
---|
| 263 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 264 |
|
---|
| 265 | /*
|
---|
| 266 | * udp_cre_cep -- UDP é信端ç¹ã®çæãæ¡å¼µæ©è½ã
|
---|
| 267 | */
|
---|
| 268 |
|
---|
| 269 | #ifdef __udp_cre_cep
|
---|
| 270 |
|
---|
| 271 | ER
|
---|
| 272 | UDP_CRE_CEP (ID cepid, T_UDPN_CCEP *pk_ccep)
|
---|
| 273 | {
|
---|
| 274 | T_UDP_CEP *cep;
|
---|
| 275 | ER error;
|
---|
| 276 |
|
---|
| 277 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 278 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 279 | return E_ID;
|
---|
| 280 |
|
---|
| 281 | /* pk_ccep ã NULL ãªãã¨ã©ã¼ */
|
---|
| 282 | if (pk_ccep == NULL)
|
---|
| 283 | return E_PAR;
|
---|
| 284 |
|
---|
| 285 | #if (API_PROTO == API_PROTO_IPV6) && !defined(API_CFG_IP4MAPPED_ADDR)
|
---|
| 286 |
|
---|
| 287 | /*
|
---|
| 288 | * API ã IPv6 㧠IPv4 å°å½±ã¢ãã¬ã¹ãèªãããã¦ããªãã®ã«ããããããã
|
---|
| 289 | * IPv4 å°å½±ã¢ãã¬ã¹ãæå®ããããã¨ã©ã¼
|
---|
| 290 | */
|
---|
| 291 | if (in6_is_addr_ipv4mapped(&pk_ccep->myaddr.ipaddr))
|
---|
| 292 | return E_PAR;
|
---|
| 293 |
|
---|
| 294 | #endif /* of #if (API_PROTO == API_PROTO_IPV6) && !defined(DAPI_CFG_IP4MAPPED_ADDR) */
|
---|
| 295 |
|
---|
| 296 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 297 | cep = GET_UDP_CEP(cepid);
|
---|
| 298 |
|
---|
| 299 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 300 | if (VALID_UDP_CEP(cep))
|
---|
| 301 | return E_OBJ;
|
---|
| 302 |
|
---|
| 303 | /* UDP é信端ç¹ããåççæç¨ã§ãªããã°ã¨ã©ã¼ */
|
---|
| 304 | if (!DYNAMIC_UDP_CEP(cep))
|
---|
| 305 | return E_ID;
|
---|
| 306 |
|
---|
| 307 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 308 | syscall(wai_sem(cep->semid_lock));
|
---|
| 309 |
|
---|
| 310 | /*
|
---|
[429] | 311 | * UDP é信端ç¹ããã§ãã¯ãããçææ¸ã¿ã§ããã°ã¨ã©ã¼
|
---|
| 312 | */
|
---|
| 313 | if (VALID_UDP_CEP(cep))
|
---|
| 314 | error = E_OBJ;
|
---|
| 315 | else {
|
---|
[331] | 316 |
|
---|
[429] | 317 | /*
|
---|
| 318 | * èªãã¼ãçªå·ã UDP_PORTANY ãªããèªåã§å²ãå½ã¦ãã
|
---|
| 319 | */
|
---|
[331] | 320 | if (pk_ccep->myaddr.portno == UDP_PORTANY)
|
---|
| 321 | error = UDP_ALLOC_AUTO_PORT(cep);
|
---|
| 322 | else
|
---|
| 323 | error = UDP_ALLOC_PORT(cep, pk_ccep->myaddr.portno);
|
---|
| 324 |
|
---|
| 325 | if (error == E_OK) {
|
---|
| 326 | /* UDP é信端ç¹çææ
|
---|
| 327 | å ±ãã³ãã¼ããã*/
|
---|
| 328 | cep->cepatr = pk_ccep->cepatr; /* é信端ç¹å±æ§ */
|
---|
| 329 | cep->myaddr.ipaddr = pk_ccep->myaddr.ipaddr; /* èªåã®ã¢ãã¬ã¹ */
|
---|
| 330 | cep->callback = (void*)pk_ccep->callback; /* ã³ã¼ã«ãã㯠*/
|
---|
| 331 |
|
---|
| 332 | /* UDP é信端ç¹ãçææ¸ã¿ã«ããã*/
|
---|
| 333 | cep->flags |= UDP_CEP_FLG_VALID;
|
---|
| 334 | }
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | /* é信端ç¹ã®ããã¯ã解é¤ããã*/
|
---|
| 338 | syscall(sig_sem(cep->semid_lock));
|
---|
| 339 |
|
---|
| 340 | return error;
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | #endif /* of #ifdef __udp_cre_cep */
|
---|
| 344 |
|
---|
| 345 | #ifdef __udp_del_cep
|
---|
| 346 |
|
---|
| 347 | /*
|
---|
| 348 | * udp_delete_cep -- UDP é信端ç¹ãåé¤ããã
|
---|
| 349 | *
|
---|
| 350 | * udp_del_cep ããå¼åºãããã¡ã¤ã³é¢æ°
|
---|
| 351 | */
|
---|
| 352 |
|
---|
| 353 | static ER
|
---|
| 354 | UDP_DELETE_CEP (T_UDP_CEP *cep)
|
---|
| 355 | {
|
---|
| 356 | ER error;
|
---|
| 357 |
|
---|
| 358 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 359 | if (!VALID_UDP_CEP(cep))
|
---|
| 360 | return E_NOEXS;
|
---|
| 361 |
|
---|
| 362 | /* UDP é信端ç¹ããåççæç¨ã§ãªããã°ã¨ã©ã¼ */
|
---|
| 363 | if (!DYNAMIC_UDP_CEP(cep))
|
---|
| 364 | return E_ID;
|
---|
| 365 |
|
---|
| 366 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 367 | syscall(wai_sem(cep->semid_lock));
|
---|
| 368 |
|
---|
| 369 | /*
|
---|
| 370 | * UDP é信端ç¹ããã§ãã¯ãããæªçæã®å ´åã¯ã¨ã©ã¼
|
---|
| 371 | * ã»æªçæã
|
---|
| 372 | */
|
---|
| 373 | if (!VALID_UDP_CEP(cep))
|
---|
| 374 | error = E_NOEXS;
|
---|
| 375 | else {
|
---|
| 376 | UDP_CAN_SND(cep, E_DLT);
|
---|
| 377 | UDP_CAN_RCV(cep, E_DLT);
|
---|
| 378 |
|
---|
| 379 | /* UDP é信端ç¹ãæªçæã«ããã*/
|
---|
| 380 | cep->flags &= ~UDP_CEP_FLG_VALID;
|
---|
| 381 | error = E_OK;
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | /* é信端ç¹ã®ããã¯ã解é¤ããã*/
|
---|
| 385 | syscall(sig_sem(cep->semid_lock));
|
---|
| 386 |
|
---|
| 387 | return error;
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | /*
|
---|
| 391 | * udp_del_cep -- UDP é信端ç¹ã®åé¤ãæ¡å¼µæ©è½ã
|
---|
| 392 | */
|
---|
| 393 |
|
---|
| 394 | ER
|
---|
| 395 | UDP_DEL_CEP (ID cepid)
|
---|
| 396 | {
|
---|
| 397 | T_UDP_CEP *cep;
|
---|
| 398 |
|
---|
| 399 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 400 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 401 | return E_ID;
|
---|
| 402 |
|
---|
| 403 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 404 | cep = GET_UDP_CEP(cepid);
|
---|
| 405 |
|
---|
| 406 | /* ã¡ã¤ã³é¢æ°ãå¼ã³åºãã*/
|
---|
| 407 | return UDP_DELETE_CEP(cep);
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | #endif /* of #ifdef __udp_del_cep */
|
---|
| 411 |
|
---|
[429] | 412 | #ifdef __udp_set_opt
|
---|
[331] | 413 |
|
---|
| 414 | /*
|
---|
| 415 | * udp_set_option -- UDP é信端ç¹ãªãã·ã§ã³ãè¨å®ããã
|
---|
| 416 | *
|
---|
| 417 | * udp_set_opt ããå¼åºãããã¡ã¤ã³é¢æ°
|
---|
| 418 | */
|
---|
| 419 |
|
---|
| 420 | static ER
|
---|
| 421 | UDP_SET_OPTION (T_UDP_CEP *cep, int_t optname, void *optval, int_t optlen)
|
---|
| 422 | {
|
---|
| 423 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 424 | if (!VALID_UDP_CEP(cep))
|
---|
| 425 | return E_NOEXS;
|
---|
| 426 | #if defined(SUPPORT_INET6)
|
---|
| 427 | #elif defined(SUPPORT_INET4) && defined(SUPPORT_IGMP) && TNUM_UDP4_CEPID > 0
|
---|
| 428 | switch (optname) {
|
---|
| 429 | case IP_MULTICAST_LOOP:
|
---|
| 430 | if (optlen >= sizeof(uint8_t)) {
|
---|
| 431 | return igmp_set_loop(cep, *(uint8_t *)optval);
|
---|
| 432 | }
|
---|
| 433 | break;
|
---|
| 434 | case IP_MULTICAST_TTL:
|
---|
| 435 | if (optlen >= sizeof(uint8_t)) {
|
---|
| 436 | return igmp_set_ttl(cep, *(uint8_t *)optval);
|
---|
| 437 | }
|
---|
| 438 | break;
|
---|
| 439 | case IP_MULTICAST_IF:
|
---|
| 440 | if (optlen >= sizeof(T_IN4_ADDR)) {
|
---|
| 441 | return igmp_set_if(cep, (T_IN4_ADDR *)optval);
|
---|
| 442 | }
|
---|
| 443 | break;
|
---|
| 444 | case IP_ADD_MEMBERSHIP:
|
---|
| 445 | if (optlen >= sizeof(T_IP_MREQ)) {
|
---|
| 446 | return igmp_add_membership(cep, (T_IP_MREQ *)optval);
|
---|
| 447 | }
|
---|
| 448 | break;
|
---|
| 449 | case IP_DROP_MEMBERSHIP:
|
---|
| 450 | if (optlen >= sizeof(T_IP_MREQ)) {
|
---|
| 451 | return igmp_drop_membership(cep, (T_IP_MREQ *)optval);
|
---|
| 452 | }
|
---|
| 453 | break;
|
---|
| 454 | case IP_MSFILTER:
|
---|
| 455 | if (optlen >= sizeof(T_IP_MSFILTER)) {
|
---|
| 456 | return igmp_set_ip_msfilter(cep, (T_IP_MSFILTER *)optval);
|
---|
| 457 | }
|
---|
| 458 | break;
|
---|
| 459 | }
|
---|
| 460 | #endif
|
---|
| 461 | return E_PAR;
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | /*
|
---|
| 465 | * udp_set_opt -- UDP é信端ç¹ãªãã·ã§ã³ã®è¨å®ãæ¡å¼µæ©è½ã
|
---|
| 466 | *
|
---|
| 467 | * 注æ: è¨å®å¯è½ãª UDP é信端ç¹ãªãã·ã§ã³ã¯ç¡ããããE_PAR ãè¿ãããã
|
---|
| 468 | */
|
---|
| 469 |
|
---|
| 470 | ER
|
---|
| 471 | UDP_SET_OPT (ID cepid, int_t optname, void *optval, int_t optlen)
|
---|
| 472 | {
|
---|
| 473 | T_UDP_CEP *cep;
|
---|
| 474 |
|
---|
| 475 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 476 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 477 | return E_ID;
|
---|
| 478 |
|
---|
| 479 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 480 | cep = GET_UDP_CEP(cepid);
|
---|
| 481 |
|
---|
| 482 | /* ã¡ã¤ã³é¢æ°ãå¼ã³åºãã*/
|
---|
| 483 | return UDP_SET_OPTION(cep, optname, optval, optlen);
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | #endif /* of #ifdef __udp_set_opt */
|
---|
| 487 |
|
---|
[429] | 488 | #ifdef __udp_get_opt
|
---|
[331] | 489 |
|
---|
| 490 | /*
|
---|
| 491 | * udp_get_option -- UDP é信端ç¹ãªãã·ã§ã³ãç²å¾ããã
|
---|
| 492 | *
|
---|
| 493 | * udp_get_opt ããå¼åºãããã¡ã¤ã³é¢æ°
|
---|
| 494 | */
|
---|
| 495 |
|
---|
| 496 | static ER
|
---|
| 497 | UDP_GET_OPTION (T_UDP_CEP *cep, int_t optname, void *optval, int_t optlen)
|
---|
| 498 | {
|
---|
| 499 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 500 | if (!VALID_UDP_CEP(cep))
|
---|
| 501 | return E_NOEXS;
|
---|
| 502 | #if defined(SUPPORT_INET6)
|
---|
| 503 | #elif defined(SUPPORT_INET4) && defined(SUPPORT_IGMP) && TNUM_UDP4_CEPID > 0
|
---|
| 504 | switch (optname) {
|
---|
| 505 | case IP_MULTICAST_LOOP:
|
---|
| 506 | if (optlen >= sizeof(uint8_t)) {
|
---|
| 507 | return igmp_get_loop(cep, (uint8_t *)optval);
|
---|
| 508 | }
|
---|
| 509 | break;
|
---|
| 510 | case IP_MULTICAST_TTL:
|
---|
| 511 | if (optlen >= sizeof(uint8_t)) {
|
---|
| 512 | return igmp_get_ttl(cep, (uint8_t *)optval);
|
---|
| 513 | }
|
---|
| 514 | break;
|
---|
| 515 | case IP_MULTICAST_IF:
|
---|
| 516 | if (optlen >= sizeof(uint32_t)) {
|
---|
| 517 | return igmp_get_if(cep, (uint32_t *)optval);
|
---|
| 518 | }
|
---|
| 519 | break;
|
---|
| 520 | case IP_MSFILTER:
|
---|
| 521 | if (optlen >= sizeof(T_IP_MSFILTER)) {
|
---|
| 522 | return igmp_get_ip_msfilter(cep, (T_IP_MSFILTER *)optval);
|
---|
| 523 | }
|
---|
| 524 | break;
|
---|
| 525 | }
|
---|
| 526 | #endif
|
---|
| 527 | return E_PAR;
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | /*
|
---|
| 531 | * udp_get_opt -- UDP é信端ç¹ãªãã·ã§ã³ã®ç²å¾ãæ¡å¼µæ©è½ã
|
---|
| 532 | *
|
---|
| 533 | * 注æ: è¨å®å¯è½ãª UDP é信端ç¹ãªãã·ã§ã³ã¯ç¡ããããE_PAR ãè¿ãããã
|
---|
| 534 | */
|
---|
| 535 |
|
---|
| 536 | ER
|
---|
| 537 | UDP_GET_OPT (ID cepid, int_t optname, void *optval, int_t optlen)
|
---|
| 538 | {
|
---|
| 539 | T_UDP_CEP *cep;
|
---|
| 540 |
|
---|
| 541 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 542 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 543 | return E_ID;
|
---|
| 544 |
|
---|
| 545 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 546 | cep = GET_UDP_CEP(cepid);
|
---|
| 547 |
|
---|
| 548 | /* ã¡ã¤ã³é¢æ°ãå¼ã³åºãã*/
|
---|
| 549 | return UDP_GET_OPTION(cep, optname, optval, optlen);
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | #endif /* of #ifdef __udp_get_opt */
|
---|
| 553 |
|
---|
| 554 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 555 |
|
---|
| 556 | #ifdef UDP_CFG_NON_BLOCKING
|
---|
| 557 |
|
---|
| 558 | #else /* of #ifdef UDP_CFG_NON_BLOCKING */
|
---|
| 559 |
|
---|
| 560 | #ifdef __udp_can_snd
|
---|
| 561 |
|
---|
| 562 | /*
|
---|
| 563 | * udp_can_snd -- ãã³ãã£ã³ã°ãã¦ããéä¿¡ã®ãã£ã³ã»ã«
|
---|
| 564 | */
|
---|
| 565 |
|
---|
| 566 | ER
|
---|
| 567 | UDP_CAN_SND (T_UDP_CEP *cep, ER error)
|
---|
| 568 | {
|
---|
| 569 | if (cep->snd_tskid != TA_NULL) { /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 570 |
|
---|
| 571 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 572 |
|
---|
| 573 | /* å¾
|
---|
| 574 | ã¡ä¸ã«çºçããã¨ã©ã¼æ
|
---|
| 575 | å ±ãè¨å®ããã*/
|
---|
| 576 | cep->error = error;
|
---|
| 577 |
|
---|
| 578 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 579 |
|
---|
| 580 | error = rel_wai(cep->snd_tskid);
|
---|
| 581 | cep->snd_tskid = TA_NULL;
|
---|
| 582 | }
|
---|
| 583 | else /* ã©ã¡ãã§ããªããªããã³ãã£ã³ã°ãã¦ããªã */
|
---|
| 584 | error = EV_NOPND;
|
---|
| 585 |
|
---|
| 586 | return error;
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | #endif /* of #ifdef __udp_can_snd */
|
---|
| 590 |
|
---|
| 591 | #ifdef __udp_can_rcv
|
---|
| 592 |
|
---|
| 593 | /*
|
---|
| 594 | * udp_can_rcv -- ãã³ãã£ã³ã°ãã¦ããåä¿¡ã®ãã£ã³ã»ã«
|
---|
| 595 | */
|
---|
| 596 |
|
---|
| 597 | ER
|
---|
| 598 | UDP_CAN_RCV (T_UDP_CEP *cep, ER error)
|
---|
| 599 | {
|
---|
| 600 | if (cep->rcv_tskid != TA_NULL) { /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 601 |
|
---|
| 602 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 603 |
|
---|
| 604 | /* å¾
|
---|
| 605 | ã¡ä¸ã«çºçããã¨ã©ã¼æ
|
---|
| 606 | å ±ãè¨å®ããã*/
|
---|
| 607 | cep->error = error;
|
---|
| 608 |
|
---|
| 609 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 610 |
|
---|
| 611 | error = rel_wai(cep->rcv_tskid);
|
---|
| 612 | cep->rcv_tskid = TA_NULL;
|
---|
| 613 | }
|
---|
| 614 | else /* ã©ã¡ãã§ããªããªããã³ãã£ã³ã°ãã¦ããªã */
|
---|
| 615 | error = EV_NOPND;
|
---|
| 616 |
|
---|
| 617 | return error;
|
---|
| 618 | }
|
---|
| 619 |
|
---|
| 620 | #endif /* of #ifdef __udp_can_rcv */
|
---|
| 621 |
|
---|
| 622 | #ifdef __udp_snd_dat
|
---|
| 623 |
|
---|
| 624 | /*
|
---|
| 625 | * udp_snd_dat -- ãã±ããã®éä¿¡ãæ¨æºæ©è½ã
|
---|
| 626 | */
|
---|
| 627 |
|
---|
| 628 | ER_UINT
|
---|
| 629 | UDP_SND_DAT (ID cepid, T_IPEP *p_dstaddr, void *data, int_t len, TMO tmout)
|
---|
| 630 | {
|
---|
| 631 | T_UDP_CEP *cep;
|
---|
| 632 | ER error;
|
---|
| 633 |
|
---|
| 634 | /* p_dstaddr ã¾ã㯠data ã NULL ããtmout ã TMO_NBLK ãªãã¨ã©ã¼ */
|
---|
| 635 | if (p_dstaddr == NULL || data == NULL || tmout == TMO_NBLK)
|
---|
| 636 | return E_PAR;
|
---|
| 637 |
|
---|
| 638 | /* ãã¼ã¿é·ããã§ãã¯ããã*/
|
---|
| 639 | if (len < 0 || len + IP_HDR_SIZE + UDP_HDR_SIZE > IF_MTU)
|
---|
| 640 | return E_PAR;
|
---|
| 641 |
|
---|
| 642 | #if (API_PROTO == API_PROTO_IPV6) && !defined(API_CFG_IP4MAPPED_ADDR)
|
---|
| 643 |
|
---|
| 644 | /*
|
---|
| 645 | * API ã IPv6 㧠IPv4 å°å½±ã¢ãã¬ã¹ãèªãããã¦ããªãã®ã«ããããããã
|
---|
| 646 | * IPv4 å°å½±ã¢ãã¬ã¹ãæå®ããããã¨ã©ã¼
|
---|
| 647 | */
|
---|
| 648 | if (in6_is_addr_ipv4mapped(&p_dstaddr->ipaddr))
|
---|
| 649 | return E_PAR;
|
---|
| 650 |
|
---|
| 651 | #endif /* of #if (API_PROTO == API_PROTO_IPV6) && !defined(DAPI_CFG_IP4MAPPED_ADDR) */
|
---|
| 652 |
|
---|
| 653 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 654 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 655 | return E_ID;
|
---|
| 656 |
|
---|
| 657 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 658 | cep = GET_UDP_CEP(cepid);
|
---|
| 659 |
|
---|
| 660 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 661 | if (!VALID_UDP_CEP(cep))
|
---|
| 662 | return E_NOEXS;
|
---|
| 663 |
|
---|
| 664 | /*
|
---|
| 665 | * èªãã¼ãçªå·ã UDP_PORTANY ãªããèªåã§å²ãå½ã¦ãã
|
---|
| 666 | */
|
---|
| 667 | if (cep->myaddr.portno == UDP_PORTANY) {
|
---|
| 668 | if ((error = UDP_ALLOC_AUTO_PORT(cep)) != E_OK)
|
---|
| 669 | return error;
|
---|
| 670 | }
|
---|
| 671 |
|
---|
| 672 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 673 | syscall(wai_sem(cep->semid_lock));
|
---|
| 674 |
|
---|
| 675 | if (cep->snd_tskid != TA_NULL) {
|
---|
| 676 |
|
---|
| 677 | /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 678 | error = E_QOVR;
|
---|
| 679 |
|
---|
| 680 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 681 | syscall(sig_sem(cep->semid_lock));
|
---|
| 682 | }
|
---|
| 683 | else {
|
---|
| 684 | /* ç¾å¨ã®ã¿ã¹ã¯èå¥åãè¨é²ããã*/
|
---|
| 685 | get_tid(&(cep->snd_tskid));
|
---|
| 686 |
|
---|
| 687 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 688 |
|
---|
| 689 | /* å¾
|
---|
| 690 | ã¡ä¸ã«çºçããã¨ã©ã¼æ
|
---|
| 691 | å ±ããªã»ããããã*/
|
---|
| 692 | cep->error = E_OK;
|
---|
| 693 |
|
---|
| 694 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 695 |
|
---|
| 696 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 697 | syscall(sig_sem(cep->semid_lock));
|
---|
| 698 |
|
---|
| 699 | /* ãã±ãããéä¿¡ããã*/
|
---|
| 700 | error = UDP_SEND_DATA(cep, p_dstaddr, data, len, tmout);
|
---|
| 701 |
|
---|
| 702 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 703 |
|
---|
| 704 | /* å¾
|
---|
| 705 | ã¡ä¸ã«çºçããã¨ã©ã¼æ
|
---|
| 706 | å ±ãè¿ãã*/
|
---|
| 707 | if (error == E_RLWAI)
|
---|
| 708 | error = cep->error;
|
---|
| 709 |
|
---|
| 710 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | return error;
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | #endif /* of #ifdef __udp_snd_dat */
|
---|
| 717 |
|
---|
| 718 | #ifdef __udp_rcv_dat
|
---|
| 719 |
|
---|
| 720 | /*
|
---|
| 721 | * udp_rcv_dat -- ãã±ããã®åä¿¡ãæ¨æºæ©è½ã
|
---|
| 722 | */
|
---|
| 723 |
|
---|
| 724 | ER_UINT
|
---|
| 725 | UDP_RCV_DAT (ID cepid, T_IPEP *p_dstaddr, void *data, int_t len, TMO tmout)
|
---|
| 726 | {
|
---|
| 727 | T_NET_BUF *input;
|
---|
| 728 | T_UDP_CEP *cep;
|
---|
| 729 | T_UDP_HDR *udph;
|
---|
| 730 | ER_UINT error;
|
---|
| 731 | uint_t ulen, uhoff;
|
---|
| 732 |
|
---|
| 733 | /* p_dstaddr ã¾ã㯠data ã NULL ãlen < 0 ããtmout ã TMO_NBLK ãªãã¨ã©ã¼ */
|
---|
| 734 | if (p_dstaddr == NULL || data == NULL || len < 0 || tmout == TMO_NBLK)
|
---|
| 735 | return E_PAR;
|
---|
| 736 |
|
---|
| 737 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 738 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 739 | return E_ID;
|
---|
| 740 |
|
---|
| 741 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 742 | cep = GET_UDP_CEP(cepid);
|
---|
| 743 |
|
---|
| 744 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 745 | if (!VALID_UDP_CEP(cep))
|
---|
| 746 | return E_NOEXS;
|
---|
| 747 |
|
---|
| 748 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 749 | syscall(wai_sem(cep->semid_lock));
|
---|
| 750 |
|
---|
| 751 | if (cep->rcv_tskid != TA_NULL) {
|
---|
| 752 |
|
---|
| 753 | /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 754 | error = E_QOVR;
|
---|
| 755 |
|
---|
| 756 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 757 | syscall(sig_sem(cep->semid_lock));
|
---|
| 758 | }
|
---|
| 759 | else {
|
---|
| 760 |
|
---|
| 761 | /* ç¾å¨ã®ã¿ã¹ã¯èå¥åãè¨é²ããã*/
|
---|
| 762 | get_tid(&(cep->rcv_tskid));
|
---|
| 763 |
|
---|
| 764 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 765 |
|
---|
| 766 | /* å¾
|
---|
| 767 | ã¡ä¸ã«çºçããã¨ã©ã¼æ
|
---|
| 768 | å ±ããªã»ããããã*/
|
---|
| 769 | cep->error = E_OK;
|
---|
| 770 |
|
---|
| 771 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 772 |
|
---|
| 773 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 774 | syscall(sig_sem(cep->semid_lock));
|
---|
| 775 |
|
---|
| 776 | /* å
|
---|
| 777 | ¥åãããã¾ã§å¾
|
---|
| 778 | ã¤ã*/
|
---|
| 779 | if (cep->cb_netbuf != NULL) {
|
---|
| 780 |
|
---|
| 781 | /*
|
---|
| 782 | * ããã«ããå ´åã¯ãã³ã¼ã«ããã¯é¢æ°ã®ä¸ãã
|
---|
| 783 | * udp_rcv_dat ãå¼ã³åºãã¦ãããã¨ã«ãªãã
|
---|
| 784 | * ãã§ã«å
|
---|
| 785 | ¥åæ¸ã¿ã§ããã
|
---|
| 786 | */
|
---|
| 787 | input = cep->cb_netbuf;
|
---|
| 788 | cep->cb_netbuf = NULL;
|
---|
| 789 | }
|
---|
| 790 | else if ((error = trcv_dtq(cep->rcvqid, (intptr_t*)&input, tmout)) != E_OK) {
|
---|
| 791 |
|
---|
| 792 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 793 |
|
---|
| 794 | /* å¾
|
---|
| 795 | ã¡ä¸ã«çºçããã¨ã©ã¼æ
|
---|
| 796 | å ±ãè¿ãã*/
|
---|
| 797 | if (error == E_RLWAI)
|
---|
| 798 | error = cep->error;
|
---|
| 799 |
|
---|
| 800 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 801 |
|
---|
| 802 | cep->rcv_tskid = TA_NULL;
|
---|
| 803 | return error;
|
---|
| 804 | }
|
---|
| 805 |
|
---|
| 806 | /* p_dstaddr ãè¨å®ããã*/
|
---|
| 807 | uhoff = (uint_t)GET_UDP_HDR_OFFSET(input);
|
---|
| 808 | udph = GET_UDP_HDR(input, uhoff);
|
---|
| 809 | p_dstaddr->portno = ntohs(udph->sport);
|
---|
| 810 | IN_COPY_TO_HOST(&p_dstaddr->ipaddr, input);
|
---|
| 811 |
|
---|
| 812 | /* ãã¼ã¿ããããã¡ã«ç§»ãã*/
|
---|
| 813 | ulen = ntohs(udph->ulen);
|
---|
| 814 | if (ulen - UDP_HDR_SIZE > len)
|
---|
| 815 | error = E_BOVR;
|
---|
| 816 | else {
|
---|
| 817 | len = (uint_t)(ulen - UDP_HDR_SIZE);
|
---|
| 818 | error = (ER_UINT)(ulen - UDP_HDR_SIZE);
|
---|
| 819 | }
|
---|
| 820 |
|
---|
| 821 | memcpy(data, GET_UDP_SDU(input, uhoff), (size_t)len);
|
---|
| 822 |
|
---|
| 823 | syscall(rel_net_buf(input));
|
---|
| 824 |
|
---|
| 825 | cep->rcv_tskid = TA_NULL;
|
---|
| 826 | }
|
---|
| 827 |
|
---|
| 828 | return error;
|
---|
| 829 | }
|
---|
| 830 |
|
---|
| 831 | #endif /* of #ifdef __udp_rcv_dat */
|
---|
| 832 |
|
---|
| 833 | #endif /* of #ifdef UDP_CFG_NON_BLOCKING */
|
---|