1 /*
2  * (c) 2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  * This file is part of TUD:OS and distributed under the terms of the
5  * GNU Lesser General Public License 2.1.
6  * Please see the COPYING-LGPL-2.1 file for details.
7  */
8 #include <sys/socket.h>
9 #include <errno.h>
10 #include <stdio.h>
11 #include <netdb.h>
12 #include <unistd.h>
13 #include <string.h>
14 
15 /* Define all functions weak so that real implementation can overwrite them */
16 #define W __attribute__((weak))
17 
socket(int domain,int type,int protocol)18 int W socket(int domain, int type, int protocol)
19 {
20   printf("Unimplemented: %s(%d, %d, %d)\n", __func__, domain, type, protocol);
21   errno = EINVAL;
22   return -1;
23 }
24 
connect(int sockfd,const struct sockaddr * addr,socklen_t addrlen)25 int W connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
26 {
27   printf("Unimplemented: %s(%d, %p, %d)\n", __func__, sockfd, addr, addrlen);
28   errno = EBADF;
29   return -1;
30 }
31 
accept(int sockfd,struct sockaddr * addr,socklen_t * addrlen)32 int W accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
33 {
34   printf("Unimplemented: %s(%d, %p, %p)\n", __func__, sockfd, addr, addrlen);
35   errno = EBADF;
36   return -1;
37 }
38 
39 int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
accept4(int sockfd,struct sockaddr * addr,socklen_t * addrlen,int flags)40 int W accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
41 {
42   printf("Unimplemented: %s(%d, %p, %p, %d)\n",
43          __func__, sockfd, addr, addrlen, flags);
44   errno = EBADF;
45   return -1;
46 }
47 
bind(int sockfd,const struct sockaddr * addr,socklen_t addrlen)48 int W bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
49 {
50   printf("Unimplemented: %s(%d, %p, %d)\n", __func__, sockfd, addr, addrlen);
51   errno = EBADF;
52   return -1;
53 }
54 
getsockopt(int sockfd,int level,int optname,void * optval,socklen_t * optlen)55 int W getsockopt(int sockfd, int level, int optname,
56                  void *optval, socklen_t *optlen)
57 {
58   printf("Unimplemented: %s(%d, %d, %d, %p, %p)\n",
59          __func__, sockfd, level, optname, optval, optlen);
60   errno = EBADF;
61   return -1;
62 }
63 
setsockopt(int sockfd,int level,int optname,const void * optval,socklen_t optlen)64 int W setsockopt(int sockfd, int level, int optname,
65                  const void *optval, socklen_t optlen)
66 {
67   printf("Unimplemented: %s(%d, %d, %d, %p, ...)\n",
68          __func__, sockfd, level, optname, optval);
69   (void)optlen;
70   errno = EBADF;
71   return -1;
72 }
73 
listen(int sockfd,int backlog)74 int W listen(int sockfd, int backlog)
75 {
76   printf("Unimplemented: %s(%d, %d)\n", __func__, sockfd, backlog);
77   errno = EBADF;
78   return -1;
79 }
80 
shutdown(int sockfd,int how)81 int W shutdown(int sockfd, int how)
82 {
83   printf("Unimplemented: %s(%d, %d)\n", __func__, sockfd, how);
84   errno = EBADF;
85   return -1;
86 }
87 
recv(int sockfd,void * buf,size_t len,int flags)88 ssize_t W recv(int sockfd, void *buf, size_t len, int flags)
89 {
90   printf("Unimplemented: %s(%d, %p, %zd, %d)\n", __func__, sockfd, buf, len, flags);
91   errno = EBADF;
92   return -1;
93 }
94 
recvfrom(int sockfd,void * buf,size_t len,int flags,struct sockaddr * src_addr,socklen_t * addrlen)95 ssize_t W recvfrom(int sockfd, void *buf, size_t len, int flags,
96                    struct sockaddr *src_addr, socklen_t *addrlen)
97 {
98   printf("Unimplemented: %s(%d, %p, %zd, %d, %p, %p)\n",
99          __func__, sockfd, buf, len, flags, src_addr, addrlen);
100   errno = EBADF;
101   return -1;
102 }
103 
send(int sockfd,const void * buf,size_t len,int flags)104 ssize_t W send(int sockfd, const void *buf, size_t len, int flags)
105 {
106   printf("Unimplemented: %s(%d, %p, %zd, %d)\n", __func__, sockfd, buf, len, flags);
107   errno = EBADF;
108   return -1;
109 }
110 
sendto(int sockfd,const void * buf,size_t len,int flags,const struct sockaddr * dest_addr,socklen_t addrlen)111 ssize_t W sendto(int sockfd, const void *buf, size_t len, int flags,
112                  const struct sockaddr *dest_addr, socklen_t addrlen)
113 {
114   printf("Unimplemented: %s(%d, %p, %zd, %d, %p, %d)\n", __func__,
115          sockfd, buf, len, flags, dest_addr, addrlen);
116   errno = EBADF;
117   return -1;
118 }
119 
socketpair(int domain,int type,int protocol,int sv[2])120 int W socketpair(int domain, int type, int protocol, int sv[2])
121 {
122   printf("Unimplemented: %s(%d, %d, %d, %p)\n", __func__,
123          domain, type, protocol, sv);
124   errno = EOPNOTSUPP;
125   return -1;
126 }
127 
getsockname(int sockfd,struct sockaddr * addr,socklen_t * addrlen)128 int W getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
129 {
130   printf("Unimplemented: %s(%d, %p, %p)\n", __func__, sockfd, addr, addrlen);
131   errno = EBADF;
132   return -1;
133 }
134 
getpeername(int sockfd,struct sockaddr * addr,socklen_t * addrlen)135 int W getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
136 {
137   printf("Unimplemented: %s(%d, %p, %p)\n", __func__, sockfd, addr, addrlen);
138   errno = EBADF;
139   return -1;
140 }
141 
getnameinfo(const struct sockaddr * sa,socklen_t salen,char * host,socklen_t hostlen,char * serv,socklen_t servlen,unsigned int flags)142 int W getnameinfo(const struct sockaddr *sa, socklen_t salen,
143                 char *host, socklen_t hostlen,
144                 char *serv, socklen_t servlen, unsigned int flags)
145 {
146   printf("Unimplemented: %s(%p, %d, %p, %d, %p, %d, %d)\n", __func__,
147          sa, salen, host, hostlen, serv, servlen, flags);
148   return EAI_FAIL;
149 }
150 
gethostent_r(struct hostent * ret,char * buf,size_t buflen,struct hostent ** result,int * h_errnop)151 int W gethostent_r(struct hostent *ret, char *buf, size_t buflen,
152                  struct hostent **result, int *h_errnop)
153 {
154   printf("Unimplemented: %s(%p, %p, %zd, %p, %p)\n", __func__,
155          ret, buf, buflen, result, h_errnop);
156   *h_errnop = HOST_NOT_FOUND;
157 
158   if (result)
159     *result = NULL;
160   return -1;
161 }
162