* Perhaps this routine, and sooptcopyout(), below, ought to come in an * additional variant to handle the case where the option value needs to be * some kind of integer, but not a specific size. In addition to their use * here, these functions are also called by the protocol-level pr_ctloutput() * routines. */
| 2943 | * routines. |
| 2944 | */ |
| 2945 | int |
| 2946 | sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen) |
| 2947 | { |
| 2948 | size_t valsize; |
| 2949 | |
| 2950 | /* |
| 2951 | * If the user gives us more than we wanted, we ignore it, but if we |
| 2952 | * don't get the minimum length the caller wants, we return EINVAL. |
| 2953 | * On success, sopt->sopt_valsize is set to however much we actually |
| 2954 | * retrieved. |
| 2955 | */ |
| 2956 | if ((valsize = sopt->sopt_valsize) < minlen) |
| 2957 | return EINVAL; |
| 2958 | if (valsize > len) |
| 2959 | sopt->sopt_valsize = valsize = len; |
| 2960 | |
| 2961 | if (sopt->sopt_td != NULL) |
| 2962 | return (copyin(sopt->sopt_val, buf, valsize)); |
| 2963 | |
| 2964 | bcopy(sopt->sopt_val, buf, valsize); |
| 2965 | return (0); |
| 2966 | } |
| 2967 | |
| 2968 | /* |
| 2969 | * Kernel version of setsockopt(2). |
no test coverage detected