aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/options.c24
-rw-r--r--src/core/options.h2
2 files changed, 26 insertions, 0 deletions
diff --git a/src/core/options.c b/src/core/options.c
index 3e35f44c..843b066d 100644
--- a/src/core/options.c
+++ b/src/core/options.c
@@ -202,6 +202,30 @@ nni_copyin_u64(uint64_t *up, const void *v, size_t sz, nni_opt_type t)
}
int
+nni_copyin_sockaddr(nng_sockaddr *ap, const void *v, size_t sz, nni_opt_type t)
+{
+ nng_sockaddr a;
+
+ switch (t) {
+ case NNI_TYPE_SOCKADDR:
+ a = *(nng_sockaddr *) v;
+ break;
+ case NNI_TYPE_OPAQUE:
+ if (sz != sizeof(nng_sockaddr)) {
+ return (NNG_EINVAL);
+ }
+ memcpy(&a, v, sz);
+ break;
+ default:
+ return (NNG_EBADTYPE);
+ }
+ if (ap != NULL) {
+ *ap = a;
+ }
+ return (0);
+}
+
+int
nni_copyout(const void *src, size_t srcsz, void *dst, size_t *dstszp)
{
int rv = 0;
diff --git a/src/core/options.h b/src/core/options.h
index 2a21a039..ac64f9e3 100644
--- a/src/core/options.h
+++ b/src/core/options.h
@@ -32,6 +32,8 @@ extern int nni_copyin_size(
extern int nni_copyin_str(char *, const void *, size_t, size_t, nni_opt_type);
extern int nni_copyin_ptr(void **, const void *, size_t, nni_opt_type);
extern int nni_copyin_u64(uint64_t *, const void *, size_t, nni_opt_type);
+extern int nni_copyin_sockaddr(
+ nng_sockaddr *, const void *, size_t, nni_opt_type);
// nni_copyout_xxx copies out a type of the named value. It assumes that
// the type is aligned and the size correct, unless NNI_TYPE_OPAQUE is passed.