+#define FAIL_LG 0, cc->cl.description, &cc->loc, failmsgclass
+#define FAIL(...) do{ \
+ lg_perror(FAIL_LG,errno,__VA_ARGS__); \
+ goto failed; \
+ }while(0)
+
+static bool_t record_socket_gotaddr(struct udpcommon *uc, struct udpsock *us,
+ int failmsgclass)
+{
+ struct commcommon *cc=&uc->cc;
+ socklen_t salen=sizeof(us->addr);
+ int r=getsockname(us->fd,&us->addr.sa,&salen);
+ if (r) FAIL("getsockname()");
+ if ((size_t)salen>sizeof(us->addr)) /* cast squashes clang warning */
+ { errno=0; FAIL("getsockname() length"); }
+ return True;
+
+ failed:
+ return False;
+}
+
+bool_t udp_import_socket(struct udpcommon *uc, struct udpsock *us,
+ int failmsgclass, int fd)
+{
+ FILLZERO(us->experienced);
+ us->fd=fd;
+ return record_socket_gotaddr(uc,us,failmsgclass);
+}
+