]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
Implement bind() for libvfscore
authorSharan Santhanam <sharan.santhanam@neclab.eu>
Wed, 13 Jun 2018 00:17:45 +0000 (02:17 +0200)
committerSimon Kuenzer <simon.kuenzer@neclab.eu>
Fri, 15 Jun 2018 01:21:07 +0000 (03:21 +0200)
Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
socket_glue.c

index 2148c396d427b89d68ea4f4d5afcf4ff359c512b..c323ffc63779c7b91217dad6e55a00a1464d60bf 100644 (file)
@@ -4,6 +4,7 @@
 #include <uk/alloc.h>
 #include <uk/essentials.h>
 #include <uk/print.h>
+#include <uk/errptr.h>
 #include <stdio.h>
 #include <errno.h>
 #include <lwip/sockets.h>
@@ -20,6 +21,21 @@ struct sock_net_file {
        int sock_fd;
 };
 
+static inline struct sock_net_file *sock_net_file_get(int fd)
+{
+       struct sock_net_file *file = NULL;
+       struct vfscore_file *fos;
+       fos  = vfscore_get_file(fd);
+       if(NULL == fos) {
+               uk_printd(DLVL_ERR,"failed with invalid descriptor\n");
+               file = ERR2PTR(-EINVAL);
+               goto EXIT;
+       }
+       file = __containerof(fos, struct sock_net_file, vfscore_file);
+EXIT:
+       return file;
+}
+
 static int sock_fd_alloc(struct vfscore_fops *fops, int sock_fd)
 {
        int ret = 0;
@@ -124,6 +140,23 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
 int bind(int s, const struct sockaddr *name, socklen_t namelen)
 {
        int ret = 0;
+       struct sock_net_file *file = NULL;
+       file = sock_net_file_get(s);
+       if(PTRISERR(file)) {
+               uk_printd(DLVL_ERR, "failed to identify the socket descriptor \n");
+               ret = -1;
+               /* Setting the errno */
+               SOCK_NET_SET_ERRNO(PTR2ERR(file));
+               goto EXIT;
+       }
+       /* Bind an incoming connection */
+       ret = lwip_bind(file->sock_fd, name, namelen);
+       if(0 > ret) {
+               uk_printd(DLVL_ERR, "failed to bind with the socket \n");
+               ret = -1;
+               goto EXIT;
+       }
+EXIT:
        return ret;
 }