From: Sharan Santhanam Date: Wed, 13 Jun 2018 00:17:45 +0000 (+0200) Subject: Implement bind() for libvfscore X-Git-Tag: RELEASE-0.3~13 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2b6b4f8cd6fff149036765673630c002b5e65484;p=unikraft%2Flibs%2Flwip.git Implement bind() for libvfscore Signed-off-by: Sharan Santhanam --- diff --git a/socket_glue.c b/socket_glue.c index 2148c39..c323ffc 100644 --- a/socket_glue.c +++ b/socket_glue.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -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; }